I hard-coded a cloud region into everything, and it cost us a day
This week I had to move our deployments from one cloud region to another. It should have been a trivial change. Instead it touched a few dozen files, forced a teardown and rebuild of an environment, burned a globally unique resource name for the next three months, and required editing a formal requirement document. None of that was the cloud provider’s fault. It was mine, and it was written in months ago.
What went wrong
When I first set up our deployment tree, I knew which region we’d run in, so I wrote it down. The problem is where I wrote it down, and how many times.
The region ended up in five separate layers, each restating the same fact:
- The design document. The architecture page literally said “both deployments live in region X” and listed resource group names with the region baked in.
- A numbered requirement. I wrote a MUST-level requirement stating that production and staging exist in a specific region. That requirement was enforced by a documentation gate, so changing it meant a formal review.
- The naming scheme. Our naming table embedded the region into the suffixes of several resource kinds: resource groups, node pool groups, DNS zones, monitoring rules. A separate infrastructure module held its own copy of the region as a variable, and a bootstrap script parsed that variable out of the module with
sed. - The Kubernetes overlays. Manifests referred to resource groups by their full, region-bearing names, and so did comments.
- The tests. Dozens of table tests asserted literal resource names with the region spelled out, by hand, dozens of times. Fixtures carried the region as expected command-line arguments. An example config in one of the services referenced a database host that, it turns out, never existed under any version of the naming table. It had just drifted.
Then our first staging stand-up failed because the subscription didn’t have availability-zone access in that region, and our cluster and database are declared zone-redundant. Correct response: pick a region that has zones and move on. Actual response: a day of edits across 36 files.
Why this was a real mistake, not just untidiness
The region isn’t a property of the system. Nothing a user, operator, or other component observes depends on it. The hostnames, the protocol, the isolation between environments, the shape of the stack: all identical in any region that offers the services we use. It’s an operational choice, and operational choices are hostage to things outside your control: quotas, zone availability, capacity, pricing, what your subscription tier allows. By writing it as a design-level MUST, I turned a provisioning limitation into a design change.
Repetition multiplied the cost. One fact in one place is a one-line change. The same fact in a design page, a requirement, a JSON table, an infra variable, a shell script parsing that variable, overlays and dozens of tests is a day of work, a large review, and a real risk of missing a copy. Which I did, at least once, as the stale example config proves.
Baking it into names made it permanent. Resource group names are fixed at creation. Our vault’s name is globally unique and, with purge protection enabled, is reserved for 90 days after deletion. So a “region move” became a “rename,” and a rename became a teardown plus a brand new vault name. If the names had been region-free, the move would have been a new resource group in the new region under the same names, and the soft-deleted vault could have been recovered into it. Instead, the old vault name is dead until January.
Tests that assert derived literals don’t test anything. We already had one test proving that the naming script derives each name correctly from the naming table. Every other test that typed out a full resource name by hand was just re-asserting that derivation with a copy that could drift. Those tests weren’t protecting behavior; they were hard-coding the naming table a second time, and every one of them had to change for something the table alone should have absorbed.
What I should have done
-
Keep operational choices out of the design. The design page should say that two deployments exist, what they’re for, and that they share nothing. Where they run belongs in the deployment tree’s README next to the other operational decisions, stated once, changeable without a requirement edit.
-
One value, one place, derived everywhere. The region should be a single field in the naming table that the infra module and the naming script both read. Any name where the provider forces a region into the format (there are a couple of those) gets it by substitution, never by typing. The move is then the change of one string.
-
Region-free names by default. Resources should be named by project, environment and kind. The cloud provider already records where a resource lives; the name doesn’t need to say so. The only exceptions are the provider’s own conventions, and those should be derived.
-
Tests ask for names; they don’t spell them. A test that needs the staging resource group should call the naming script and ask for it, or derive a fixture from the table once at the top. Exactly one test holds literal expectations about naming, and only that test changes when the table does.
-
Examples derive from the same source of truth. An example configuration that shows a realistic hostname should be generated from, or checked against, the naming table, so it can never reference something that doesn’t exist.
The rule I’m taking away: a design document states what must be true for the system to be the system. If a fact could change without any user or component noticing, it’s not design, it’s implementation, and it goes in one place.
What’s fixed and what isn’t
The naming table now has a single region field, the region-bearing affixes are gone except where the provider requires them (and those are substituted), the infra module and the naming script both read from the table, and the bootstrap script stopped parsing another file with sed. The requirement and the design page no longer mention a region. The vault got a new suffix because the old name is locked in soft-delete. Staging has been torn down and rebuilt in the new region.
What I did not finish: the tests still spell out literal names. I updated them so they’re correct, but I didn’t rewrite them to ask the naming script. That’s follow-up work, and I want to be honest that this change made them right, not better. Until that’s done, the next region move will still be bigger than one line.
I’d like to say the lesson is “don’t hard-code things,” but I knew that already. The real lesson is that I didn’t stop to ask whether the thing I was writing down was a fact about the system or a fact about today’s circumstances. Those deserve very different homes.