Complete the code to query an existing AWS VPC using a data source.
data "aws_vpc" "example" { id = [1] }
The id attribute must be the VPC ID, like "vpc-12345678", to query the existing VPC.
Complete the code to get the CIDR block of an existing AWS VPC using a data source.
output "vpc_cidr" { value = data.aws_vpc.example.[1] }
The cidr_block attribute gives the IP range of the VPC.
Fix the error in the data source block to correctly query an existing AWS subnet by its ID.
data "aws_subnet" "example" { [1] = "subnet-87654321" }
The correct attribute to specify the subnet ID is id.
Fill both blanks to query an existing AWS security group by its name and output its ID.
data "aws_security_group" "example" { [1] = "my-security-group" } output "sg_id" { value = data.aws_security_group.example.[2] }
Use name to find the security group by name, and id to output its unique identifier.
Fill all three blanks to query an existing AWS EC2 instance by its ID, get its subnet ID, and output the subnet ID.
data "aws_instance" "example" { [1] = "i-0abcdef1234567890" } output "instance_subnet" { value = data.aws_instance.example.[2] } resource "aws_security_group_rule" "allow_http" { type = "ingress" from_port = 80 to_port = 80 protocol = "tcp" security_group_id = data.aws_instance.example.[3][0] cidr_blocks = ["0.0.0.0/0"] }
Use id to query the instance, subnet_id to get its subnet, and vpc_security_group_ids to get the security group IDs for the rule.