This lab is currently in Beta, content may be updated as we refine the material
LABBEGINNER

Parameterize an AWS AMI

Split an amazon-ebs template into variables, a data source, and a var file, enforce both IMDSv2 knobs, prove a bad filter fails closed, bake a uniquely prefixed AMI, validate Azure and GCP sidecars, then clean up.

45 minutes
hashicorp/packer
Parameterize an AWS AMI - Platform Engineering Hands-On Lab Icon
Share this Lab

Lab Overview

This is the hands-on lab for Section 6 of Packer 101 that applies HCL2 variables, locals, and data sources on a live AWS bake. You split the template into variables.pkr.hcl and aws-ubuntu.pkr.hcl, select Ubuntu 24.04 with data "amazon-ami", pass a session-unique ami_prefix from a var file, and set both IMDSv2 knobs: metadata_options http_tokens = required on the builder instance and imds_support = v2.0 on the resulting AMI. You break the data filter on purpose, watch packer validate -evaluate-datasources fail closed, then restore and bake. After proving the AMI you fmt and validate dummy Azure and GCP sidecar templates in separate directories. Cleanup deregisters the AMI and deletes its EBS snapshot.

You will:

  • Confirm Packer 1.16.0 and AWS credentials, then author a split HCL2 layout
  • Use data.amazon-ami, a .pkrvars.hcl file, tags, and both IMDS knobs
  • Prove a bad data filter fails closed with -evaluate-datasources
  • Build the AMI, prove it with aws ec2 describe-images, and validate sidecars
  • Deregister the AMI and delete its snapshot

What You'll Learn

Split an amazon-ebs template across variables.pkr.hcl, aws-ubuntu.pkr.hcl, and a var file

Select a Noble source AMI with data.amazon-ami and feed source_ami from the data id

Set both metadata_options http_tokens = required and imds_support = v2.0

Demonstrate that a bad data filter fails closed under packer validate -evaluate-datasources

Build a uniquely prefixed AMI, validate Azure/GCP sidecars, then deregister and delete the snapshot

Prerequisites

Completion of Packer 101 Section 5 (variables, locals, data sources) and Section 6 lessons

Completion of Lab 2 First AWS AMI (or equivalent amazon-ebs familiarity)

Basic Linux command line (bash, reading logs)

Technologies Covered

packeramazon-ebsamiawsvariablesdata-sourcesimdsv2hcl2

Part of a Course

This lab is part of the Packer 101 - Golden Images for AWS, Azure, and GCP course

View All Courses

Choose your plan

Simple, Transparent Pricing

Unlock full access to TeKanAid courses, labs, and bootcamps

Buying for a team? Private corporate training is available for up to 15 learners.View team training
MonthlyQuarterly
Try Premium free for 7 days →

Just exploring? Start free below. Want the full experience? Try Premium free for 7 days (card required, $0 today).

Pro

All courses, with lab scripts to run on your own machine

$59/month

Renews automatically. Cancel anytime.

Final price verified at checkout.

  • Full access to all courses
  • Lab scripts to download and run on your own machine (hosted labs not included)
  • Progress tracking
  • Certificate of completion
  • Community access
  • Self-paced bootcamps
  • Premium puzzle library not included (5 free puzzles available)
  • New content access
Recommended

Premium

Full access, including unlimited hosted labs

$99/month

Renews automatically. Cancel anytime.

Final price verified at checkout.

  • Everything in Pro
  • Unlimited hands-on labs, fully hosted on TeKanAid Academy (nothing to set up)
  • Full access to the puzzle library
  • Lab AI Assistant
  • Priority support

Prefer a single course?

Purchase individual courses for a one-time fee of $79. Full access to course content, quizzes, certificates, and community features, lab access is not included.

Browse Courses

Just exploring? Start free, no account needed

Three free ways to start. All bridge into the paid Premium catalog when you're ready.

Not ready to commit? The crash course is email-only. No academy account required.

Ready to Get Started?

Start this hands-on lab and build real-world Platform Engineering skills

Get Access Now