A security audit reveals that database passwords managed by Terraform are stored in plaintext in the state file. What is the recommended remediation?

Direct Answer (Verified)Reviewed by Sunny (Senior Cloud Engineer)

Correct Answer: Encrypt the state file at rest using S3 SSE and restrict access with IAM policies; additionally move secrets to AWS Secrets Manager and reference via data source

Terraform state always stores resource attributes including secrets in plaintext JSON. The correct approach is: (1) encrypt state at rest (S3 SSE, Terraform Cloud encrypts by defau...

Real Exam Scenario

A security audit reveals that database passwords managed by Terraform are stored in plaintext in the state file. What is the recommended remediation?

✓ Correct Answer & Explanation

Correct Answer

Encrypt the state file at rest using S3 SSE and restrict access with IAM policies; additionally move secrets to AWS Secrets Manager and reference via data source

Why This Answer Is Correct

Terraform state always stores resource attributes including secrets in plaintext JSON. The correct approach is: (1) encrypt state at rest (S3 SSE, Terraform Cloud encrypts by default), (2) restrict state access with IAM, and (3) move secrets out of Terraform-managed resources into a secrets manager (AWS Secrets Manager, HashiCorp Vault). `sensitive = true` hides values from CLI output but does NOT remove them from state. `.gitignore` for tfvars prevents git leaks but not state exposure.