Interview Prep/Terraform/Secrets Provisioners and Policy as Code

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 →

  1. Two roles: plan (read-only plus state read, lock write) and apply (write permissions scoped to the services in that stack).
  2. PR pipelines assume plan; only the protected main-branch job assumes apply.
  3. Add permission boundaries and use IAM Access Analyzer's policy generation from CloudTrail to tighten.
  4. 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.

All Terraform questions

More on Secrets Provisioners and Policy as Code