-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
command/fmt: Ensure all variable files ending in .pkrvars.hcl
get formatted
#10377
Conversation
…ormatted Before change ``` ⇶ packer fmt -check /tmp/unformatted.pkrvars.hcl Error: Cannot tell whether /tmp/unformatted.pkrvars.hcl contains HCL2 configuration data ⇶ echo $? 1 ``` After fix ``` ⇶ packer fmt -check /tmp/unformatted.pkrvars.hcl /tmp/unformatted.pkrvars.hcl ⇶ echo $? 3 ⇶ packer fmt -check command/test-fixtures/fmt command/test-fixtures/fmt/unformatted.pkr.hcl command/test-fixtures/fmt/unformatted.auto.pkrvars.hcl command/test-fixtures/fmt/unformatted.pkrvars.hcl ```
Codecov Report
|
@@ -162,7 +164,7 @@ func (p *Parser) Parse(filename string, varFiles []string, argVars map[string]st | |||
|
|||
// parse var files | |||
{ | |||
hclVarFiles, jsonVarFiles, moreDiags := GetHCL2Files(filename, hcl2VarFileExt, hcl2VarJsonFileExt) | |||
hclVarFiles, jsonVarFiles, moreDiags := GetHCL2Files(filename, hcl2AutoVarFileExt, hcl2AutoVarJsonFileExt) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, super good catch !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nywilken I was referring to this change here: before this the HCL2 parse would read all .varvars.hcl
files in the folder, now it only reads .auto.pkrvars.hcl
files ( which I think is a good way to go ).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So if anyone was mistakenly relying on this behaviour. Bang ! I say mistakenly because the docs says that only .auto
files in the same folder will be auto parsed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, thanks. To confirm you mean .auto.pkrvars.hcl
, right? If so then the behavior was correct to begin with. I just renamed the variable to so that I could use hcl2VarFileExt
for the non-auto variable file extension 😄 I'm going to merge since this this is what we want. But do let me know if I misunderstood the case for .pkr.hcl
files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OOoohh right I misread the diff sorry ! Yup even better !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Super good one, LGTM. I hadn't realised that we were reading all .pkr.hcl
files from the same project folder ( unlike the docs stated ) that was def a bug. I hope the breaking change won't be too annoying.
fatalCommand(t, c.Meta) | ||
} | ||
expected := "" | ||
assert.Equal(t, expected, strings.TrimSpace(s.String())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Totally for another PR but one nice thing we could have done is having a input
file and an expected
per folder, making the tests easy to read & add.
@azr is this in reference to the the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! LGTM 👍🏼
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. |
Before change
After fix
Closes #10350