Infrastructure as code means your servers, networks, databases and permissions are described in text files, and a tool builds and changes the environment from those files. Nobody clicks through a console to set things up. For a small team it is worth it for anything new and for anything you would have to rebuild in a hurry. It is usually not worth stopping other work to convert a stable environment that nobody changes.
How it works
The files say what should exist: this network, this database at this size, these firewall rules, these people with access. They are kept in source control beside the application’s code. A tool reads them, compares them with what is running, and makes the changes needed for the two to match.
Microsoft’s description of infrastructure as code puts it this way: the same model generates the same environment every time it is deployed, and to make a change the team edits the source and not the target.
Most tools also show what they are about to change before they change it. That preview is what a second person reviews.
The tools you are likely to meet
- Bicep is Microsoft’s language for deploying Azure resources. Microsoft’s overview says it is free, that Microsoft supports it, that a what-if operation previews changes, and that Azure keeps track of the state so there are no state files to manage.
- CloudFormation is the AWS equivalent. You write a template that describes the AWS resources you want, and the service provisions them and manages them as one unit.
- Terraform, from HashiCorp, works across cloud providers and on-premises systems. It records what it has built in a state file, and it produces a plan that someone approves before anything changes. The state file has to be stored where the team can reach it and nobody else can.
If you run on one cloud, that cloud’s own tool is the simplest place to start.
What a small team gets from it
- The environment is written down. On a small team the environment often lives in one person’s memory. The files are a description that stays current, because they are what built it. How do you reduce key-person risk on a small IT team? covers the rest of that problem.
- A rebuild is a known procedure. If an environment is deleted, damaged or encrypted, you run the files and restore the data. Without them, someone rebuilds from memory while the business waits.
- Changes are reviewed and recorded. Source control shows who changed what, when and why, which is the record an auditor asks for.
An example: the test environment that has drifted
Take a test environment that was built by hand. It began as a copy of production. Since then production has had a larger database, a firewall rule added during an incident and a setting changed to fix a slow report. None of that reached the test environment. A release passes there and fails in production.
Built from the same files, the two cannot differ in ways nobody chose. The firewall rule added during the incident is a line in a file, and it reaches the test environment on the next deployment.
What it costs
- Time to learn. Someone has to learn the tool, and the team has to change a habit.
- Discipline about the console. Once the files are the source, a change made by hand does not match them. The next deployment may undo it or fail. The working rule is that the console is for looking, and an emergency change made there is written back into the files the next day.
- Care with secrets. Passwords and keys do not belong in the files. They go in the secret store your cloud provides, and the files refer to them.
- Slower work on what already exists. Writing files for a new environment is quick. Bringing an existing one under the files means importing each resource and checking that the tool would not change it.
When it is worth it and when it is not
It is worth it for a new application or a new environment, for the environment you land in during a migration, for anything built more than once, and for anything the business could not be without for a week.
It is not worth it for a server that is stable and due to be retired, or for an environment that changes once a year and has a written rebuild page and a tested backup.
Our recommendation is to write every new environment as code from the first day, and to convert an old one only when it is being changed anyway.
Common questions
Is infrastructure as code only for the cloud? No, but the cloud is where it pays most, because everything there can be created through an interface a tool can call. Some tools also manage on-premises systems.
Do we need a DevOps engineer to do this? No. To start, you need one person who learns the tool and a second who reviews each change. Begin with one new environment and the tool your cloud provider publishes.
Should we convert the environment we already have? Convert the parts you would have to rebuild in a hurry, and do it when you are changing them anyway. Leave alone what is stable and close to retirement. For those, a written page on how to rebuild and a tested backup are enough.
Our MSP manages the environment. Does this still apply? Yes. Ask where the definition of the environment is kept and whether you would receive it if the relationship ended. If it exists as code, ask for it to be kept in a repository your company owns.
If your environment was built by hand and nobody is sure what is in it, a System Evaluation is the fixed-fee first step: an independent look at the environments, the backups and how a change reaches your users, with a prioritized plan.