liveBook · Manning

Dependency inversion

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

A software design principle stating that high-level components should depend on abstractions rather than low-level implementation details.

Dependency inversion expresses dependencies between high-level and low-level infrastructure resources through abstractions. The abstraction translates required attributes and buffers high-level modules from low-level changes. section 4.2.2

Use three abstraction forms when passing infrastructure metadata:

  • Interpolate resource attributes within a module or configuration. section 4.2.2
  • Expose module outputs between modules. section 4.2.2
  • Retrieve values through infrastructure state or an infrastructure API. section 4.2.2

Protecting a server from network changes

If a network changes its output from a name to an ID, a server module that consumes the raw output can break. An API, stored configuration, module output, or attribute interpolation provides a stable translation layer instead. Python examples show a subnet obtaining the network name from a network object. section 4.2.2

Figure 4.4 Dependency inversion returns an abstraction of the low-level resource metadata to the resource that depends on it.

Diagram the abstraction boundary that returns low-level resource metadata to its dependent resource. section 4.2.2

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

How deep it goes
Defines the principle, compares three abstraction forms, and demonstrates attribute interpolation, while deferring full implementations of other forms.
Examples
Uses network, subnet, and server modules, with Python attribute interpolation and module or state-based metadata access.
What it assumes
Assumes familiarity with high-level and low-level resources, while teaching how abstractions decouple their dependencies.
What you can do after
Apply it by inserting abstractions between infrastructure resources and selecting attributes, outputs, or state for metadata exchange.
How it connects
Connects dependency inversion with inversion of control, dependency injection, facade, adapter, and mediator patterns.

Also explained in

Compare how 6 books explain dependency inversion →

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.