The mediator pattern organizes dependencies among infrastructure resources and creates or deletes objects in dependency order. It acts as the authority for coordinating resources such as networks, servers, and firewall rules. section 4.5
Apply the mediator by making dependency order explicit:
- Create the network before a server. section 4.5
- Create the network and server before a firewall rule. section 4.5
- Use dependency injection to abstract and control resource relationships. section 4.5
- Repeat operations idempotently so existing resources converge on the same target state. section 4.5
Python resource mediator
A Python mediator checks the requested resource type, recursively creates its low-level dependencies, and then creates the requested object. A load balancer can extend the sequence after the server or firewall. section 4.5
Use the workflow diagram to inspect how the mediator becomes the authority on which infrastructure resource is configured first. section 4.5
Choose a mediator when many dependencies connect multiple modules or resources. It improves scalability and change isolation, but requires substantial implementation, testing, and troubleshooting effort; an untested mediator can create incorrect infrastructure. section 4.6

