liveBook · Manning

Single repository structure

As explained in Infrastructure as Code, Patterns and Practices: With examples in Python and Terraform

A repository organization pattern in which all infrastructure configurations and modules are stored together in one code repository.

When teams need shared infrastructure modules, environment configurations, and a common place to inspect changes, a single repository keeps those pieces together. It suits smaller estates with tens of modules and a few environments, while exposing the whole infrastructure layout to every team. section 5.1.1 section 5.1.3

A single repository structure, also called a monorepo, stores all infrastructure-as-code configuration and modules for a team or function in one code repository. A common layout separates modules from environments, then separates development and production configurations within each team or environment. section 5.1.1

Apply the pattern with a deliberately visible structure:

  • Create a top-level modules directory for reusable server, network, database, tagging, or tool-specific components. section 5.1.1
  • Create environments directories for teams or deployment stages, separating development and production configurations. section 5.1.1
  • Reference local modules by path, allowing configurations to compose infrastructure without publishing every module separately. section 5.1.1
  • Compare environment files in one place to identify differences, while accepting that cost and resource constraints can justify some variation. section 5.1.3
  • Add versioning, specialized build systems, and governance before unrestricted module changes or recursive CI checks become disruptive. section 5.1.3 section 5.5

Local modules for production infrastructure

A production configuration adds the modules directory to Python's path, imports database, server, and network factory modules, constructs them with a shared name and environment, and combines their outputs into one resource configuration. The same repository can organize team environments under environments and provider-specific implementations under modules. section 5.1.1

Figure 5.2 The Leafy Greens team’s production and development environments use the directories containing server, network, and database factory modules in a single repository structure.

Use the repository diagram to see how development and production environments consume server, network, and database factory modules. section 5.1.1

The pattern preserves composability, evolvability, and reproducibility, but shared visibility also increases blast radius: an ungoverned module change can break dependent configurations, and CI may struggle to process every directory. When scale or access-control needs exceed the build system, split modules or domains into multiple repositories and version released artifacts. section 5.1.3 section 5.5

How Infrastructure as Code, Patterns and Practices: With examples in Python and Terraform covers it

How deep it goes
Defines the layout, demonstrates local imports, and explains trade-offs, but defers detailed build-system implementation and governance mechanics.
Examples
Uses team-based development and production directories, local Python imports, and composed server, network, and database factory modules.
What it assumes
Assumes familiarity with infrastructure as code, configuration, modules, environments, and basic repository or CI concepts.
What you can do after
Operate/configure a monorepo layout, reference local modules, compare environments, and recognize when scaling requires repository decomposition.
How it connects
Connects infrastructure as code with modules, environment configuration, CI systems, versioning, artifact repositories, and multiple repository structures.

Also explained in

Compare how 2 books explain single repository structure →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Infrastructure as Code, Patterns and Practices: With examples in Python and Terraform. The section links point to the parts of the book it draws on.