liveBook · Manning

Composite design pattern

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

A structural design pattern that treats individual components and compositions uniformly, allowing hierarchical assembly of grouped components.

The composite design pattern treats an infrastructure module as one instance while assembling, grouping, and ranking modules into a hierarchy. It supports composable, reproducible, and evolvable infrastructure configurations. section 3.2

Apply the pattern by:

  • Combining dependent resources, such as a network and its subnet, inside one module. section 3.2
  • Nesting modules to organize larger infrastructure systems and reproduce groups of related resources. section 3.2
  • Combining composite modules with factory, prototype, singleton, and builder patterns according to purpose, reuse, update frequency, and resource composition. section 3.6

Network and subnet module

Define the network configuration, define the dependent subnet configuration, and place both in one module. Reusing that module reproduces the network system across environments. section 3.2

Figure 3.4 A network module can use the composite pattern to group the network and subnetwork resources.

Use the network diagram to see how the composite pattern groups network and subnetwork resources. section 3.2

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

How deep it goes
Explains module composition through a network-and-subnet example and connects it to broader pattern selection.
Examples
Uses reporting hierarchies, a network with subnet, and nested infrastructure modules as concrete examples.
What you can do after
Build composable infrastructure modules and combine them into larger automated configurations.
How it connects
Connects infrastructure modules with factory, prototype, singleton, and builder patterns.

Also explained in

Compare how 4 books explain composite design pattern →

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.