Infrastructure as Code Needs Code Reviews
Once infrastructure is code, a small diff decides about security, cost and the risk of outages – that is why it belongs in the same review process as application code.
Infrastructure as Code Needs Code Reviews
If you wave a wildcard permission through, you have granted it. The merge is the moment of decision, not the audit a year later in which the same line gets marked red. And this moment looks harmless: a few changed lines, a green build, a thumbs-up.
The trigger is the AWS CDK, which became stable this summer. With it, I no longer describe cloud infrastructure in a thousand lines of YAML but in TypeScript – with types, functions and abstractions. That is noticeably more productive, and that is exactly the catch.
Because a change to the infrastructure now looks like any other pull request. But what is in this inconspicuous diff is not a Feature Flag. It is an IAM policy, a security group or the memory allocation of a function that is billed per invocation. The friction of making changes has dropped – the risk per change has not. This widening gap is the real topic.
What Infrastructure as Code really changes#
Before, infrastructure lived in click sessions in the console and in the heads of two or three people. Nobody could review a change, because there was no diff. Whoever opened a rule in a security group left no traceable trail. Outages turned into archaeological digs: Who changed what and when, and why?
Infrastructure as Code turns this around. Every change becomes a commit, every commit is versioned, every version can be checked. The real gain is not the nicer syntax. It is that infrastructure is finally subject to the same control mechanisms as the rest of the system. Rollback becomes a git revert, traceability becomes a git blame, knowledge becomes a readable repository instead of a conversation at the bar.
The catch: review discipline did not automatically grow along with this shift. We have been reviewing application code for years with a clear eye for side effects, edge cases and security. With infrastructure code, many teams read the same diff with half their attention, because it looks short and the build is green. With IaC, though, a green build only means that synthesis ran through – not that the resulting infrastructure is secure, affordable and can be rolled back.
The diff I really have to review#
CDK works with constructs: building blocks that encapsulate one or more CloudFormation resources along with sensible defaults. That is the strength and the trap at the same time. A high-level construct can create a dozen resources from three lines of TypeScript – a function, a log group, an execution role, a few permissions. The TypeScript diff shows me the intent. It does not show what actually gets provisioned.
The real review artifact is therefore the cdk diff, not the code alone: the comparison of the current and planned CloudFormation state. Only there does it become visible that an inconspicuous line creates a role with a wildcard permission or opens a security group.
const handler = new lambda.Function(this, "ApiHandler", {
runtime: lambda.Runtime.NODEJS_10_X,
handler: "index.handler",
code: lambda.Code.fromAsset("dist/api")
});
These four lines are deliberately small. But they create more than a function: a log group, an execution role with basic permissions and the links between them. The review question is not “does the handler run?” but “which permissions does this role get, how long do the logs stay around, and what does an invocation cost?” A good construct reduces repetition and encapsulates good defaults – but it must not hide which resources, permissions and costs arise. That is exactly the boundary I check in the review.
The most expensive line is often a permission#
The classic mistake is the convenient permission. It works right away if I give a function broad access, and nobody notices in the demo that the boundary is drawn too wide.
// convenient, and wrong
bucket.grantReadWrite(handler);
table.grant(handler, "dynamodb:*");
That runs. It is also the kind of line that gets marked red in a security audit a year later. Least privilege is not a chore for later. The decision about it is made in the review, at the moment of the merge – after that, the role is in operation, and “I will tighten it later” rarely turns into anything. That is why I ask concretely in the review: Does this function really need write permissions, or only read? Does it need the whole table or one action? Every wildcard is a claim that needs evidence.
The pattern repeats with public buckets, open security groups and shared secrets. None of these mistakes is technically difficult. All of them are cheap to prevent if someone reads the diff with the right question – and expensive if nobody does.
Cost belongs in the review#
With serverless infrastructure, the bill is a direct result of lines of code. A function’s memory size, provisioned concurrency, a NAT gateway, an instance type chosen too large, a retention setting that keeps logs forever – all of these are one-line changes with an ongoing monthly consequence.
I have seen a single changed line double a team’s cloud bill because a default was adopted without thinking. The diff was inconspicuous, the build green, the review a formality. Cost transparency in the review does not mean predicting every bill. It means asking the question at all: What does this line change about the running costs – one-time, per invocation or per month? Serverless shifts operational work; it does not remove it. Permissions, logs, cold starts, timeouts, cost and the ability to roll back still have to be designed explicitly.
What I look for in an infrastructure review#
Across the individual examples, I always check the same boundaries. Is the permission as narrow as possible, or does the diff open more than the task needs? How big is the blast radius if this resource is misconfigured – does it hit one service or the entire account? Is the change idempotent and reversible, or does a second deployment create a different state than the first? What happens on a failed deployment – is there a clean way back, or does someone have to repair things by hand at night? And does operations produce enough signals – logs, metrics, alarms – to explain an error later at all?
These questions seem dry. But they are the difference between a system that looks clean in the demo and one that holds up under repetition, partial failures, old data and wrong permissions. The happy path is never the problem. Infrastructure gets interesting exactly where something goes wrong.
The trade-off of abstraction#
CDK offers constructs on several levels: thin wrappers around individual CloudFormation resources, convenient building blocks with good defaults and entire patterns made of several resources. The higher the level, the less code I write – and the more decisions I delegate to defaults I do not see.
That is not an argument against abstraction. It is an argument for choosing the level of abstraction deliberately and making it visible in the review. A high-level construct is a good trade if its defaults match my requirements for security and cost. It is a bad trade if I have never checked its defaults and get to know them by surprise in production. The methodical consequence is simple: the cdk diff belongs in every pull request, so that the level at which I delegate does not stay implicit.
Where the review belongs in the pipeline#
flowchart LR Source --> Synth Synth --> Diff["cdk diff"] Diff --> Review["Review<br/>Permissions · Cost · Rollback"] Review --> Deploy Deploy --> Observe
The diff is not a formality at the end. It is the place where the review takes hold: before the deployment, as a visible artifact in the pull request. This moves the error from operations into the review phase – and that is the whole point. A configuration error that stands out in the diff costs ten minutes of discussion. The same error in production costs an incident, a night shift and trust.
What the machine checks, what the human checks#
A good review process does not waste human attention on things a rule can handle. Much of an infrastructure review is mechanical and can be automated: open security groups, unencrypted buckets, wildcard policies, missing log retention. Static analysis of the synthesized CloudFormation template – for example with cfn_nag – catches this class of errors in the pipeline before a human even looks at it.
Because the infrastructure is now code, I can also pin down assumptions as tests. CDK allows assertions against the synthesized template: “this role must not contain a wildcard action,” “this bucket is not public.” Such a test fails as soon as someone loosens the boundary – not only in the audit a year later. It is the same reflex I know from application code: what was right once and has to stay right becomes a test, not a mnemonic.
Automation does not take the work away from the human review; it focuses it. When the machine enforces the same rules every time, the human can concentrate on what no rule can decide: Is this level of abstraction the right one? Is the blast radius acceptable? Does the cost consequence fit the task? These questions are exactly why the review exists at all.
The mistake of taking the tool for the solution#
A tool does not create good architecture; it can only express it. CDK is not a security concept. CloudFormation is not a permission model. Serverless is not an operations strategy. These tools make it easier to draw good boundaries – they do not draw them by themselves. If you believe that switching to Infrastructure as Code settles the security and cost question, you have only changed the medium in which the same decisions are now made faster and less visibly.
That is exactly why Infrastructure as Code needs the review more, not less. The low friction that makes the whole approach so attractive is at the same time its biggest risk. Changing has become cheap – understanding has to stay.
What it gives the team#
The benefit is measurable, even if it shows up as an absence. Errors that used to appear as incidents now show up as comments in a pull request. The cloud bill stays predictable, because cost changes are named instead of discovered. Onboarding gets shorter, because new people read the infrastructure instead of guessing. And lead time even drops: there is not less checking; there is less to repair.
A review costs minutes. An open bucket, a wildcard role or a doubled NAT gateway costs days and, in the worst case, customer data. Infrastructure as Code has finally brought infrastructure into a format in which this trade pays off. It would be a shame to skip the review as the only step that turns a diff into a decision.
Further reading#
- AWS CDK Developer Guide: https://docs.aws.amazon.com/cdk/latest/guide/home.html
- AWS CDK Constructs: https://docs.aws.amazon.com/cdk/latest/guide/constructs.html
The sources help you double-check platform behavior and defaults. But the actual decision is not in the docs. It is in the concrete diff – and it depends on someone reading it before it goes live.
Revised and translated from German with the help of AI.