Simple Packer Template - Packer Typing CST Test
Loading…
Simple Packer Template — Packer Code
A simple Packer HCL template to create an Ubuntu AWS AMI with Nginx installed.
# 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"
]
}
}Packer Language Guide
Packer is an open-source tool from HashiCorp that automates the creation of machine images for multiple platforms from a single configuration.
Primary Use Cases
- ▸Building machine images for multiple cloud providers
- ▸Creating immutable infrastructure artifacts
- ▸Automating OS and application provisioning
- ▸Integrating with CI/CD pipelines for image builds
- ▸Ensuring reproducible infrastructure environments
Notable Features
- ▸Multi-platform builders
- ▸Provisioner support for configuration management
- ▸Template-driven infrastructure as code
- ▸Post-processors for artifact modification
- ▸Versioned, repeatable image builds
Origin & Creator
Created by HashiCorp in 2013 and maintained as an open-source project.
Industrial Note
Packer is widely used in cloud and DevOps environments for pre-building immutable images, including VM templates for hybrid cloud, container base images, and edge computing systems.