Yashotantra Academy logo

3 · Infrastructure as Code

3. Terraform State Management & Policy as Code

Remote state locking, module design, drift detection, and OPA/Checkov compliance.

10 min read · 2 MCQs

State Locking & Remote Backends

Terraform maps configuration to real-world resources via state files. Storing state in remote buckets (S3 with DynamoDB locking, GCS, Terraform Cloud) prevents concurrent executions from corrupting infrastructure state.

Policy as Code with Open Policy Agent

Shift security left by asserting rules against `terraform plan` output JSON. Automated pipelines reject plans that create world-open security groups (0.0.0.0/0) or unencrypted S3 buckets before resources are provisioned.

Chapter quiz

2 questions · pass mark 75%
  1. 1. What danger does DynamoDB state locking prevent in Terraform?

  2. 2. What is configuration drift?