Complete the code to query an existing AWS VPC by its ID.
data "aws_vpc" "selected" { id = "[1]" }
The id attribute must be the VPC ID. Only option A is a valid VPC ID format.
Complete the code to query the AWS region where Terraform is running.
data "aws_region" "current" { [1] = true }
The current attribute set to true tells Terraform to get the current region.
Fix the error in the code to query an existing AWS subnet by its filter.
data "aws_subnet" "selected" { filter { name = "[1]" values = ["my-subnet"] } }
To filter by a tag name, use tag:Name as the filter name.
Fill both blanks to query an existing AWS security group by its name and VPC ID.
data "aws_security_group" "selected" { filter { name = "[1]" values = ["my-security-group"] } filter { name = "[2]" values = ["vpc-abc123"] } }
Use group-name to filter by security group name and vpc-id to filter by VPC ID.
Fill all three blanks to query existing AWS EC2 instances filtered by tag, state, and availability zone.
data "aws_instances" "selected" { filter { name = "[1]" values = ["web-server"] } filter { name = "[2]" values = ["running"] } filter { name = "[3]" values = ["us-east-1a"] } }
Use tag:Name to filter by tag, instance-state-name for instance state, and availability-zone for zone.