Introduction
You can create resources that have sensitive data.
When you output this data with default settings you get the following error
│ Error: Output refers to sensitive values
│
│ on main.tf line 23:
│ 23: output "token_value" {
│
│ 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
Expected Outcome
You actually want to read the sensitive data.
Case example
We have the following example code
resource "tfe_team" "test" {
name = "test"
organization = "my-organisation"
}
resource "tfe_team_token" "test" {
team_id = tfe_team.test.id
}
output "token_value" {
value = tfe_team_token.test.token
}
We want to output the actual value of the token_value.
Solution 1:
Use the nonsensitive function in the output
output "token_value" {
value = nonsensitive(tfe_team_token.test.token)
}
Solution 2:
Output the data raw
Add the sensitive option to the output
output "token_value" {
value = tfe_team_token.test.token
sensitive = true
}
Use terraform output command
terraform output -raw token_value
Additional Information
-
Documentation for nonsensitive: https://www.terraform.io/language/functions/nonsensitive
- Documentation for terraform output: https://www.terraform.io/cli/commands/output