AI DeliveryPreview Learning Center

Real case: three clouds, real runs

Infrastructure as code: three clouds, four validators, zero credentials

What an agent writes from one sentence, what the ladder catches before anything reaches a plan, and the loop that makes the agent fix it. Terraform for AWS, Azure and GCP, every number from a real run.

Proves the stages: Architect · Release. Moved here from the test center, where the tests it runs still live.

The ladder

Five rungs before a plan, none of them needing an account

An agent writes infrastructure quickly and plausibly, and the first draft deploys. The problems are the controls it did not know your team requires. The ladder runs in seconds on a laptop, in the agent's own hook, and in CI on every pull request, and the apply credential stays where the agent cannot reach it.

  1. 1

    Format tofu fmt -check (or terraform fmt)

    Style, and a parse of every file. Free, instant, and the agent runs it after every edit.

    Credentials: none

  2. 2

    Lint tflint with the terraform, aws, azurerm and google rulesets

    Missing required_version, deprecated arguments, invalid instance types, data resources that should be protected from deletion: provider-specific mistakes a plan would not catch.

    Credentials: none

  3. 3

    Scan checkov -d module --framework terraform

    Hundreds of security checks per provider: public access, encryption, logging, TLS, versioning, each with the resource and the lines. SARIF output lands in the Security tab.

    Credentials: none

  4. 4

    Policy conftest test --parser hcl2 -p policy

    The team's own rules in Rego, read straight from the HCL. The rules have tests of their own (conftest verify).

    Credentials: none

  5. 5

    Test tofu test (terraform test) with mock_provider

    Plan the module against generated values and assert on the result: the controls are really in the configuration, not just absent from the findings.

    Credentials: none (the provider binaries, not an account)

  6. then

    Plan and apply CI only, through OIDC, in a protected environment

    The agent never holds the apply credential; its hook blocks the command; the pipeline applies from main after review.

    Credentials: cloud credentials, in CI

Tools as read on 2026-10-25: TFLint terraform ruleset: rules · Checkov CLI command reference · Conftest · Terraform: tests, mocking (mock_provider, override blocks). Versions in the run: OpenTofu 1.11.0, tflint 0.65.0 with aws 0.50.0, azurerm 0.32.0 and google 0.40.0 rulesets, Checkov 3.3.30, Conftest 0.71.1.

Draft and fixed

The same bucket, three clouds: what the agent wrote and what the ladder made of it

"Give me a bucket for the export job." The drafts are what an agent produces from that sentence: correct, deployable, and missing every control. The numbers are read from the unedited transcripts of the ladder run on 2026-10-25. Across the three drafts Checkov passed 9 checks and failed 16; across the fixed modules it passed 56 and failed 0, with six exceptions recorded below.

Draft: as the agent wrote it

  • 1 tflint issue
  • 4 Checkov failed, 5 passed
  • 1 policy failure of 5 rules
  • ladder failed
infra/draft/aws/main.tf
# First draft, as an agent wrote it from "give me a bucket for the export job".
terraform {
  required_providers {
    aws = { source = "hashicorp/aws", version = "~> 6.0" }
  }
}

provider "aws" {
  region = "ca-central-1"
}

resource "aws_s3_bucket" "exports" {
  bucket = "acme-exports-prod"
}
What the ladder reported
  • tflint terraform_required_version
  • CKV2_AWS_6 Ensure that S3 bucket has a Public Access block aws_s3_bucket.exports
  • CKV2_AWS_61 Ensure that an S3 bucket has a lifecycle configuration aws_s3_bucket.exports
  • CKV_AWS_21 Ensure all data stored in the S3 bucket have versioning enabled aws_s3_bucket.exports
  • CKV_AWS_145 Ensure that S3 buckets are encrypted with KMS by default aws_s3_bucket.exports
  • policy aws_s3_bucket.exports: no aws_s3_bucket_versioning enables versioning for it

Fixed: after the ladder

  • 0 tflint issues
  • 0 Checkov failed, 31 passed
  • 0 policy failures of 5 rules
  • ladder passed
