Packer "Failed to parse" a .pkr.hcl file in CI
Packer could not parse a .pkr.hcl file because of a syntax error. Parsing happens before any evaluation, so the whole template load aborts at the first structural problem.
What this error means
packer validate or build fails with a parse error like "Argument or block definition required", "Unclosed configuration block", or "Missing newline after argument", pointing at a line.
packer
Error: Missing newline after argument
on build.pkr.hcl line 6, in source "amazon-ebs" "ubuntu":
6: region "us-east-1"
An argument definition must end with a newline.Common causes
A missing equals sign or quote
Writing region "us-east-1" without = (or leaving a quote unclosed) makes the parser fail on the line.
An unclosed block
A missing closing brace leaves a block open, so Packer reports a parse error near the end of the file.
How to fix it
Fix the flagged syntax
- Open the file and line Packer names.
- Add the missing
=, quote, or closing brace. - Run
packer fmtandpacker validateto confirm the file parses.
build.pkr.hcl
source "amazon-ebs" "ubuntu" {
region = "us-east-1"
}Format and validate in CI
Run packer fmt -check and packer validate as early steps so syntax errors fail fast with a clear location.
Terminal
packer fmt -check .
packer validate .How to prevent it
- Run
packer fmt -checkandpacker validatein CI. - Use an editor HCL plugin to catch unclosed blocks locally.
- Keep templates small so a parse error is easy to locate.
Related guides
Packer "Unsupported argument" in a .pkr.hcl block in CIFix Packer "Error: Unsupported argument" in CI - a source, build, or provisioner block sets an argument that…
Packer legacy JSON template deprecation in CIFix Packer legacy JSON template warnings and failures in CI - the JSON template format is deprecated and newe…
Packer "references unknown source" in a build block in CIFix Packer "build references unknown source" in CI - a build block lists a sources entry that does not match…