The question this answers
Which properties of production must my lower environments reproduce, and which ones must they deliberately not?
A change that passes in staging must be very likely to work in production, and a mistake in development must not be able to touch a production resource, read a production customer record, or generate a production-sized bill.
Separate blast radii with a shared shape: the same topology and deployment path across environments, on different scales, in different accounts, with different data and different permissions.
Parity is selective, and the selection is the whole skill
The instinct that staging should be identical to production comes from a real observation — most staging failures are things staging did not have. But "identical" is the wrong correction, because it is unaffordable and, for data, illegal in a growing number of jurisdictions. The right question is narrower: *which differences can invalidate a test?*
Topology can. If production routes through a load balancer into a private subnet and staging runs one instance with a public address, staging has never tested the security group, the health check, the readiness path or the failover. Deployment path can: if production is deployed by the pipeline and staging is deployed by hand, the pipeline is untested. Configuration mechanism can: if staging reads secrets from environment variables and production from a secret manager, the secret-manager path first runs in production. IAM *shape* can: if the staging workload has an administrative role, every permission error appears for the first time in production, which is the single most common "worked in staging" failure there is.
Size cannot, mostly. Two instances instead of twenty tests the same code path. One zone instead of three tests the same wiring — you lose the failover test, which you should run deliberately in production with a controlled injection anyway. Data volume can matter for query plans, which is a real exception worth naming: a query that is fine on ten thousand rows and fatal on fifty million is a class of bug staging structurally cannot find, and the answer is production-shaped index review, not a full-size copy.
| Property | Must match production? | Reason |
|---|---|---|
| Topology and network path | Yes | The security group, health check and private-subnet routing are only exercised if they exist. |
| Deployment mechanism | Yes | A pipeline that only ever runs against production is an untested pipeline. |
| IAM shape (roles, scoping style) | Yes | An admin role in staging defers every permission error to production. |
| Configuration and secret source | Yes | The secret-manager path must run somewhere before it runs in production. |
| Runtime, image, provider versions | Yes | This is the parity that catches the boring, expensive failures. |
| Instance count and size | No | Two instances test the same code path as twenty. Scale is a load-test question, not a parity question. |
| Multi-zone / multi-region redundancy | No | Expensive, and failover is better verified by deliberate injection than by standing capacity. |
| Real customer data | No — never | It is a privacy incident waiting for a debug session. Use masked or generated data. |
| Data *volume* and distribution | Partly | Query plans depend on it. Approximate the shape; do not copy the rows. |
| Human access | No — inverted | Broad in development, tightly restricted in production. This is the one axis that should differ deliberately. |
Isolation is an account boundary, not a tag
Separating environments by naming convention inside one account fails in the way you would expect: an IAM policy written with a wildcard, a script with the wrong variable exported, a module whose default environment is prod. The boundary that actually holds is the one the provider enforces — a separate account, subscription or project per environment, with no trust relationship from the lower ones to the higher one.
That boundary also gives you the things you would otherwise build: a hard cost boundary you can put a budget alarm on, a separate quota pool so a load test in staging cannot exhaust production capacity, a clean audit surface, and the ability to give a developer broad rights in development without that meaning anything in production.
The same configuration should build all of them. One set of modules, one set of variable files, one pipeline, differing by inputs — which is what makes the parity claims above verifiable rather than aspirational. If development is built from a different configuration than production, you do not have three environments; you have three systems that resemble each other.
The bill is where environment design shows up
Non-production environments are where cost quietly accumulates, because nothing about them creates pressure to be small. They are created easily, used intermittently, and nobody is paged when they are idle. A per-developer environment that mirrors production is a multiplier on every line item, applied to resources that are busy for perhaps two hours a day.
The controls that work are structural rather than behavioural. Environment-aware defaults in the modules, so smaller is what happens by default. A scheduled destroy for development environments, which is only possible because they are code. Ephemeral per-pull-request environments that live for the life of the branch instead of permanent per-developer ones. And a budget alarm per account, which is the whole reason the account boundary was worth having.
The one place to spend deliberately is staging's data tier, because that is where the parity that matters — schema, indexes, query plans, migration behaviour — actually lives. A staging database with production-shaped indexes on masked data is worth more than four extra application instances.
Bars are relative weights, not currency. Real rates depend on provider, region, commitment and volume.
Key points
- Match topology, deployment path, IAM shape, configuration mechanism and versions. Those are what make a staging test meaningful.
- Do not match size, redundancy, human access or real data. Full-scale parity is a bill, not a guarantee.
- Data volume is the honest exception: query plans depend on it, so approximate the shape without copying the rows.
- Isolate with a provider account boundary, not a naming convention — it gives you cost, quota, audit and permission separation at once.
- Build every environment from the same configuration with different inputs, or the parity claims are unverifiable.
The loop, answered
Every field is required, which is why no lesson here can recommend something without saying what it costs and what simpler thing to consider first.
- • One set of modules; per-environment variable files supply size class, replica bounds, redundancy and retention.
- • Each environment is a separate provider account with its own state, so a mistake cannot cross the boundary even with a wrong variable.
- • The pipeline assumes a per-environment role; lower environments have no trust path to production credentials.
- • Promotion moves an artifact, not a configuration — the same image digest is deployed to each environment in turn. See Build Once, Promote the Same Bytes.
- • Data is generated or masked at the boundary; production data never flows downward unmasked.
- • You own the variable files, and the discipline that a value differing between environments is a deliberate decision with a reason.
- • You own the data-masking pipeline and its correctness, which is a real engineering commitment and the part most teams underestimate.
- • You own the lifecycle of ephemeral environments: creation on branch, destruction on merge, and cleanup for the ones that leak.
- • You own per-account budget alarms and quota requests, since separate accounts mean separate quota pools.
- • You own the environment-specific defaults inside modules, which is where the cost control actually lives.
- • A permission error that appears for the first time in production, because the staging workload had an administrative role.
- • A migration that is fast on ten thousand staging rows and locks a table for eleven minutes on fifty million production rows.
- • A configuration value hardcoded rather than parameterised, so production silently inherits a development endpoint — or the reverse, which is worse.
- • Production customer data copied into staging for a debugging session, where fifteen engineers have read access. This is a privacy incident, not a shortcut.
- • A lower environment with a trust path into production — a shared role, a peered network, a shared secret store — which turns the weakest environment into the way in.
- • Environment sprawl: eleven long-lived environments, four of which nobody can name an owner for.
- • Environment count scales with teams, and the cost scales with it linearly unless the environments are ephemeral.
- • What runs out first is usually a provider quota in the non-production account, because that is where people experiment.
- • Configuration complexity grows with per-environment special cases; each one is a place where staging stops predicting production.
- • Separate accounts mean a compromise in development does not grant anything in production — provided no trust relationship crosses the boundary.
- • Human access should be inverted between environments: broad in development, break-glass in production. This is the intended asymmetry, not a parity failure.
- • Real customer data in a lower environment is a data-classification violation with a wider access list than production. Mask or generate, always.
- • The staging workload's IAM policy should be scoped like production's even though the resources are less valuable, because the *shape* of the policy is what you are testing.
- • Idle non-production compute is typically the largest avoidable line item, and a scheduled destroy removes most of it.
- • Duplicated redundancy in lower environments is pure waste — reliability is a production property, verified by injection.
- • Spend deliberately on staging's data tier: schema and query-plan parity catches the failures that cost real money.
- • Per-account budget alarms are the only cost control that fires before the invoice, which is the main practical argument for the account boundary.
- • Configuration diff between environments: the list of values that differ should be short, and every entry should have a reason.
- • Per-account spend and its trend, with an alarm rather than a monthly review.
- • Environment age and last-deploy time — a long-lived environment nobody has deployed to in six weeks is a candidate for deletion.
- • Whether staging actually receives every release before production. A skipped staging deploy under deadline pressure is the failure that precedes the incident.
- • The signal that lies: "it worked in staging". It is only evidence about the properties staging actually reproduces, which is exactly what the parity table above enumerates.
- • Two environments — production and one pre-production. For a small team a third is often ceremony, and two well-maintained environments beat three neglected ones.
- • Ephemeral per-pull-request environments instead of permanent per-developer ones: created on branch, destroyed on merge, costing hours instead of months.
- • Testing in production with feature flags and canaries, for the classes of behaviour no lower environment can reproduce — real traffic, real data volume, real concurrency. See Deployment Is Not Release and Canary: Let 5% of Traffic Find the Bug.
- • For a genuinely small system, local development plus production with a strong canary. Not fashionable, occasionally correct, and honest about what staging was really testing.
- • Buys a meaningful pre-production signal; costs a second full topology to maintain and pay for.
- • Account isolation buys a hard boundary; costs cross-account plumbing, more roles, and per-account quota management.
- • Masked data buys privacy safety; costs a masking pipeline that must be maintained and whose bugs are silent.
- • Ephemeral environments buy a much lower bill; cost pipeline work and a slower first deploy on every branch.
What people believe, and what is true
Staging should be an exact copy of production.
It should be an exact copy of the properties that make a test meaningful, and a deliberately smaller, safer version of everything else. An exact copy doubles the bill and puts real customer data where more people can read it.
Tags are enough to separate environments.
A wildcard in a policy or a wrong exported variable crosses a tag boundary without noticing. Only a provider-enforced account boundary holds.
If it passed staging it will work in production.
It is evidence about what staging reproduces. Data volume, real concurrency, real traffic patterns and production IAM scope are usually not on that list unless you put them there.
Apply it
Check yourself
Answer out loud or on paper first, then compare. These come from the interview questions linked to this lesson.
What is infrastructure drift, how does it happen, and what does the next apply do about it?
Show a strong answerHide the answer
Drift is divergence between declared and actual state, and the causes are mostly organizational rather than technical: an emergency console change at 3am, a script run out of band, another tool managing an overlapping resource, or a provider-side default that changed under you.
What the next apply does depends on the direction. If the code is authoritative and the manual change is not represented, the apply reverts it — which is exactly right when someone widened a security group to 0.0.0.0/0 to unblock themselves, and exactly wrong when someone bumped the instance size to survive a load spike. The reconciliation is not aware of intent.
The dangerous variant is a change that cannot be reverted in place. Reverting an attribute that forces replacement means destroy-and-create — a new database, a new IP, a new volume — and that discovery belongs in a reviewed plan, not in an apply someone ran quickly.
The detection mechanism is a scheduled
planin CI against production, alerting when it is non-empty. Drift found within a day is a conversation; drift found in six months is an archaeology project where nobody remembers whether the difference is deliberate.The fix for a legitimate drift is to codify it: put the change in the configuration, plan, review, apply, and confirm the plan is clean. The fix for an illegitimate drift is to let the apply revert it and then find out why the console was reachable.
Full interview question, with follow-ups and red flags →What is Terraform state, why does it exist, and what happens when a team treats it carelessly?
Show a strong answerHide the answer
State is the mapping from configuration addresses to real resource identifiers, plus a cached copy of their last-known attributes. Without it, Terraform has no way to know that
aws_instance.webis instancei-0abc; it can only see your desired configuration, not what it previously created.That is why losing state is not a small problem: the next plan sees no existing resources and proposes to create everything again — duplicate infrastructure alongside the live one that is now unmanaged, and in the worst case a name or address collision that fails halfway through, leaving a half-built environment.
It must be remote and locked. Local state means two engineers apply against different pictures of reality and the second silently clobbers the first's record. A remote backend with state locking makes concurrent applies wait instead of interleave, which is the difference between a queue and a corruption.
It must be treated as sensitive. State stores resource attributes verbatim, and that includes values that came from or feed secrets — connection strings, generated passwords, keys. State goes in an encrypted, access-controlled, versioned store, never in the application repository.
And it must be versioned, because the recovery path for a bad apply or a corrupted state is restoring the previous version. Versioning on the state bucket costs nothing and is the thing you will need on your worst day.
Full interview question, with follow-ups and red flags →During an incident someone scaled the database to a larger instance in the console. Next apply?
Show a strong answerHide the answer
It will propose scaling back to the declared size, which for many engines is a restart or a failover. Codify the new size first — update the variable, plan, review, apply — so reconciliation confirms reality instead of undoing the fix at the worst moment.
Full interview question, with follow-ups and red flags →