infra/fixed/aws/main.tf
# After the ladder: versioning, SSE-KMS, every public access path blocked, access logs, lifecycle
# rules, a key policy, and nothing that holds data can be destroyed by accident.
terraform {
  required_version = ">= 1.7"
  required_providers {
    aws = { source = "hashicorp/aws", version = "~> 6.0" }
  }
}

provider "aws" {
  region = "ca-central-1"
}

data "aws_caller_identity" "current" {}

resource "aws_s3_bucket" "exports" {
  bucket = "acme-exports-prod"

  lifecycle {
    prevent_destroy = true
  }
}

resource "aws_s3_bucket_versioning" "exports" {
  bucket = aws_s3_bucket.exports.id
  versioning_configuration {
    status = "Enabled"
  }
}

resource "aws_s3_bucket_server_side_encryption_configuration" "exports" {
  bucket = aws_s3_bucket.exports.id
  rule {
    apply_server_side_encryption_by_default {
      sse_algorithm     = "aws:kms"
      kms_master_key_id = aws_kms_key.exports.arn
    }
  }
}

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

resource "aws_s3_bucket_lifecycle_configuration" "exports" {
  bucket = aws_s3_bucket.exports.id
  rule {
    id     = "expire-old-versions"
    status = "Enabled"
    filter {}
    noncurrent_version_expiration {
      noncurrent_days = 90
    }
    abort_incomplete_multipart_upload {
      days_after_initiation = 7
    }
  }
}

resource "aws_s3_bucket_logging" "exports" {
  bucket        = aws_s3_bucket.exports.id
  target_bucket = aws_s3_bucket.logs.id
  target_prefix = "exports/"
}

# The access-log bucket gets the same controls, minus logging into itself.
resource "aws_s3_bucket" "logs" {
  bucket = "acme-exports-prod-logs"

  lifecycle {
    prevent_destroy = true
  }
}

resource "aws_s3_bucket_versioning" "logs" {
  bucket = aws_s3_bucket.logs.id
  versioning_configuration {
    status = "Enabled"
  }
}

resource "aws_s3_bucket_server_side_encryption_configuration" "logs" {
  bucket = aws_s3_bucket.logs.id
  rule {
    apply_server_side_encryption_by_default {
      sse_algorithm     = "aws:kms"
      kms_master_key_id = aws_kms_key.exports.arn
    }
  }
}

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

resource "aws_s3_bucket_lifecycle_configuration" "logs" {
  bucket = aws_s3_bucket.logs.id
  rule {
    id     = "expire-logs"
    status = "Enabled"
    filter {}
    expiration {
      days = 365
    }
    abort_incomplete_multipart_upload {
      days_after_initiation = 7
    }
  }
}

