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 →
- On Terraform 1.10+, use ephemeral values and ephemeral resources for secrets that are only needed during the run.
- On 1.11+, use write-only arguments where the provider supports them (for example
secret_string_wowithsecret_string_wo_versiononaws_secretsmanager_secret_version). - 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.
More on Secrets Provisioners and Policy as Code
A developer hardcodes a DB password in `terraform.tfvars` and commits it. What do you do right now, and what's the long-term fix?BeginnerSomeone wants a `remote-exec` provisioner to configure servers after creation. What's your advice?BeginnerYou must run a one-off command after a resource is created, such as registering with an external system.IntermediateHow do you generate and manage the master password for a new RDS instance?IntermediateCompare Sentinel, OPA/Conftest and Checkov for policy as code.IntermediateHow do you prevent public S3 buckets from ever reaching production via Terraform?Intermediate