Goal: I want to print out a sensitive value of foo_resource.name.sensitive_field.
Originally I attempted to create an output:
output "password" {
value = foo_resource.name.sensitive_field
}
and I got
Error: Output refers to sensitive values
│
│ on main.tf line 186:
│ 186: output "password" {
│
│ To reduce the risk of accidentally exporting sensitive data that was intended to be only internal, Terraform requires that any root module output containing sensitive data be
│ explicitly marked as sensitive, to confirm your intent.
│
│ If you do intend to export this data, annotate the output value as sensitive by adding the following argument:
│ sensitive = true
╵
so I added sensitive = true to it:
output "password" {
value = foo_resource.name.sensitive_field
sensitive = true
}
and then when I run it again I got:
$ terraform output
password = <sensitive>
terraform output -raw password
does the trick.
For more details see the doc:
Note: When using the -json or -raw command-line flag, any sensitive values in Terraform state will be displayed in plain text. For more information, see Sensitive Data in State.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With