resource "aws_kms_key" "exports" {
  description         = "acme-exports-prod"
  enable_key_rotation = true
  policy = jsonencode({
    Version = "2012-10-17"
    Statement = [{
      Sid       = "AccountAdministersTheKey"
      Effect    = "Allow"
      Principal = { AWS = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:root" }
      Action    = "kms:*"
      Resource  = "*"
    }]
  })

  lifecycle {
    prevent_destroy = true
  }
}
What the ladder reported

Nothing reported.

Drafts, fixed modules, tests, policy, the workflow and the hooks: 20 files of the example project, zipped in your browser.

Policy as code

The team's rules, in Rego, read from the HCL, with tests of their own

Scanners know the general rules. The team's rules (TLS 1.2 on every storage account, public access prevention on every bucket, versioning on every S3 bucket) go in a policy Conftest evaluates against the configuration itself, no plan and no credentials. A policy is code: it has tests, and conftest verify runs them.

The rules

infra/policy/storage.rego
# Policy as code for the team's storage rules, in Rego, checked by Conftest against the HCL
# itself (no plan, no credentials). Conftest's HCL parser gives each resource as a list of
# blocks, so every rule reads input.resource.<type>[name][_].
package main

deny contains msg if {
  some name
  input.resource.aws_s3_bucket[name]
  not versioning_enabled_for(sprintf("${aws_s3_bucket.%s.id}", [name]))
  msg := sprintf("aws_s3_bucket.%s: no aws_s3_bucket_versioning enables versioning for it", [name])
}

versioning_enabled_for(bucket_ref) if {
  some v
  block := input.resource.aws_s3_bucket_versioning[v][_]
  block.bucket == bucket_ref
  block.versioning_configuration[_].status == "Enabled"
}

deny contains msg if {
  some name
  sa := input.resource.azurerm_storage_account[name][_]
  sa.min_tls_version != "TLS1_2"
  msg := sprintf("azurerm_storage_account.%s: min_tls_version must be TLS1_2", [name])
}

deny contains msg if {
  some name
  sa := input.resource.azurerm_storage_account[name][_]
  not sa.allow_nested_items_to_be_public == false
  msg := sprintf("azurerm_storage_account.%s: allow_nested_items_to_be_public must be false", [name])
}

deny contains msg if {
  some name
  b := input.resource.google_storage_bucket[name][_]
  not b.public_access_prevention == "enforced"
  msg := sprintf("google_storage_bucket.%s: public_access_prevention must be enforced", [name])
}

deny contains msg if {
  some name
  b := input.resource.google_storage_bucket[name][_]
  not b.uniform_bucket_level_access == true
  msg := sprintf("google_storage_bucket.%s: uniform_bucket_level_access must be true", [name])
}

Their tests

infra/policy/storage_test.rego
# Tests for the policy itself: conftest verify -p policy. The inputs mirror what Conftest's HCL
# parser produces: each resource as a list of blocks.
package main

test_azure_tls10_is_denied if {
  doc := {"resource": {"azurerm_storage_account": {"x": [{"min_tls_version": "TLS1_0", "allow_nested_items_to_be_public": false}]}}}
  deny["azurerm_storage_account.x: min_tls_version must be TLS1_2"] with input as doc
}

test_azure_public_blobs_denied_when_unset if {
  doc := {"resource": {"azurerm_storage_account": {"x": [{"min_tls_version": "TLS1_2"}]}}}
  deny["azurerm_storage_account.x: allow_nested_items_to_be_public must be false"] with input as doc
}

test_gcp_enforced_and_uniform_passes if {
  doc := {"resource": {"google_storage_bucket": {"b": [{"public_access_prevention": "enforced", "uniform_bucket_level_access": true}]}}}
  count(deny) == 0 with input as doc
}

test_aws_bucket_without_versioning_is_denied if {
  doc := {"resource": {"aws_s3_bucket": {"logs": [{"bucket": "x"}]}}}
  deny["aws_s3_bucket.logs: no aws_s3_bucket_versioning enables versioning for it"] with input as doc
}

test_aws_bucket_with_versioning_passes if {
  doc := {"resource": {
    "aws_s3_bucket": {"exports": [{"bucket": "x"}]},
    "aws_s3_bucket_versioning": {"exports": [{"bucket": "${aws_s3_bucket.exports.id}", "versioning_configuration": [{"status": "Enabled"}]}]},
  }}
  count(deny) == 0 with input as doc
}

conftest verify -p policy

5 tests, 5 passed, 0 warnings, 0 failures, 0 exceptions, 0 skipped

Conftest's HCL parser gives each resource as a list of blocks, so every rule reads input.resource.<type>[name][_]; a rule that reads the wrong shape passes silently, which is the first reason to test the policy. Conftest

Test it like code

terraform test with mock providers: assert the plan, no cloud account

Since Terraform 1.7, a .tftest.hcl file can declare mock_provider "aws" {}: the test runs plan (or apply) against values the mock generates, and assert blocks check the configuration the way a unit test checks a function. mock_resource and mock_data set defaults, override_resource and override_data pin specific values, and override_during chooses plan or apply.

Not run here. These three files are shown as written. The machine that produced this page could not download the provider binaries the mock providers still need, so rung 5 did not run; rungs 1 to 4 did. Run tofu test (or terraform test) in each fixed module directory with provider access.

fixed/aws/tests/storage.tftest.hcl
infra/fixed/aws/tests/storage.tftest.hcl
# terraform test with a mock provider: plan the module against generated values, no AWS account,
# and assert the controls are in the configuration. Terraform 1.7 and later, OpenTofu 1.7 and later.
mock_provider "aws" {}

run "exports_bucket_is_locked_down" {
  command = plan

  assert {
    condition     = aws_s3_bucket_versioning.exports.versioning_configuration[0].status == "Enabled"
    error_message = "the exports bucket must have versioning enabled"
  }

  assert {
    condition     = aws_s3_bucket_server_side_encryption_configuration.exports.rule[0].apply_server_side_encryption_by_default[0].sse_algorithm == "aws:kms"
    error_message = "the exports bucket must be encrypted with a KMS key"
  }

  assert {
    condition = alltrue([
      aws_s3_bucket_public_access_block.exports.block_public_acls,
      aws_s3_bucket_public_access_block.exports.block_public_policy,
      aws_s3_bucket_public_access_block.exports.ignore_public_acls,
      aws_s3_bucket_public_access_block.exports.restrict_public_buckets,
    ])
    error_message = "every public access path must be blocked"
  }

  assert {
    condition     = aws_kms_key.exports.enable_key_rotation
    error_message = "the KMS key must rotate"
  }

  assert {
    condition     = aws_s3_bucket_logging.exports.target_prefix == "exports/"
    error_message = "access logs go to the logs bucket under exports/"
  }
}
fixed/azure/tests/storage.tftest.hcl
infra/fixed/azure/tests/storage.tftest.hcl
# terraform test with a mock provider: no subscription, no credentials; the plan is asserted.
mock_provider "azurerm" {}

run "storage_account_is_private_tls12_and_versioned" {
  command = plan

  assert {
    condition     = azurerm_storage_account.exports.min_tls_version == "TLS1_2"
    error_message = "TLS 1.2 is the minimum"
  }

  assert {
    condition     = azurerm_storage_account.exports.https_traffic_only_enabled
    error_message = "HTTPS only"
  }

  assert {
    condition = alltrue([
      azurerm_storage_account.exports.allow_nested_items_to_be_public == false,
      azurerm_storage_account.exports.shared_access_key_enabled == false,
      azurerm_storage_account.exports.public_network_access_enabled == false,
    ])
    error_message = "no public blobs, no shared key, no public network access"
  }

  assert {
    condition     = azurerm_storage_account.exports.blob_properties[0].versioning_enabled
    error_message = "blob versioning must be on"
  }

  assert {
    condition     = azurerm_storage_account.exports.network_rules[0].default_action == "Deny"
    error_message = "the network rules must deny by default"
  }
}
fixed/gcp/tests/storage.tftest.hcl
infra/fixed/gcp/tests/storage.tftest.hcl
# terraform test with a mock provider: no project, no credentials; the plan is asserted.
mock_provider "google" {}

run "bucket_is_uniform_private_versioned_and_encrypted" {
  command = plan

  assert {
    condition     = google_storage_bucket.exports.public_access_prevention == "enforced"
    error_message = "public access prevention must be enforced"
  }

  assert {
    condition     = google_storage_bucket.exports.uniform_bucket_level_access
    error_message = "uniform bucket-level access must be on"
  }

  assert {
    condition     = google_storage_bucket.exports.versioning[0].enabled
    error_message = "object versioning must be on"
  }

  assert {
    condition     = length(google_storage_bucket.exports.encryption) == 1
    error_message = "the bucket must name a customer-managed key"
  }

  assert {
    condition     = google_kms_crypto_key.exports.rotation_period == "7776000s"
    error_message = "the key rotates every 90 days"
  }

  assert {
    condition     = google_storage_bucket.logs.public_access_prevention == "enforced"
    error_message = "the logs bucket is private too"
  }
}

Terraform: tests, mocking (mock_provider, override blocks)

Exceptions as code

What the fixed modules still do not do, and who decided

Checkov's remaining findings after the second pass were decisions, not omissions: cross-region replication, event notifications, a private endpoint, a customer-managed key for Azure, logging of the log buckets. Each became a line in .checkov.yaml with an owner, a reason and a review date, so the exception is reviewed with the code and expires on purpose. The agent is told never to add an inline skip comment.

infra/.checkov.yaml
# Checkov's settings for this repository. Every skip is an exception with an owner, a reason and
# a review date; adding one changes this file, so the code owners of infra/ see it in the pull
# request. The agent never adds inline skip comments (CLAUDE.md).
framework:
  - terraform
compact: true
quiet: true
skip-check:
  # CKV_AWS_144 cross-region replication: exports are regional by design. Owner platform. Review 2027-04.
  - CKV_AWS_144
  # CKV2_AWS_62 S3 event notifications: nothing consumes them yet. Owner platform. Review 2027-04.
  - CKV2_AWS_62
  # CKV_AWS_18 and CKV_GCP_62 access logging of the access-log bucket itself: circular; the logs
  # buckets are private, encrypted and versioned. Owner cloud-security. Review 2027-04.
  - CKV_AWS_18
  - CKV_GCP_62
  # CKV2_AZURE_33 private endpoint: waiting on the hub network (ticket NET-212). Owner cloud-security. Review 2027-01.
  - CKV2_AZURE_33
  # CKV2_AZURE_1 customer-managed key: Key Vault for this subscription lands in Q1 (ticket SEC-88). Owner cloud-security. Review 2027-01.
  - CKV2_AZURE_1

Before the exceptions and the second pass, the first run in the video reported 9 passed and 22 failed checks for the drafts and 44 passed and 16 failed for the first fix; the transcripts for both are in the repository beside the ladder's.

The agent's loop

The ladder runs after every edit, and apply never runs at all

After every edit

A PostToolUse hook on Edit|Write reads the file path from stdin and, for a .tf file, climbs rungs 1 to 4 for its module. A failure exits 2, which blocks and feeds the output back to the agent as the thing to fix next. The agent iterates against the same validators CI will run.

Claude Code hooks guide

Before every command

The PreToolUse guard refuses tofu apply, terraform apply, force pushes and destructive commands. CLAUDE.md says why; the hook makes it true whatever the model decides.

In the pull request

The workflow climbs the ladder per module in a matrix, uploads Checkov's SARIF to the Security tab, and has no cloud credentials at all. Plan and apply are separate jobs on main, through OIDC and a protected environment with a human approver.

Claude Code GitHub Actions

.claude/hooks/tf_after_edit.sh

.claude/hooks/tf_after_edit.sh
#!/bin/bash
# PostToolUse for Edit|Write on *.tf: climb rungs 1 to 4 of the ladder for the module that changed
# and feed the result back to Claude. Exit 2 makes it a blocking error the agent must fix.
FILE=$(jq -r '.tool_input.file_path // empty')
case "$FILE" in *.tf|*.tftest.hcl) ;; *) exit 0 ;; esac
MOD=$(dirname "$FILE"); [ -d "$MOD/tests" ] || true
OUT=$(LADDER_SKIP_TEST=1 infra/scripts/ladder.sh "$MOD" 2>&1)
if [ $? -ne 0 ]; then echo "$OUT" | tail -40 >&2; exit 2; fi
exit 0

