Skip to content
Latchkey

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

  1. Open the file and line Packer names.
  2. Add the missing =, quote, or closing brace.
  3. Run packer fmt and packer validate to 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 -check and packer validate in CI.
  • Use an editor HCL plugin to catch unclosed blocks locally.
  • Keep templates small so a parse error is easy to locate.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →