hashicorp / packer

Packer is a tool for creating identical machine images for multiple platforms from a single source configuration.
http://www.packer.io
Other
15.11k stars 3.33k forks source link

Unable to fmt .pkrvars.hcl extension #10350

Closed danielkubat closed 3 years ago

danielkubat commented 3 years ago

Overview of the Issue

It is not possible to format *.pkrvars.hcl variable file using packer fmt command. This should be possible using fmt command according to help:

Usage: packer fmt [options] [TEMPLATE]

  Rewrites all Packer configuration files to a canonical format. Both
  configuration files (.pkr.hcl) and variable files (.pkrvars) are updated.
  JSON files (.json) are not modified

1 fmt help documentation should rather include `.pkrvars.hcl, not just.pkrvars`. 2 formatting of variable files not working

Reproduction Steps

Error when formatting *.pkrvars.hcl extension:

packer fmt amazon2.pkrvars.hcl
Error: Cannot tell whether amazon2.pkrvars.hcl contains HCL2 configuration data

After renaming variable file to *.pkr.hcl, formatting works as expected:

mv amazon2.pkrvars.hcl amazon2.pkr.hcl
packer fmt amazon2.pkr.hcl 
echo $?
0

Packer version

packer --version
1.6.6

Simplified Packer Buildfile

cat amazon2.pkrvars.hcl 
ami_filter_name = "amzn2-ami-hvm-*-x86_64-gp2"
ami_filter_owners = [
  "137112412989"
]

Operating system and Environment details

macOS Catalina 10.15.7

Log Fragments and crash.log files

N/A

nywilken commented 3 years ago

@danielkubat thanks for bubbling this up. We'll get this squared away as soon as we can.

As it currently stands, the fmt command will only automatically detect var files with the extension *.auto.pkrvars.hcl, which is an oversight. Thanks again.

ghost commented 3 years ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.