Would you keep every environment's infrastructure code in one repository or give each environment its own repository, and how does that choice affect who can approve production changes?
answer
- the real question is the approval boundary
- one repo keeps promotion a diff
- split repos, drifting environments
- path ownership plus scoped credentials is cheaper
- the credential grants privilege, not the repository
basics
~20 sUsually one repository, because promotion across repositories degrades into copying and the environments drift. Separate repositories buy a hard permission boundary, but the same boundary is cheaper to get from path-based ownership rules plus per-environment credentials — and the credentials, not the repository, are what actually gate production.
solid answer
~50 sI default to one repository holding all environments, with shared components published as versioned artifacts from their own repository. One repository keeps promotion as a small reviewed diff — bump the pin, see the change against the previous environment — and lets anyone diff prod against staging in one place, which is how drift gets noticed. The objection is always access: not everyone who touches dev should be able to change production. But repository boundaries are a coarse way to buy that. Path-based ownership rules with stricter required reviewers on the production paths give the same gate at a fraction of the operational cost, and per-environment credentials are what actually enforce it — a repository split with one shared admin credential buys nothing real. I would split repositories only when a compliance or contractual boundary demands separate access control lists, and I would expect to pay for it in drift.
go deeper
Know that infrastructure code for all environments commonly lives in one repository, with separate folders per environment, and that production changes usually need review from a specific team before they can merge.
Be able to compare the two layouts on concrete grounds — promotion effort, visibility of differences between environments, and duplicated tooling — rather than on a general sense that separation is safer.
Make the enforcement argument: repository permissions gate proposals, credentials gate what an apply can do, and a split without scoped credentials is theatre. Describe path-based ownership plus per-environment credentials as the cheaper equivalent.
Own the decision and its cost curve. Say when you would split — restricted read access, a contractual boundary, an estate that no longer fits one repository — and what you would put in place to stop the split from producing three divergent estates.
## Framing the question correctly The question sounds like repository layout, but the thing being decided is **where the approval and privilege boundary sits**. Repository split is one implementation of that boundary; there are cheaper ones. A candidate who answers only in terms of folders is answering a smaller question than the one asked. ## The case for one repository **Promotion stays a diff.** With every environment in one place, promoting a change is a one-line pin bump reviewed against the environment that already runs it. Across repositories, promotion means copying content between histories, which is re-implementation by another name, and re-implementation is where environments diverge. **Drift is visible.** Anyone can diff the production configuration against staging in one command. This sounds minor and is not: teams with split repositories routinely cannot answer "how does prod differ from staging?" without a manual audit. **One review culture, one set of tooling.** Formatting, linting, policy checks and pre-commit hooks are configured once. In N repositories they are configured N times and are stale in at least one of them. **Atomic cross-cutting change.** Renaming a shared convention or adding a required tag everywhere is one reviewable change, not a coordinated set of pull requests that half-lands. ## The case for repository-per-environment **A hard access boundary.** Repository permissions are a coarse, well-understood, auditable control. If a regulator or a customer contract requires that a named group of people cannot even propose changes to production, a separate repository with a separate access list is easy to demonstrate. **Blast radius of tooling.** A bad shared workflow, hook or lint rule affects everything in the repository at once. Splitting limits that. **Scale.** At very large estates a single repository accumulates history, ownership ambiguity and slow tooling. This is a real problem — and it is usually solved by splitting along *service or team* lines, not along environment lines, because that is where ownership actually differs. ## The costs of splitting, honestly Three environments means three sets of tooling, three review configurations and three histories that answer the same question differently. The shared components must become versioned external artifacts anyway — which is a good practice regardless — so the split buys nothing there. And every cross-environment operation, from "apply this fix everywhere" to "show me the difference", becomes manual. The predictable end state is that dev's repository is well maintained and production's is the one nobody dares refactor. ## The cheaper way to get the same boundary Most of what teams want from a repository split is available inside one repository: - **Path-based ownership rules**, so changes touching the production paths require review from a named group and cannot merge without it. - **Branch protection on the default branch**, so nothing reaches production paths without that review. - **Distinct credentials per environment**, scoped so the production credential exists only in the production pipeline context and is unusable elsewhere. - **Separate accounts or subscriptions**, so even a stolen credential is bounded. The crucial point: **the repository does not grant privilege — the credential does.** A team that splits repositories but keeps one powerful shared credential available to every pipeline has built a boundary that is documentation, not enforcement. Conversely, a single repository with strict path ownership and a production credential nobody can reach outside the protected path is genuinely locked down. When you argue this in an interview, argue it from where the privilege actually lives. ## The layout I would actually propose ``` components repo shared components, published as immutable versions infrastructure environments/dev, environments/staging, environments/prod path ownership: prod requires platform-team review credentials: one per environment, per account ``` Two repositories, not four: one for the reusable library where versioning discipline lives, one for the environment compositions where promotion is a visible diff. Beyond that, split by team or service when a single repository stops fitting the organisation — never merely to express that production is important. ## Where this becomes a genuine judgement call Separate repositories start to win when the people allowed to *see* production configuration are a strict subset of everyone else — a real situation in some regulated or multi-tenant contexts, since a configuration file reveals topology, naming and sometimes hostnames. Access control on reading, not on approving, is the argument that survives scrutiny. If reading is not restricted, prefer one repository and spend the saved effort on ownership rules and credential scoping.
- What is the strongest argument that survives for a separate production repository?Restricting who may *read* it. Configuration reveals topology, naming and sometimes hostnames, and in regulated or multi-tenant settings the audience for that is deliberately narrow. Restricting who may approve is achievable with path ownership inside one repository; restricting who may read is not, so that is the case where the split earns its cost.
- If a team splits repositories per environment but every pipeline uses the same powerful credential, what have they achieved?Documentation, not enforcement. The repository boundary shapes where code lives; the credential decides what an apply can actually do. With one shared credential, a run started from any repository can change production. Scope credentials per environment and per account first — that boundary holds even when someone runs the tool from a laptop.
- How would you keep environments from drifting if you are forced into repository-per-environment?Make the environment repositories as thin as possible: nothing but pins and values, with all substance in versioned shared components. Add an automated comparison that reports pin and value differences between environments on a schedule, and enforce a maximum version lag. The thinner those repositories are, the less there is to diverge.
saying these in an interview costs you the question
- Separate repositories are safer because production is more important.
- Repository permissions stop anyone from changing production infrastructure.
- Promotion means copying files from the staging repo to the prod repo.
- A monorepo means everyone can change everything, with no way to gate.
- Split repositories per environment first, worry about drift later.