chapter three

3 Patterns for infrastructure modules

 

This chapter covers

  • Grouping infrastructure resources into composable modules based on function
  • Building infrastructure modules with software development design patterns
  • Applying module patterns to common infrastructure use cases

In the last chapter, I covered the fundamental practices for infrastructure as code (IaC). Even though I knew the fundamental practices, my first Python automation script grouped code into one file with messy functions. Years later, I learned software design patterns. They provided a standard set of patterns that made it easier for me to change the script and hand it over to another teammate for maintenance.

In the following two chapters, I will show how to apply design patterns to infrastructure as code configuration and dependencies. Software design patterns help you identify common problems and build reusable, object-oriented solutions.

Definition

A design pattern is a repeatable solution to a common problem in software.

Applying software design patterns to IaC has its pitfalls. Infrastructure as code has reusable objects (as infrastructure resources). However, its opinionated behaviors and domain-specific languages do not map directly to software design patterns.

3.1 Singleton

3.2 Composite

3.3 Factory

3.4 Prototype

3.5 Builder

3.6 Choosing a Pattern

3.7 Exercises and Solutions

3.8 Summary