Terraform in CI/CD Pipelines

Production-level Terraform CI/CD: Code Commit → Validate → Format Check → Terraform Init → Plan → Policy Check (Sentinel/OPA) → Manual Approval → Apply. Remote state in S3 + DynamoDB lock. GitHub Actions flow, folder structure, and best practices for safe infrastructure automation.

Overview

Why Terraform needs a pipeline

Running Terraform manually is fine for experiments. In production without CI/CD there is no peer review, no audit trail, no policy enforcement and no protection against two people applying at once.

A pipeline fixes all four. It is consistent, because the same pipeline runs every time. It is collaborative, because changes are reviewed through a pull request (PR). It is auditable, because the CI logs keep the full history. And it is safe, because policy gates and a manual approval stand before Apply.

Key concepts

  • terraform plan artifact
  • DynamoDB state locking
  • Sentinel / OPA policy as code
  • Manual approval gate
  • Workspace vs environment folders
  • Checkov

Interview questions

  • How do you safely run Terraform in a CI/CD pipeline?
  • Describe Terraform remote state with S3 and DynamoDB.

Sign up free to read the full topic

More DevOps topics

Start free on Cariara · Coding problems · System design studio