What is Packer and how does it relate to Terraform?
Answer
Packer is a HashiCorp tool for creating identical machine images (AMIs, VHDs, Docker images) from a single template across multiple platforms. It automates creating pre-baked images with all software pre-installed. Relationship with Terraform: Build time vs runtime: Packer builds the image with software; Terraform deploys instances using that image. Workflow: 1. Packer: starts a temporary VM, installs Nginx/Java/your app via a shell provisioner or Ansible, creates a snapshot (AMI), terminates the VM. 2. Terraform: use the AMI ID from Packer as the ami attribute. VMs launch instantly with everything pre-installed. Benefits: faster instance boot (no user_data scripts), immutable infrastructure (never modify running instances — build a new image and redeploy), consistent environments. The Packer AMI ID can be passed to Terraform via a data source: data "aws_ami" "my_app" { filter { name = "tag:Version"; values = ["1.2.3"] } }.
Previous
What is the Terraform lifecycle of a resource?
Next
What is Atlantis and how does it automate Terraform?
More Terraform / IaC Questions
View all →- Intermediate What is the Terraform state locking mechanism?
- Intermediate How do you handle sensitive values in Terraform?
- Intermediate What are Terraform Provisioners and when should you avoid them?
- Intermediate What is Terraform import?
- Intermediate How do you structure Terraform code for large teams?