raymondbutcher / pretf

Generate Terraform code with Python
https://pretf.readthedocs.io/
MIT License
104 stars 14 forks source link

Helper function to load tfvars into environment variables #27

Open raymondbutcher opened 5 years ago

raymondbutcher commented 5 years ago

In the workspace example it mirrors (symlinks) a tfvars file into the current directory so it will get loaded automatically (and the other files in the params dir won't get loaded).

https://github.com/raymondbutcher/pretf/blob/77ef2f69681556a8a05dc584b8582994fc6e8c63/examples/workspaces/pretf.workflow.py#L25-L27

This symlink could be avoided by parsing the file and exporting TF_VAR_* environment variables for each value found in the file.

This would be a work around for Terraform not being able to load tfvars per workspace and perhaps other use cases I haven't thought of. Maybe people just prefer their params to be sitting together in a separate directory, I don't know.

Usage might be like this:

workflow.export_variables_from_file(f"{terraform.workspace}.workspace.tfvars")