DFdom@fradley
← ~/writing
$ cat clickops-to-code.md

From ClickOps to code, without the big-bang rewrite

The estate was built in the portal, and the plan for fixing it has been "we'll do it properly on the next project" for three years. The next project keeps landing in the same estate.

It stays that way because people assume the fix is a rewrite. "Move to infrastructure as code" sounds like a rewrite: freeze delivery, rebuild everything as Terraform, and hope the new estate behaves like the old one when traffic swings across. Priced like that it never gets approved, and it shouldn't be.

You don't have to rebuild anything. Terraform can take over resources that already exist, in place, with no downtime and no change to the running infrastructure. The resource stays where it is; what changes is who may change it and how.

Adoption, not migration

Since Terraform 1.5, adoption is a reviewable operation. Declare what you're taking over in an import block:

import {
  to = azurerm_storage_account.logs
  id = "/subscriptions/<sub-id>/resourceGroups/rg-ops/providers/Microsoft.Storage/storageAccounts/stlogsprod"
}

Then ask Terraform to draft the matching configuration:

terraform plan -generate-config-out=generated.tf

The acceptance test is the plan output. When it says 1 to import, 0 to add, 0 to change, 0 to destroy, the code is a faithful description of what's running and nothing has been touched. Changes to that resource now go through a pull request instead of a click. There is no cutover, because Terraform adopts the estate in place.

The order of attack

Adopting a whole estate at once carries the same risks as the rewrite, so sequence it.

  1. Stop digging. From this week, new resources are born as code. It costs almost nothing and caps the size of the problem.
  2. Adopt the platform layer. Networking, DNS zones, policy assignments and shared identity are few in number and rarely change, but a hand edit to one hits the whole estate. That makes them the best return on your first import blocks.
  3. Adopt what changes most often. Bring the resource groups with the busiest change history under management next. Each adopted resource turns its future changes from unreviewed clicks into reviewed pull requests, and a resource nobody has touched since 2023 can wait.

Leave out anything scheduled for decommission, vendor-managed appliances you're contractually not allowed to touch, and resources another team owns (adopting those turns a governance improvement into a turf war). Park them and note why.

The first fortnight

In week one, pick a real but calm resource group with a handful of resources. Import it, generate the config, tidy the generated HCL into something a colleague would read, and get to the zero-diff plan.

In week two, make one real change to that resource group through code, reviewed and applied from a pipeline rather than a laptop. That change shipping with a review trail is the demo that wins over sceptics.

After that, take a resource group or two per sprint, platform layer first, with delivery never pausing.

The import block and the zero-diff walkthrough are in the blog-examples repo.

More useful tidbits coming, one a week.

discuss on linkedin → more writing