.github/workflows/iac.yml

.github/workflows/iac.yml
# Every pull request that touches infra/ climbs the ladder for each module, with no cloud
# credentials. The plan and apply jobs run on main through OIDC and a protected environment,
# never from a pull request and never from an agent's shell.
name: Infrastructure
on:
  pull_request:
    paths: ["infra/**"]
permissions:
  contents: read
jobs:
  ladder:
    name: ${{ matrix.module }}
    runs-on: ubuntu-latest
    timeout-minutes: 15
    strategy:
      fail-fast: false
      matrix:
        module: [infra/fixed/aws, infra/fixed/azure, infra/fixed/gcp]
    steps:
      - uses: actions/checkout@v6
      - uses: opentofu/setup-opentofu@v1
      - uses: terraform-linters/setup-tflint@v4
      - uses: actions/setup-python@v6
        with: { python-version: "3.12" }
      - run: pip install checkov
      - run: |
          curl -fsSL https://github.com/open-policy-agent/conftest/releases/download/v0.71.1/conftest_0.71.1_Linux_x86_64.tar.gz | tar xz conftest
          sudo mv conftest /usr/local/bin/
      - run: tflint --init --config=infra/.tflint.hcl
        env: { GITHUB_TOKEN: "${{ github.token }}" }
      - run: infra/scripts/ladder.sh ${{ matrix.module }}
      - run: checkov -d ${{ matrix.module }} --framework terraform -o sarif --output-file-path results --soft-fail
        if: always()
      - uses: github/codeql-action/upload-sarif@v4
        if: always()
        with: { sarif_file: results/results_sarif.sarif }
