What it means
Infrastructure as code describes networks, servers, roles, buckets, and clusters in text files that a tool applies to a cloud account. The files live in version control, so every change has an author, a reviewer, and a history.
Before it changes anything, the tool produces a plan: the resources it would create, change, or delete. That plan is the useful part for security. A policy check can read it and refuse a risky setting before the setting exists, which makes it a preventive control. The code only describes what goes through the pipeline, though. A change made by hand in the console is drift, and a resource created outside the code never appears in a plan. Only a check on the live account finds those.
See the idea / Cloud
Infrastructure as code lets a check refuse a change before it exists.
Follow one pull request from Git to a failed policy check, then see the one change the pipeline never saw.
Kael writes templates for Meridian's ground-telemetry account: the cluster, the node role, and the halcyon-downlink bucket. The templates live in Git. Terraform reads them and writes a plan, the list of changes it would make. A policy check reads each plan. Its rules forbid a privileged pod and a role with a wildcard action. A scheduled job plans against the live account every 15 minutes to find drift, a change made outside the code.
01 / 04
Commit
At 09:40 Kael commits his first templates, which import the live resources from the files already in Git. Two hand fixes from earlier in the week are missing.
More about this step
The node role and the uplink-status pod had both been fixed by hand, in the live account. The files in Git still held the old settings: a wildcard storage action and a privileged pod.
Step through at your own pace.
Keep in mindOne account and one tool. The check reads only what goes through the pipeline, and drift detection covers only resources the code manages. Runtime behavior and the data in the bucket are not checked. Terraform state can hold secrets in plain text, which is not shown.
Read the visual, step by step
- Commit. At 09:40 Kael commits his first templates, which import the live resources from the files already in Git. Two hand fixes from earlier in the week are missing. The node role and the uplink-status pod had both been fixed by hand, in the live account. The files in Git still held the old settings: a wildcard storage action and a privileged pod.
- Plan. At 09:42 the plan shows what applying would do. It would put back the wildcard action and the privileged pod. Terraform compares the templates with the live account and lists each difference. The plan is exported as JSON with terraform show -json, so a policy engine can read it.
- Check. At 09:43 the policy check fails the plan twice. The pipeline stops, and the live account keeps its fixes. One failure is the wildcard action in the node role's policy. The other is the privileged pod. Kael copies the hand fixes into the templates, and the corrected plan passes.
- Drift. At 16:10 Dax changes a load balancer setting in the console. No plan or check sees it, until the scheduled plan reports drift at 16:25. The corrected templates were applied at 11:12, so the account matched its code until 16:10. The change was sound, but it went around the pipeline. Until it is copied into the templates, the next apply would put the old setting back. Drift detection is the detective half that a plan check cannot be.
One account and one tool. The check reads only what goes through the pipeline, and drift detection covers only resources the code manages. Runtime behavior and the data in the bucket are not checked. Terraform state can hold secrets in plain text, which is not shown.
Flow references: HashiCorp Terraform: terraform plan command · Open Policy Agent documentation: Terraform · NIST SP 800-204D (February 2024)
AN ILLUSTRATIVE SCENARIO
A plan that would have undone two fixes
Kael wrote templates for Meridian's ground-telemetry cluster from the files already in Git, with import blocks for the live resources. Those files still held a wildcard storage policy and a privileged pod that had been fixed by hand. The plan would have put both back. A policy check failed the plan twice, nothing was applied, and Kael copied the hand fixes into the templates before merging.
Put it to work
- Keep templates in version control and require review before any plan is applied.
- Run a policy check on every plan, so that a failing rule stops the pipeline before apply.
- Schedule a drift check against the live account, and keep a posture tool running for resources the code does not manage.
How to check your work
Open a pull request that adds a known-bad setting and confirm the pipeline fails it. Change a managed setting in the console and confirm the drift check reports it.
Connect the ideas
- CSPM
Checks of cloud configuration against policy, such as public storage or open security groups.
- Provenance
The recorded origin, collection method, transformations, and completeness limits of a piece of evidence.
- Control
A process, configuration, or technology meant to reduce a named risk or detect a named failure.