Interview Prep/CI/CD/GitHub Actions

A team asks for a workflow that deploys Terraform with a plan on PR and apply on merge.

AdvancedScenarioGitHub Actions
Answer

Situation read → Safe IaC pipeline.

What I'd do →

  1. On pull_request: terraform fmt -check, validate, plan -out=tfplan and post the plan as a PR comment; use OIDC with a read-only role.
  2. On push to main: environment production with required reviewers, apply the saved plan from the same commit with a write role.
  3. Use remote state with locking (S3 + DynamoDB or S3 native lockfile) and a concurrency group per state.

Why → Separate roles for plan and apply keep PRs from changing infrastructure.

Interview tip → Plan on PR, apply on merge, with different IAM roles.

All CI/CD questions

More on GitHub Actions