Error: Missing newline after argument: HCL syntax error on one line
Fixes Terraform's "Error: Missing newline after argument" HCL syntax error, where two arguments share one line. Use when validate fails right after editing config. Put each argument on its own line and run terraform fmt; not for semicolon errors ("Invalid character").
TL;DR
Two arguments ended up on one line, or you used non-HCL syntax (like a JavaScript function call) inside a .tf file. HCL wants one argument per line. Split them, replace JS-isms with HCL natives (jsonencode), and run terraform fmt.
The error
Error: Missing newline after argument
on main.tf line 200:
200: event_pattern = JSON.stringify({Steps to fix
- Open the flagged line. Look for two arguments jammed together, or a function call from another language (
JSON.stringify, etc.).
- Expected: you spot the offending syntax.
- Rewrite in HCL: one argument per line, HCL-native functions:
event_pattern = jsonencode({
source = ["my.service"]
})- Expected: no foreign syntax remains.
- Run
terraform fmtthenterraform validate.
- Expected:
Success! The configuration is valid.
When to use this
terraform validate/planfails withMissing newline after argumentafter editing or pasting config, especially config translated from another language.
When NOT to use this
Invalid character(e.g.;) is the sibling error for characters HCL rejects outright. If the line looks fine, check for invisible characters from copy-paste.
Compatibility
- All Terraform versions; HCL2 syntax rules are stable.
Root cause
HCL separates block arguments with newlines. Pasting multi-argument snippets onto one line, or transliterating JavaScript/Python expressions directly into .tf files, produces tokens the parser cannot split into separate arguments.
Edge cases
- Heredocs (
<<EOT) containing code from other languages are fine; the error only applies to HCL outside strings. terraform fmtwill not fix this; it only formats valid syntax. Fix the syntax first, then format.