-
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
Feature Request: required variables settable through environment #6988
Comments
So to clarify, you want to be able to have Packer check for environment variables if the variable isn't already set inside your packer config? |
@SwampDragons so my issue is the following. Let's say you have one Packer variable called You define it in Packer like this:
Now that variable is required and the only way to provide it is through command line, e.g.:
This call has some big downsides: it requires you to know all variable names defined in the packer file, it requires you to assemble a specific command line call rather than using a generic one - as it's common practice in more automated systems. Also the long command line becomes unreadable quickly . What I can do in Packer instead is the following:
Now I can define my variables independently of the command line call, and I can access commonly known environment variables (e.g.
While this solves a problem, it introduces a new one: what if my environment variable I wish I could tell Packer: "This variable can be set through command line, or environment, but it has to be set one way or another!" Just to recap, I am not suggesting changing Packer's way of handling user variables in a backward incompatible way. I am suggesting adding some syntax to mark user variables as required, while preserving the possibility to set them through the environment. |
Okay, I can see the benefit of that. It's a good idea. Off the top of my head, I'm not totally sure how easy it will be to implement because of the way Packer's architecture handles variables, so I'll have to take a look at that before deciding if it's something we can prioritize soon. Meanwhile, have you considered using a |
I think the simplest way would be to assume that if an environment variable is empty, then default the value to be |
I think we may get this behavior "for free" as part of the HCL2 config effort that we're hoping to land this year. |
Hello there this is implemented in #8588; only for hcl2 but basically after defining a variable; one will be able to set it by setting an env var like so: |
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. |
Right now we can either specify a user variable as
null
which means it's required and it can only be set using the CLI option, or we can use{{env `foo`}}
to make it settable through the environment. I am missing an option to set a variable as required, with the option to set it through the environment.Sidenote: Terraform offers this functionality. There all variables are required by default and can be set using the
TV_VAR_
prefix for environment variables: https://www.terraform.io/docs/configuration/variables.html#environment-variablesThe text was updated successfully, but these errors were encountered: