-
Notifications
You must be signed in to change notification settings - Fork 9.7k
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
Can't use sensitive value in dynamic for_each #29744
Comments
Hi @camlow325, thanks for reporting this. I can reproduce this behaviour with The cause is that we haven't added support for sensitive We would also have to determine how to prevent sensitive iterator values from being used in the list of labels, which (like resource instance keys) would result in sensitive value escaping. |
I just ran face-first into this.
This is not intuitive, either from the error message or the documentation on input variables. If there are no plans to support sensitive values in dynamic for_each, a more clear warning message, or updated documentation or both would help prevent someone else from the same frustration. |
That's a good point, and I agree that this error message is poor. An interim improvement for this issue could detect a sensitive |
TF noob here. I spent a good hour messing around with different kinds of types to try and work around this problem, when in fact the error was due to the input being sensitive. My use case is mapping environment settings from a secrets file decrypted with SOPS straight into the env block of a Docker container definition. Iterating directly over a map of secrets is far easier to manage and reason about than specifying each environment variable block twice: once for the actual key/value map, and again for the block. I'm using the |
For the record, there's a variant of the error message with apparently the same cause:
Searching for that error message gave no result, so I figured adding a comment here would not hurt. Especially as it is even less understandable as the sensitive keyword does not appear. When I added a
The work-around to use
Edit: Edit 2:
|
In a complex scenario, it took me around 5 hours (and a rubberduck companion for an hour) to finally end up here and see that the issue was due to my inputs being sensitive. To make it short, I think it would already be a lot easier to debug if the error message would at least say something along the lines of "reminder: sensitive values are not iterable". |
I'm counting 12 hours , burning the midnight oil trying to find an obscure sensitive value breaking my for_each. Any tips for doing this? Many modules involved. Can't see any sensitive = true in the code we own. I'm left thinking the azurerm provider is baking in sensitive value and it is part of the dependency graph. |
still no solution here here? 😢 |
Had the same problem for an ALB listener rule with dynamic query strings. I solved this by splitting the original variable definition. From this: variable "basic_auth" {
type = object({
username = string
password = string
enabled = bool
query_strings = list(object({
key = string
value = string
}))
})
sensitive = true
} To this: variable "basic_auth_credentials" {
type = object({
username = string
password = string
})
sensitive = true
}
variable "basic_auth_config" {
type = object({
enabled = bool
query_strings = list(object({
key = string
value = string
}))
})
} So I can use |
This comment was marked as off-topic.
This comment was marked as off-topic.
it's end of 2024 and neither the issue, nor the error message was rectified:
came from this dynamic block:
whilst trying to set some values in Helm values.yaml |
Terraform Version
Terraform Configuration Files
Note that this example uses an arbitrary Helm chart, just to demonstrate the behavior around processing of the dynamic
set_sensitive
attribute.Debug Output
Crash Output
Expected Behavior
In prior versions of Terraform (we last tried
0.13.5
) — albeit without the input variable being marked assensitive
since that wasn't supported yet — the Terraform apply succeeded.Actual Behavior
In Terraform
1.0.8
, we see the following error:As described in for_each documentation, we understand that this new behavior is intentional for
resources
(and, therefore, presumably tomodules
as well):It wasn't clear to us, however, if this behavior was intentionally intended to apply for
dynamic
attributes of a resource. We can work around the error by using thenonsensitive
function, like this:That could work here since the
set_sensitive
attribute is inherently sensitive in ahelm_release
resource and so would be redacted from UI output. It just seemed incorrect to have to do that when using content that fundamentally is sensitive.Steps to Reproduce
terraform init
TF_VAR_secrets='{secret_1_key: "secret_1_val", secret_2_key: "secret_2_val"}' terraform apply
Additional Context
References
The text was updated successfully, but these errors were encountered: