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

hcl2: Provide an option for disable warnings on undeclared variables within a var-file #12109

Closed
nywilken opened this issue Nov 11, 2022 · 1 comment · Fixed by #12104
Closed

Comments

@nywilken
Copy link
Contributor

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

Please search the existing issues for relevant feature requests, and use the
reaction feature
(https://blog.github.com/2016-03-10-add-reactions-to-pull-requests-issues-and-comments/)
to add upvotes to pre-existing requests.

Description

Previously for JSON legacy templates the use of variable definition files containing one or more variables that were not declared in the "variables" JSON property Packer would execute without warning. The same build using HCL templates warn for undeclared variables. The only option for silencing the warnings is to defined the variable within the template with a default value, which is confusing if the variable is not used anywhere in the template; this is issue is greatly amplified when the variable definition file contains many unused variables for the said template.

Use Case(s)

When using a shared variables definition file that is used as an input to multiple template files it would be great to have an option for disabling the warning for undeclared variables within a var-file. Having to update each of the templates with default values for the unused variables is tedious and confusing for users looking at the template that contains a bunch of declared but unused variables.

Potential configuration

shared-variables.json

{
  "region": "us-west-2",
  "username": "nywilken"
}

build.pkr.hcl

variable "username" {
 type     =  string
 default = "packer"
}

source "null" "example" {
  communicator = "none"
}

build {
  sources = ["source.null.example"]
  provisioner "shell-local" {
    inline = [ "echo 'Running a build as ${var.username}'"]
  }
}
~>  packer build -var-file=/tmp/shared.json /tmp/build.pkr.hcl
Warning: Undefined variable

A "region" variable was set but was not declared as an input variable. To
declare variable "region", place this block in one of your .pkr.hcl files, such
as variables.pkr.hcl

variable "region" {
  type = string
}


null.example: output will be in this color.

==> null.example: Running local shell script: /var/folders/jd/zhl6kpsn1156cmqdyttt22xm0000gp/T/packer-shell3565688691
    null.example: Running a build as nywilken
Build 'null.example' finished after 139 milliseconds 711 microseconds.

==> Wait completed after 139 milliseconds 761 microseconds

==> Builds finished. The artifacts of successful builds are:
--> null.example: Did not export anything. This is the null builder

Potential References

Relevant discussion :#12020 (comment)

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant