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 preceding chapter, I covered the fundamental practices for infrastructure as code. 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 show how to apply design patterns to IaC 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. IaC has reusable objects (as infrastructure resources). However, its opinionated behaviors and DSLs 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

Summary