Most organisations need to run multiple copies of infrastructure, whether it’s multiple environments for testing a system, or separate instances of an application for different customers. This pattern catalogue describes the concept of an infrastructure stack as a collection of infrastructure defined and provisioned as a unit - a Terraform project, CloudFormation stack, etc. There are different ways to replicate infrastructure in relation to these stacks. Some of these ways are useful, which are described here as patterns. Other ways are best avoided, which are described as antipatterns.
With the template stack pattern, a stack source code project is implemented so that it can be used to create multiple instances of the stack in a consistent way.
The singleton stack antipattern is a naive implementation, where each stack instance is defined and managed by its own separate copy of the stack source code. This is useful for very simple use cases, particularly when learning something, but it isn’t a suitable approach for important infrastructure.
Note that the wrapper stack pattern is essentially implemented like a singleton stack. However, this isn’t considered to be an antipattern because each instance project contains only configuration parameters, not infrastructure definition code.
A Many-Headed Stack defines multiple copies of infrastructure in a single stack project. For example, if there are three environments for testing and running an application, a single Terraform project (and single statefile) includes the code for all three of the environments.