Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Support specifying custom environment variables for input variable default values #2362

Merged
merged 5 commits into from
Sep 28, 2021

Conversation

mitchellh
Copy link
Contributor

@mitchellh mitchellh commented Sep 27, 2021

This lets input variables specify any named environment variable as a source for a default value. Example:

variable "region" {
  type    = string
  env     = ["REGION"]
}

If the REGION env var is set, it will populate the default value of this variable (Note: WP_VAR_region takes priority always). If multiple env vars are specified, the first matching takes priority. If none of the defined env vars are set, the default value (if set) is used. If no default is specified, it is an error since the variable is required and unset.

The env vars specified here are loaded only at the runner (config evaluation time) currently. I'm unsure if we want to expand this to load at CLI time but I would say no, we only want WP_VAR_ variables there, unless the CLI also happens to be the runner (local mode).

This also fixes a potential bug I found where WP_VAR_ variables weren't loaded at runner-time. This could easily be as intended but I think we want to load those at runner-time too so that runner scoped configs can set variables for builds and so on.

TODO: I still have to write docs and validate this a bit more.

Copy link
Contributor

@krantzinator krantzinator left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I think this work expedites the need to output what values were used in a given operation #2137, to lend clarity to what source is providing what value.

@mitchellh
Copy link
Contributor Author

I believe there is good consensus around this. Merging!

@mitchellh mitchellh merged commit 6aa435d into main Sep 28, 2021
@mitchellh mitchellh deleted the feature/var-env branch September 28, 2021 18:19
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants