0
0
Terraformcloud~10 mins

AMI lookup data source example in Terraform - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a data source for the latest Amazon Linux 2 AMI.

Terraform
data "aws_ami" "example" {
  most_recent = true
  filter {
    name   = "name"
    values = ["[1]"]
  }
  owners = ["amazon"]
}
Drag options to blanks, or click blank then click option'
Aubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*
Bamzn2-ami-hvm-2.0.*-x86_64-gp2
Cwindows/images/*
Dcentos/images/*
Attempts:
3 left
💡 Hint
Common Mistakes
Using an AMI name pattern for a different OS like Ubuntu or CentOS.
Not including wildcards in the AMI name pattern.
2fill in blank
medium

Complete the code to reference the AMI ID from the data source in an EC2 instance resource.

Terraform
resource "aws_instance" "example" {
  ami           = [1]
  instance_type = "t2.micro"
}
Drag options to blanks, or click blank then click option'
Aaws_instance.example.ami
Baws_ami.example.id
Cdata.aws_instance.example.ami
Ddata.aws_ami.example.id
Attempts:
3 left
💡 Hint
Common Mistakes
Referencing the resource instead of the data source.
Using incorrect attribute names.
3fill in blank
hard

Fix the error in the filter block to correctly filter AMIs by architecture.

Terraform
data "aws_ami" "example" {
  most_recent = true
  filter {
    name   = "architecture"
    values = ["[1]"]
  }
  owners = ["amazon"]
}
Drag options to blanks, or click blank then click option'
Ax86_64
Bamd64
Cx64
Darm64
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect architecture strings like 'amd64' or 'x64'.
Confusing architecture with instance type.
4fill in blank
hard

Fill both blanks to filter AMIs by name and virtualization type.

Terraform
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"]
}
Drag options to blanks, or click blank then click option'
Aname
Bvirtualization-type
Carchitecture
Droot-device-type
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong filter names like 'architecture' for the AMI name.
Confusing 'virtualization-type' with 'root-device-type'.
5fill in blank
hard

Fill all three blanks to create a data source that filters AMIs by name, architecture, and owner.

Terraform
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"]
}
Drag options to blanks, or click blank then click option'
Aname
Barchitecture
Cx86_64
Dvirtualization-type
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up filter names and values.
Using incorrect architecture values.