Hi,
When using sensitive values in a variable map/object with the defaults function, a single key will render the full variable sensitive without being possible to use nonsensitive as the values are "known only after apply".
Terraform Version
Terraform v0.15.0-dev @ b3b6099
on darwin_amd64
Terraform Configuration Files
terraform {
experiments = [module_variable_optional_attrs]
}
variable "myvar" {
type = object({
test_bool = optional(bool)
test_string1 = optional(string)
test_string2 = optional(string)
})
default = {}
}
locals {
myvar = defaults(var.myvar, {
test_bool = false
test_string1 = sensitive("mystring")
test_string2 = "mystring"
})
}
output "test_string2" {
value = local.myvar.test_string2
}
╷
│ Error: Output refers to sensitive values
│
│ on main.tf line 22:
│ 22: output "test_string2" {
│
│ Expressions used in outputs can only refer to sensitive values if the sensitive attribute is true.
╵
Changing the output to nonsensitive
output "test_string2" {
value = nonsensitive(local.myvar.test_string2)
}
│ Error: Invalid function argument
│
│ on main.tf line 23, in output "test_string2":
│ 23: value = nonsensitive(local.myvar.test_string2)
│ ├────────────────
│ │ local.myvar.test_string2 is a string, known only after apply
│
│ Invalid value for "value" parameter: the given value is not sensitive, so this call is redundant.
Set field to nonsensitive
locals {
myvar = defaults(var.myvar, {
test_bool = false
test_string1 = sensitive("mystring")
test_string2 = nonsensitive("mystring2")
})
}
│ Error: Invalid function argument
│
│ on main.tf line 18, in locals:
│ 18: test_string2 = nonsensitive("mystring2")
│
│ Invalid value for "value" parameter: the given value is not sensitive, so this call is redundant.
Debug Output
https://gist.github.com/horjulf/d8c5ca9c234c8342c82e8f4ed83f1259
Expected Behavior
Only sensitive fields should be marked as sensitive.
Actual Behavior
The full map/object is marked as sensitive without the possibility of unmarking.
Steps to Reproduce
terraform init
terraform plan
Hi,
When using sensitive values in a variable map/object with the
defaultsfunction, a single key will render the full variable sensitive without being possible to usenonsensitiveas the values are "known only after apply".Terraform Version
Terraform Configuration Files
Changing the output to nonsensitive
Set field to nonsensitive
Debug Output
https://gist.github.com/horjulf/d8c5ca9c234c8342c82e8f4ed83f1259
Expected Behavior
Only sensitive fields should be marked as sensitive.
Actual Behavior
The full map/object is marked as sensitive without the possibility of unmarking.
Steps to Reproduce
terraform initterraform plan