-
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
prevent duplicate local block creation #11534
Conversation
732cc86
to
a2478c4
Compare
a2478c4
to
e003e0c
Compare
e003e0c
to
3239a7e
Compare
3239a7e
to
c78e61c
Compare
c78e61c
to
4405269
Compare
func (c *PackerConfig) parseLocalVariables(f *hcl.File) ([]*LocalBlock, hcl.Diagnostics) { | ||
// parseLocalVariableBlocks looks in the AST for 'local' and 'locals' blocks and | ||
// returns them all. | ||
func parseLocalVariableBlocks(f *hcl.File) ([]*LocalBlock, hcl.Diagnostics) { |
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.
I removed the PackerConfig
, so that this function is only an extraction function.
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.
Thanks for the call out here.
|
||
// divide by 2 so that you don't get duplicate locals | ||
// appear to have double locals in LocalBlock, not sure if intentional | ||
for i := 0; i < len(locals)/2; i++ { |
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.
This was not always correct
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 catch! This looks good. Test results below
Example HCL
~> cat /tmp/source.pkr.hcl
locals {
timestamp = formatdate("YYYY-MM-DD", timestamp())
other_local = "test-${local.timestamp}"
}
locals {
other_local = "testagain-${local.timestamp}"
}
With Packer 1.7.9
~> ~/Downloads/packer179 validate /tmp/source.pkr.hcl
The configuration is valid.
With Dev Build
~> packer validate /tmp/source.pkr.hcl
Error: Duplicate local definition
on /tmp/source.pkr.hcl line 7:
(source code not available)
Duplicate other_local definition found.
I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
After #11527
A bug was introduced in #10509 where a local block could be parsed and added to the list n * n times. ( n being the number of local blocks defined per file ).
This makes sure these are only parsed once by:
local
andlocals
blocks