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
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
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
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
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
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)
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.
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
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'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"
}
}
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.
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.
#!/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
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.