Complete the code to define a data source for the latest Amazon Linux 2 AMI.
data "aws_ami" "example" { most_recent = true filter { name = "name" values = ["[1]"] } owners = ["amazon"] }
The filter value must match the Amazon Linux 2 AMI name pattern to find the latest AMI.
Complete the code to reference the AMI ID from the data source in an EC2 instance resource.
resource "aws_instance" "example" { ami = [1] instance_type = "t2.micro" }
The AMI ID is accessed from the data source using data.aws_ami.example.id.
Fix the error in the filter block to correctly filter AMIs by architecture.
data "aws_ami" "example" { most_recent = true filter { name = "architecture" values = ["[1]"] } owners = ["amazon"] }
The correct architecture value for Amazon Linux 2 AMIs is x86_64.
Fill both blanks to filter AMIs by name and virtualization type.
data "aws_ami" "example" { most_recent = true filter { name = "[1]" values = ["amzn2-ami-hvm-2.0.*-x86_64-gp2"] } filter { name = "[2]" values = ["hvm"] } owners = ["amazon"] }
The first filter is by name and the second by virtualization-type to get the correct AMI.
Fill all three blanks to create a data source that filters AMIs by name, architecture, and owner.
data "aws_ami" "example" { most_recent = true filter { name = "[1]" values = ["amzn2-ami-hvm-2.0.*-x86_64-gp2"] } filter { name = "[2]" values = ["[3]"] } owners = ["amazon"] }
The filters are for name and architecture, with the architecture value x86_64.