1

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>
Alex Kuzminov
  • 325
  • 3
  • 13

1 Answers1

9
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.
Alex Kuzminov
  • 325
  • 3
  • 13
  • 8
    You don't even need `-raw`. You just have to specify the individual value name: `terraform output password` – Mark B Feb 17 '22 at 13:33