Secrets expire. Systems break. Unrotated passwords become attack vectors. Terraform can enforce password rotation policies before weaknesses spread.
Password rotation policies in Terraform define how often credentials change and how they are replaced without manual intervention. Automated rotation reduces human error, shortens the lifespan of compromised secrets, and meets compliance requirements like PCI-DSS or ISO 27001.
The fastest path is to use Terraform’s integration with secret managers such as AWS Secrets Manager, HashiCorp Vault, or GCP Secret Manager. These providers allow you to define rotation intervals and attach them to IAM roles, database logins, or API keys. Terraform state tracks infrastructure, but by externalizing passwords to a secret manager, you avoid storing them in state files, preventing leaks through version control or backups.
A best practice is to combine rotation rules with resource dependencies to trigger an update whenever the credential changes. Using Terraform null_resource with local-exec scripts or provider-specific rotation resources ensures the new secrets deploy automatically to all dependent systems. Policies should define rotation frequency, method (rekeying versus generating fresh), and immediate propagation of new credentials to all services.