Interview Prep/Terraform/Secrets Provisioners and Policy as Code

How do you avoid Terraform persisting a secret in state when creating a secret in AWS Secrets Manager?

AdvancedScenarioSecrets Provisioners and Policy as Code
Answer

Situation read → Normal resource attributes are always stored in state.

What I'd do →

  1. On Terraform 1.10+, use ephemeral values and ephemeral resources for secrets that are only needed during the run.
  2. On 1.11+, use write-only arguments where the provider supports them (for example secret_string_wo with secret_string_wo_version on aws_secretsmanager_secret_version).
  3. Check the provider docs for support per resource, and fall back to creating the secret container in Terraform while an out-of-band process sets the value.

Why → Write-only arguments are sent to the provider but never written to plan or state.

Interview tip → Know the pattern, and know that support depends on provider version and resource.

All Terraform questions

More on Secrets Provisioners and Policy as Code