Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I print out sensitive values from terraform state? [duplicate]

Tags:

terraform

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>
like image 740
Alex Kuzminov Avatar asked Nov 02 '25 01:11

Alex Kuzminov


1 Answers

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.
like image 76
Alex Kuzminov Avatar answered Nov 04 '25 15:11

Alex Kuzminov