Skip to content
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

-var-file precedence not respected when mixing JSON/HCL var files #13177

Open
joshfrench opened this issue Oct 3, 2024 · 0 comments
Open

-var-file precedence not respected when mixing JSON/HCL var files #13177

joshfrench opened this issue Oct 3, 2024 · 0 comments
Labels

Comments

@joshfrench
Copy link

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

When filing a bug, please include the following headings if possible. Any
example text in this template can be deleted.

Overview of the Issue

JSON var files clobber HCL var files, regardless of order

Reproduction Steps

When running packer build/packer console with multiple -var-files, if those var files include both JSON and HCL the JSON value is always taken:

% packer console -var-file=foo.pkrvars.hcl -var-file=bar.pkrvars.json .
> variables
> > input-variables:

var.my_var: "bar"

% packer console -var-file=bar.pkrvars.json -var-file=foo.pkrvars.hcl .
> variables
> > input-variables:

var.my_var: "bar"

When using two var files of the same type (both files either HCL or JSON) the last file to set the value wins.

Packer version

Packer v1.11.2

Simplified Packer Template

# template.pkr.hcl
variable "my_var" {
  type = string
}

# foo.pkrvars.hcl
my_var = "foo"

# bar.pkrvars.json
{
  "my_var": "bar"
}

Operating system and Environment details

OS X 14.6.1/Intel

Context

When using third-party tools (e.g. the Kubernetes Cluster API Provider's image-builder project) we may be forced to integrate with existing JSON templates. Although we'd prefer to use HCL in our own .pkrvar files to customize the upstream Packer config we're stuck using JSON.

@joshfrench joshfrench added the bug label Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant