liveBook · Manning

Dependency

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

A requirement that one infrastructure resource be created, configured, or available in relation to another resource.

A dependency is a relationship in which one component requires another component’s existence or attributes before it can build, change, or operate. In infrastructure, a server may depend on a network, while an application may depend on a service account and database proxy. section 4.0 section 11.2.2

Manage dependencies as explicit, changeable relationships:

  • Pass identifiers and attributes as variables or injected module inputs instead of hardcoding them; this loosens coupling and supports replacement. section 2.3.5 section 10.2.3
  • Map expected dependencies before changing or deleting a resource, then verify that actual dependencies match the configuration. section 11.2.2 section 12.2.1
  • Test dependency boundaries with contract tests, then use integration and end-to-end tests when modules or environments communicate. section 6.7.1 section 6.7.2
  • Change low-level dependencies first, test dependent resources afterward, and isolate replacements when using immutable blue-green changes. section 9.2.1

Tracing an indirect database dependency

A server appears not to need database credentials because the application connects to localhost. Tracing the runtime path reveals a database proxy using the server’s service account, which therefore requires database permissions. The dependency is indirect in application configuration but operationally essential. section 11.2.2

Listing 2.1 Parametrize the network as a variable
import json
 
 
def hello_server(name, network):                                       #1
   return {
       'resource': [
           {
               'google_compute_instance': [                            #2
                   {
                       name: [
                           {
                               'allow_stopping_for_update': True,
                               'zone': 'us-central1-a',
                               'boot_disk': [
                                   {
                                       'initialize_params': [
                                           {
                                               'image': 'ubuntu-1804-lts'
                                           }
                                       ]
                                   }
                               ],
                               'machine_type': 'f1-micro',
                               'name': name,
                               'network_interface': [
                                   {
                                       'network': network              #3
                                   }
                               ],
                               'labels': {
                                   'name': name,
                                   'purpose': 'manning-infrastructure-as-code'
                               }
                           }
                       ]
                   }
               ]
           }
       ]
   }
 
 
if __name__ == "__main__":
   config = hello_server(name='hello-world', network='default')        #4
 
   with open('main.tf.json', 'w') as outfile:                          #5
       json.dump(config, outfile, sort_keys=True, indent=4)            #5

Inspect a Python-generated Terraform configuration that accepts the network as an argument rather than embedding the dependency in the server resource. section 2.3.5

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

How deep it goes
Explains definitions, parameterization, injection, testing, refactoring, deployment sequencing, and diagnosis, but stops short of formal dependency algorithms.
Examples
Uses network-server provisioning, service-account authentication, module contracts, blue-green networks, monolith refactoring, and unused-resource deletion.
What it assumes
Assumes familiarity with infrastructure resources and modules while teaching dependency definitions, loose coupling, injection, and verification through operational scenarios.
What you can do after
Diagnose with dependency graphs, parameterize infrastructure inputs, test module contracts, sequence changes, and remove resources more safely.
How it connects
Connects dependencies with infrastructure as code, modules, variables, dependency injection, testing, blue-green deployment, and configuration drift.

Also explained in

Compare how 27 books explain dependency →

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.