Complete the code to declare a data source block for AWS AMI.
[1] "aws_ami" "example" { most_recent = true owners = ["amazon"] }
The keyword data is used to declare a data source block in Terraform.
Complete the code to specify the data source name for AWS VPC.
data "aws_vpc" [1] { default = true }
The data source name is an identifier you choose. default is commonly used here to indicate the default VPC.
Fix the error in the data source block by completing the missing attribute.
data "aws_subnet" default_subnet { [1] = "subnet-12345678" }
The correct attribute to specify a subnet by its ID in the data source block is subnet_id.
Fill both blanks to complete the data source block that fetches the latest Amazon Linux AMI.
data "aws_ami" [1] { most_recent = true filter { name = "name" values = ["[2]"] } owners = ["amazon"] }
The data source name is a label like amazon_linux. The filter value should match the AMI name pattern, here amzn2-ami-hvm-2.0.*-x86_64-gp2 to get the latest Amazon Linux 2 AMI.
Fill all three blanks to complete the data source block that fetches a subnet by its tag.
data "aws_subnet" [1] { filter { name = "tag:[2]" values = ["[3]"] } }
The data source name is selected_subnet. The filter uses the tag key Environment and looks for the value production to find the subnet.