The elephant in the console
Reading about infrastructure as code from scratch is easy. Reality is different: an environment with hundreds of resources created over years, by hand, by people who are no longer around. Rewriting it all at once is unworkable; leaving it out means the most critical part will never get the benefits of code.
Bring in, do not rebuild
Most tools allow existing resources to be imported: you write the code describing a resource that already exists and tell the tool 'this one here is that one there'. Without destroying or recreating anything.
The work is organised in waves:
- Inventory first. Know what actually exists, as in before fixing, know what is there.
- Start with the highest risk and the least change: network, identities and access. Mistakes there are serious and these resources change rarely, so the code stays stable.
- Carry on with the data: databases and storage, taking great care not to trigger recreations.
- Finish with compute, which changes most and is the easiest to replace with new versions created from code in the first place.
The golden rule of importing
After importing a resource, the plan has to come out empty. If the plan proposes changes, the code does not faithfully describe what exists and applying it would modify something that works. You adjust the code until the plan has nothing to do, and only then is it considered brought in.
What stays out
Not everything deserves to come in. Resources about to be retired, or unused experiments, are documented as exceptions and deleted rather than imported. The goal is not 100%, but that what matters is in code and the rest is identified.
With the infrastructure in code, the natural next step is for daily operations to stop depending on somebody remembering the steps too.
How we apply it: Automation and IaC.