AMI lookup data source example
📖 Scenario: You are setting up a cloud server and need to find the latest Amazon Machine Image (AMI) for Ubuntu 22.04 in the AWS region you are working in.
🎯 Goal: Create a Terraform configuration that uses the aws_ami data source to look up the latest Ubuntu 22.04 AMI and then launch an EC2 instance using that AMI.
📋 What You'll Learn
Use the
aws_ami data source to find the latest Ubuntu 22.04 AMIFilter the AMI by owner
099720109477 (official Ubuntu owner)Launch an EC2 instance using the found AMI
Use the
aws_instance resource with a simple instance type💡 Why This Matters
🌍 Real World
Finding the latest AMI ensures your cloud servers use up-to-date and secure operating system images.
💼 Career
Cloud engineers often use data sources in Terraform to dynamically find resources like AMIs, making infrastructure code reusable and reliable.
Progress0 / 4 steps