infra/scripts/ladder.sh
infra/scripts/ladder.sh
#!/usr/bin/env bash
# The validation ladder for one Terraform module, no credentials needed:
#   1 format   2 lint (tflint)   3 scan (checkov)   4 policy (conftest)   5 terraform test (mock providers)
# Usage: scripts/ladder.sh fixed/aws        exit 0 only when every rung passes.
# Rung 5 needs the provider binaries (it downloads them); set LADDER_SKIP_TEST=1 to stop after 4.
set -uo pipefail
MOD=${1:?module directory}; TF=${TF:-tofu}; status=0
HERE=$(cd "$(dirname "$0")/.." && pwd)   # infra/, wherever the script is called from
step() { printf '\n== %s\n' "$1"; }

step "1 format: $TF fmt -check"
$TF fmt -check -recursive "$MOD" || status=1

step "2 lint: tflint"
tflint --chdir="$MOD" --config="$HERE/.tflint.hcl" || status=1

step "3 scan: checkov"
checkov -d "$MOD" --framework terraform --quiet --compact --config-file "$HERE/.checkov.yaml" || status=1

step "4 policy: conftest"
conftest test --parser hcl2 -p "$HERE/policy" "$MOD"/*.tf || status=1

if [ "${LADDER_SKIP_TEST:-0}" != "1" ] && ls "$MOD"/tests/*.tftest.hcl >/dev/null 2>&1; then
  step "5 test: $TF test (mock providers)"
  (cd "$MOD" && $TF init -backend=false -input=false >/dev/null && $TF test) || status=1
fi

printf '\n== ladder: %s\n' "$([ $status -eq 0 ] && echo passed || echo failed)"
exit $status

What stays human

The decisions the ladder surfaces and cannot make

Data decisions

  • Replication across regions, and what it costs
  • Retention: 30 days of soft delete, 90 days of old versions, a year of logs
  • Who may read the exports, and from which network

Key decisions

  • Customer-managed keys per cloud, and who holds them
  • Rotation periods, and protection of the keys from deletion

Operating decisions

  • Drift: a scheduled plan that opens an issue when the world and the code disagree
  • Exceptions: each with an owner and a date, reviewed when it expires
  • Destroy: prevent_destroy on anything that holds data, and a person on the console for the rest

Watch

The ladder on the three drafts, in a minute and a half

Terraform for AWS, Azure and GCP: validate before you plan 1:16

An agent writes a storage module for three clouds. Before anything reaches a plan, four validators run without credentials: fmt, tflint, Checkov and a Conftest policy the team owns. Real run on the draft and on the fix. All the videos

Chapters and transcript

Sources

Read on these pages, 2026-10-25

Every number on this page is read by the site's build from the transcripts in data/testlab/transcripts/ladder-*.txt and conftest-verify.txt, recorded on 2026-10-25.