Open Pinolo opened 3 years ago
Hi @Pinolo!
What you've described here is the intended behavior -- the plan includes the same information Terraform caches in .terraform/terraform.tfstate
to ensure the plan will apply to the same state that it was created from.
I think what you've seen here is an unfortunate consequence of the fact that most of the backends allow setting credentials as arguments as well as out-of-band. Our intention is that the primary way to provide credentials for the backend is via out-of-band mechanisms, which for the http
backend means environment variables, and that the configuration therefore focuses only on describing where the state will be stored and not who or what is running Terraform.
It's a bit of a historical design mistake, born out of pragmatism, that the backends also often allow setting credentials as part of the configuration, but so far we've been reluctant to retract that because it would be a breaking change that doesn't really add any new capabilities that Terraform doesn't already have, and so it would inconvenience those whose threat model doesn't mind credentials stored in the plan without improving anything for those who do.
I think my main takeaway here then is that we ought to be clearer in the documentation for each individual backend in how we distinguish the "location-related" settings from the "user-related" settings, and then include a clear recommendation to prefer settings in the configuration for the location-based ones and out-of-band methods for the user-related ones.
For your case in particular, that would mean removing username
and password
from the configuration and setting TF_HTTP_USERNAME
and TF_HTTP_PASSWORD
instead, where all of the remaining arguments in your example are describing the details of where and how to store and manipulate the state.
Thanks for raising this!
Hi @apparentlymart, thanks for the detailed explanation. I see the point and I agree that better docs will help. A couple of suggestions for the docs enhancements.
I've also been affected by this, specifically in CI/CD pipelines with gitlab similar to what you mentioned @Pinolo. I've proposed a change to the docs to document this in https://github.com/hashicorp/terraform/pull/29519
Terraform Version
Terraform Configuration Files
Debug Output
https://gist.github.com/Pinolo/2aeb7ab20289a4ccade89014d5eeccd5
Expected Behavior
Backend configuration values (including sensitive info) are not saved to resulting tfplan
Actual Behavior
Backend configuration values (including sensitive info) are saved to resulting tfplan
Steps to Reproduce
terraform init
terraform plan -out planenv
unzip planenv
less tfplan
Additional Context
The same behavior is recorded when passing the backend config values as options for the
terraform init
command.If I set backend configuration using only environment variables, configuration values are not saved into the tfplan file (only configuration keys are). I don't know what is the intended behavior, but I see at least an undocumented inconsistency.