How do you avoid hardcoded credentials in Terraform?
BeginnerProductionSecurity, Secrets and Access
Answer
Never put keys in .tf files or tfvars. Use IAM roles and OIDC federation in CI, instance profiles on runners, and SSO profiles for humans. Scan with gitleaks or detect-secrets pre-commit and in CI. For application secrets, store them in a secrets manager and pass ARNs.
More on Security, Secrets and Access
Is reading a secret with a data source safe?IntermediateHow do ephemeral resources and write-only arguments keep secrets out of state?AdvancedWhat is the better pattern for RDS master passwords?BeginnerHow do you scope IAM for the Terraform deploy role?IntermediateWhat are dynamic provider credentials in HCP Terraform?IntermediateHow do you defend against supply-chain risk in providers and modules?Advanced