DevTools

Packer CLI

HashiCorp Packer commands for machine image building.

27 commands
Windows MacOS Linux
#image-building #automation

Build Management

Build image from HCL template
packer build template.pkr.hcl
packer build -var 'region=us-east-1' template.pkr.hcl # Build with variable override
packer build -var-file=vars.pkrvars.hcl template.pkr.hcl # Build with variable file
packer build -only='amazon-ebs.ubuntu' template.pkr.hcl # Build only specific source
packer build -except='docker.test' template.pkr.hcl # Build all except specific source
packer build -parallel-builds=1 template.pkr.hcl # Limit parallel builds
packer build -on-error=ask template.pkr.hcl # Prompt on error for debugging

Validation

Validate template syntax
packer validate template.pkr.hcl
packer validate -var 'region=us-east-1' template.pkr.hcl # Validate with variables
Format template to canonical style
packer fmt template.pkr.hcl
Check if template needs formatting
packer fmt -check template.pkr.hcl
Format all templates recursively
packer fmt -recursive .

Inspection

Show template components and variables
packer inspect template.pkr.hcl
Open interactive console for template
packer console template.pkr.hcl
Show installed Packer version
packer version

Plugins

packer plugins install github.com/hashicorp/amazon # Install Amazon plugin
packer plugins install github.com/hashicorp/docker # Install Docker plugin
List installed plugins
packer plugins installed
packer plugins remove github.com/hashicorp/azure # Remove a plugin
Install plugins required by template
packer init template.pkr.hcl

HCL2

Convert JSON template to HCL2
packer hcl2_upgrade template.json
packer build -var 'ami_name=my-image' . # Build all HCL files in directory
Validate all HCL files in directory
packer validate .
Format all HCL files in directory
packer fmt .

Quick Commands

Build machine image from HCL template
packer build template.pkr.hcl
Validate template syntax and configuration
packer validate template.pkr.hcl
Install plugins required by template
packer init template.pkr.hcl