Design least-privilege IAM for a Terraform pipeline.
AdvancedScenarioSecrets Provisioners and Policy as Code
Answer
Situation read → Pipelines often run as AdministratorAccess.
What I'd do →
- Two roles:
plan(read-only plus state read, lock write) andapply(write permissions scoped to the services in that stack). - PR pipelines assume
plan; only the protected main-branch job assumesapply. - Add permission boundaries and use IAM Access Analyzer's policy generation from CloudTrail to tighten.
- Restrict by trust policy to the exact repo and branch.
Why → A compromised PR can run arbitrary code in plan, so plan must not be able to change anything.
Interview tip → Mention that terraform plan runs provider and data source code from your PR.
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?BeginnerHow do you avoid Terraform persisting a secret in state when creating a secret in AWS Secrets Manager?AdvancedSomeone 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.Intermediate