In my CI environment (Bitbucket pipelines) I'm trying to use the new Terraform Cloud remote state management. The announcement video clearly states you can use environment variables instead of the .terraformrc
file to pass your API token. However, I cannot find any documentation on the exact environment variable I have to use.
I followed the getting started guide about Terraform Cloud, but there they also don't mention anything about environment variables.
I also looked at the environment variables section of the Terraform documentation, but there was also no mentioning of how to set (or override) the cli configuration.
Best Answer
If you are using the Terraform Cloud/Enterprise provider, you could set the
TFE_TOKEN
environment variable.Alternatively, you could write the terraform config file temporarily during the build, e.g.:
Otherwise, you could (but not recommended) manipulate the
credentials.tfrc.json
in~/.terraform.d
but beware that this may be overwritten when running terraform commands. For example using jq in bash:You should get the following when e.g. running
cat ~/.terraform.d/credentials.tfrc.json
: