Packer fmt is failing

I tried to pkr fmt . and also packer fmt -check -recursive .
then coming up with following errror. please suggest fix for this

Error: encountered an error while formatting builds.pkr.hcl

failed to parse HCL builds.pkr.hcl

Hi @sk8228402,

Your file is malformed according to the error, but it’s particularly terse. I suspect some other command will forward the parsing errors properly, have you tried running packer validate or packer build on your template?

I’ll see to submit a patch so fmt prints out the errors, the command disregards those returned by the HCL parser, so that’s quite unhelpful.

Hope that helps

Hi Ibahoket,

I am seeing following when i run packer validate and build

PS C:\Users\packer> packer validate
Usage: packer validate [options] TEMPLATE

Checks the template is valid by parsing the template and also
checking the configuration with the various builders, provisioners, etc.

If it is not valid, the errors will be shown and the command will exit
with a non-zero exit status. If it is valid, it will exit with a zero
exit status.

Options:

-syntax-only Only check syntax. Do not verify config of the template.
-except=foo,bar,baz Validate all builds other than these.
-only=foo,bar,baz Validate only these builds.
-machine-readable Produce machine-readable output.
-var ‘key=value’ Variable for templates, can be used multiple times.
-var-file=path JSON or HCL2 file containing user variables, can be used multiple times.
-no-warn-undeclared-var Disable warnings for user variable files containing undeclared variables.
-evaluate-datasources Evaluate data sources during validation (HCL2 only, may incur costs); Defaults to false.

You need to give the command a path to a template, otherwise it won’t work and print the usage function as you experienced.

Please refer to our docs if something isn’t clear in the help message: packer validate - Commands | Packer | HashiCorp Developer