0
0
Terraformcloud~5 mins

AMI lookup data source example in Terraform - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is an AMI in AWS?
An AMI (Amazon Machine Image) is a template that contains the software configuration (operating system, application server, and applications) required to launch an EC2 instance.
Click to reveal answer
beginner
What does the Terraform 'data' block do when looking up an AMI?
The 'data' block in Terraform fetches information from existing resources, like finding the latest AMI ID based on filters, without creating new resources.
Click to reveal answer
intermediate
Why use filters in an AMI lookup data source?
Filters help narrow down the search to find the exact AMI you want, such as by name, owner, or tags, ensuring you get the right image for your EC2 instance.
Click to reveal answer
intermediate
Example: What does the attribute 'most_recent = true' do in an AMI lookup?
It tells Terraform to select the newest AMI that matches the filters, so you always get the latest version available.
Click to reveal answer
beginner
How do you reference the AMI ID found by the data source in Terraform?
You use the syntax: data.<data_source_name>.<resource_name>.id to get the AMI ID for use in other resources like EC2 instances.
Click to reveal answer
In Terraform, which block is used to look up an existing AMI?
Aprovider "aws"
Bresource "aws_ami"
Cdata "aws_ami"
Dvariable "aws_ami"
What does setting 'owners = ["amazon"]' do in an AMI lookup?
ACreates a new AMI owned by Amazon
BLists all AMIs regardless of owner
CDeletes AMIs not owned by Amazon
DFilters AMIs owned by Amazon
Which attribute ensures Terraform picks the latest AMI matching filters?
Alatest = true
Bmost_recent = true
Cnewest = true
Drecent = true
How do you use the AMI ID found by the data source in an EC2 resource?
Aami = data.aws_ami.example.id
Bami = aws_ami.example.id
Cami = var.aws_ami_id
Dami = resource.aws_ami.example.id
What is the purpose of the 'filter' block inside the AMI data source?
ATo specify criteria like name or tags to find the right AMI
BTo create a new AMI with specific tags
CTo delete AMIs that don't match criteria
DTo launch an EC2 instance
Explain how to use Terraform to find the latest Amazon Linux 2 AMI using a data source.
Think about filters, owner, and most_recent attributes.
You got /5 concepts.
    Describe why using an AMI lookup data source is better than hardcoding an AMI ID in Terraform.
    Consider what happens when AMIs get updated.
    You got /5 concepts.