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

Optionally allow variables defined in HCL to be available in all provisioners (like shells) as env vars with prefix TF_VAR #25780

Open
queglay opened this issue Aug 8, 2020 · 1 comment

Comments

@queglay
Copy link

queglay commented Aug 8, 2020

Current Terraform Version

0.12.29

Use-cases

When using Terraform and Ansible together, I tend to have to define more vars as env vars than I'd like (TF_VAR*). To make values easily available to both of these programs, I default to using env vars usually. Since I have to manage that in a shell script I tend to manage more vars as env vars than I would want to.

I would prefer to define as many vars in HCL or Ansible yaml as possible (including Ansible crypt encrypted vars), but if defined in HCL these values aren't readily available to ansible shell scripts in Terraform local shell provisioners.

It would be a fantastic workflow improvement if we could flag Terraform vars to be exported into shells, and made available via the standard $TF_VAR_* prefix. This would allow the majority of variables I use to be removed out of bash and defined in HCL or (yaml possibly?)

Attempted Solutions

Define all vars as env vars.

Proposal

Provide a flag when defining a var or local that it will be exported as an env var.

References

@queglay queglay added enhancement new new issue not yet triaged labels Aug 8, 2020
@mildwonkey
Copy link
Contributor

Hi @queglay, thank you for submitting this feature request. I am going to keep this open for now, but I do have some suggestions for workarounds:

I know this doesn't meet your needs, but for anyone else looking at this issue you can define environment vars when using the local-exec provisioner: https://www.terraform.io/docs/provisioners/local-exec.html#environment

With remote-exec and other similar provisioners, I'd suggest writing a file to the machine containing your variables that you can use in whatever way is appropriate to the OS you are provisioning.

I'd also like to draw attention to the provisioners documentation where we have some suggestions for alternatives to using provisioners. We consider provisioners a "last resort" and find that there are usually (but not always!) better alternatives.

@mildwonkey mildwonkey removed the new new issue not yet triaged label Aug 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants