Terraform & IaC (50 Qs)•Part 1: Terraform Core Architecture, HCL & Providers (1 - 15)
How do you protect sensitive secrets from leaking into plaintext Terraform State files?
senior LevelFormsCI/CD & DevOpsSystem Design
In Simple Words: Terraform state files store all resource attributes—including database passwords, TLS private keys, and API tokens—in plaintext JSON.
Protection strategy:
- Enable Server-Side Encryption (SSE-KMS) and strict IAM bucket policies on the S3 state bucket.
- Restrict state bucket access: Only CI/CD runner service accounts and platform admins should have read access.
- Mark sensitive variables with
sensitive = trueso values are redacted from terminal and CI logs. - Delegate secrets generation to KMS or cloud secrets managers (AWS Secrets Manager / Vault) rather than generating plaintext passwords inside Terraform.