Infrastructure as Context
Infrastructure as Code has been around for years. We’ve adopted it for reproducibility, consistency, version control and automation, and none of that has changed.
But I think AI coding agents give us one more reason to care about it, and it’s a reason nobody had in mind when Terraform was designed: context.
An agent working in a repository can read all of the application code. The trouble is that a lot of what decides whether its change will work isn’t in that code at all. Which queue does this service consume from? Can it even reach the database from that subnet? What’s the timeout on the load balancer?
A person picks these things up over time, by asking colleagues and by living through a few incidents. An agent starts from zero in every session, and it only knows what it can read.
If those answers only exist in a cloud console, in some wiki page or in a colleague’s head, the agent is guessing. And agents are very good at guessing confidently.
What an agent can read
Once the infrastructure is written down as code, an agent can explore it the same way it explores everything else in the repo. It can grep for a resource, follow a reference into another module, look at the git history. It doesn’t need access to the cloud account for any of that.
You could put all of this into documentation instead. But then the agent has to figure out whatever structure you invented, and you have to keep it up to date. Terraform is a format the models already know well.
It also goes stale much more slowly. The files that describe the system are the same files that create it, which keeps them a lot closer to reality than a diagram usually is.
Here’s the kind of situation I have in mind. An export endpoint fails with a 504 whenever it takes more than a minute to start responding. The application timeout is set to 120 seconds, so nothing in the application code explains it. The load balancer definition does:
resource "aws_lb" "api" {
name = "api"
load_balancer_type = "application"
idle_timeout = 60
subnets = var.public_subnet_ids
}
The load balancer gives up on a connection after 60 seconds without data. The application would happily keep working for another minute, but nobody is listening anymore.
An agent that can read this file has a much better chance of finding the cause before it starts touching application code. Without the file, I’d expect it to do what a lot of us have done at some point: raise the timeout in the application again, see the same 504, and go looking for the problem in the wrong place.
The obvious alternative is to give the agent read-only access to the cloud account. I don’t think that’s a bad idea, and the live state is useful. But it answers a different question. The live state shows what exists right now. It doesn’t say what was supposed to exist, and it rarely says why. That part is in the code and in git, at least when somebody bothered to write a proper commit message.
Reading files is also just simpler. There are no credentials to hand out and no integration to set up and trust.
IaC doesn’t show everything, though. Some resources are managed outside of it, some are created at runtime, and drift happens. So I wouldn’t treat it as proof of what’s running. I’d treat it as the best description of what we meant to run.
There’s one more benefit, and it shows up when the agent starts changing things. An infrastructure change made through IaC is a diff. If the pipeline also runs a plan on the pull request, somebody can see exactly what would change before anything is applied. I’m a lot more comfortable with that than with an agent clicking around in a console.
A new reason to adopt IaC
If you already have your infrastructure in code, the first thing I’d do is boring: write down why. Nobody can tell from the code why a timeout is 60 seconds, and that’s usually the part that matters. The second is importing whatever somebody once created by hand, because an agent can’t reason about what isn’t in the files. And keep all of it somewhere the agent actually looks, ideally in the same repo.
And if you don’t have it yet, I think this is a good reason to start. I believe that how easily an agent can understand a system is becoming as important as the quality of the code itself.
We built IaC so machines could provision our systems. Now it helps them understand those systems too.