# Packer fmt is failing

**URL:** <https://discuss.hashicorp.com/t/packer-fmt-is-failing/63468>\
**Category:** Packer\
**Tags:** azure\
**Created:** [March 7, 2024, 12:10pm UTC](https://discuss.hashicorp.com/t/packer-fmt-is-failing/63468 "2024-03-07T12:10:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sk8228402](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/sk8228402/32/25064_2.png) [@sk8228402](https://discuss.hashicorp.com/u/sk8228402)\
**Post date:** [March 7, 2024, 12:10pm UTC](https://discuss.hashicorp.com/t/packer-fmt-is-failing/63468/1 "2024-03-07T12:10:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![lbajolet-hashicorp](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/lbajolet-hashicorp/32/28193_2.png) [@lbajolet-hashicorp](https://discuss.hashicorp.com/u/lbajolet-hashicorp)\
**Post date:** [March 7, 2024, 3:05pm UTC](https://discuss.hashicorp.com/t/packer-fmt-is-failing/63468/2 "2024-03-07T15:05:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sk8228402](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/sk8228402/32/25064_2.png) [@sk8228402](https://discuss.hashicorp.com/u/sk8228402)\
**Post date:** [March 7, 2024, 3:20pm UTC](https://discuss.hashicorp.com/t/packer-fmt-is-failing/63468/3 "2024-03-07T15:20:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![lbajolet-hashicorp](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/lbajolet-hashicorp/32/28193_2.png) [@lbajolet-hashicorp](https://discuss.hashicorp.com/u/lbajolet-hashicorp)\
**Post date:** [March 7, 2024, 3:30pm UTC](https://discuss.hashicorp.com/t/packer-fmt-is-failing/63468/4 "2024-03-07T15:30:37Z")

</div>

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](https://developer.hashicorp.com/packer/docs/commands/validate)
