The database was bleeding secrets, and no one noticed until the auditors came. PII data had slipped into Terraform-managed infrastructure like a shadow through a broken door. Someone had to fix it—fast.
Managing PII data with Terraform is high stakes. Infrastructure as code gives speed, but it also magnifies mistakes. A single misconfigured variable can expose customer names, emails, or government IDs across state files, logs, or cloud provider metadata. When you commit that to Git, the exposure becomes permanent.
The first safeguard is to stop storing PII in Terraform code or state files entirely. Use data sources that pull sensitive values at runtime instead of hardcoding them. Remote backends like AWS S3 or Terraform Cloud must have strong encryption and access controls. Versioned and locked state files prevent unauthorized reads and overwrites.
Secrets managers are essential. Tools like AWS Secrets Manager, HashiCorp Vault, or GCP Secret Manager integrate with Terraform to supply PII securely. Replace plain variables with references to these vaults. Never echo sensitive outputs—mark them as sensitive = true to block accidental logging.