Skip to main content

Fix Terraform Error - Output Refers to Sensitive Value

Key Takeaway

An output references a sensitive variable or attribute without marking the output as sensitive. Step-by-step guide with code examples and best practices for ...

Table of Contents

The Error

When working with Terraform, you may encounter this error:

Error: Output refers to sensitive values

This error can block your entire workflow. Let’s understand why it happens and how to fix it.

What Causes This Error

An output references a sensitive variable or attribute without marking the output as sensitive.

How to Fix It

Solution 1

Add sensitive = true to the output block.

Solution 2

Use nonsensitive() function if you intentionally want to expose the value.

Solution 3

Wrap the value: output “db_password” { value = var.db_password; sensitive = true }

Solution 4

Review which outputs truly need to be sensitive vs public.

Prevention Tips

  • Always run terraform validate before terraform plan
  • Use terraform fmt to keep configuration clean and readable
  • Pin provider versions to avoid unexpected schema changes
  • Review plan output carefully before applying

Learn More

Conclusion

Related: AWS: Increase EC2 root_block_device size — resize your EC2 storage with Terraform.

This error is common but straightforward to fix. The key is understanding the root cause and applying the correct solution for your specific situation. Following the prevention tips above will help you avoid this error in future projects.

🚀

Level Up Your Terraform Skills

Hands-on courses, books, and resources from Luca Berton

Luca Berton
Written by

Luca Berton

DevOps Engineer, AWS Partner, Terraform expert, and author. Creator of Ansible Pilot, Terraform Pilot, and CopyPasteLearn.