5 · Platform engineering

13. Infrastructure as Code

Declarative provisioning, state, modules, drift and safe change management.

10 min read · 3 MCQs

Declare, don't click

IaC describes the desired infrastructure in version-controlled files and lets a tool compute the diff. Terraform and OpenTofu are provider-agnostic; CloudFormation, Bicep and Deployment Manager are native; Pulumi and CDK use general-purpose languages.

State and drift

Terraform records reality in a state file that must live in shared, locked remote storage — never on a laptop. Manual console changes create drift; detect it with a scheduled plan and treat any surprise diff as an incident in an environment that matters.

Structure and safety

Split by environment and blast radius, keep reusable modules versioned, and run plan on pull requests with apply gated behind review. Policy-as-code (OPA, Sentinel, tfsec/Checkov) blocks public buckets and open security groups before they exist.

resource "aws_s3_bucket" "artifacts" {
  bucket = "solforge-artifacts-${var.env}"
}

resource "aws_s3_bucket_public_access_block" "artifacts" {
  bucket                  = aws_s3_bucket.artifacts.id
  block_public_acls       = true
  block_public_policy     = true
  ignore_public_acls      = true
  restrict_public_buckets = true
}

Chapter quiz

3 questions · pass mark 75%
  1. 1. Terraform state should be stored…

  2. 2. Configuration drift is…

  3. 3. Policy-as-code is used to…

Answer every question to submit. Progress for cl-13 is saved in this browser.