Learn PACKER with Real Code Examples
Updated Nov 27, 2025
Code Sample Descriptions
1
Simple Packer Template
# packer/demo/ubuntu-ami.pkr.hcl
packer {
required_plugins {
amazon = {
source = "hashicorp/amazon"
version = "~> 1.0"
}
}
}
source "amazon-ebs" "ubuntu" {
ami_name = "packer-example-{{timestamp}}"
instance_type = "t2.micro"
region = "us-east-1"
source_ami_filter {
filters = { name = "ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*", virtualization-type = "hvm" }
owners = ["099720109477"]
most_recent = true
}
}
build {
sources = ["source.amazon-ebs.ubuntu"]
provisioner "shell" {
inline = [
"sudo apt-get update",
"sudo apt-get install -y nginx"
]
}
}
A simple Packer HCL template to create an Ubuntu AWS AMI with Nginx installed.