liveBook · Manning

Dependency

As explained in Terraform in Depth: Infrastructure as Code with Terraform and OpenTofu

A dependency is a prerequisite relationship requiring one infrastructure action or object to exist before another can proceed.

A dependency is a prerequisite relationship: one infrastructure action or object must exist before another can proceed. Terraform uses these relationships to determine the order in which it launches and modifies managed resources. section 5.2

Terraform represents dependencies with a directed acyclic graph. Resources form nodes, while directed connections express relationships between them. Attribute and parameter references create these links, and Terraform state acts as a snapshot of the graph. Because the graph is acyclic, a circular dependency causes Terraform to fail rather than choose an order. section 5.2 section 5.1.1

Dependencies also organize repeatable command workflows:

  • Make allows one target to require other targets before it runs, so a grouping target can invoke several tasks together. section 7.2.2
  • A target such as chores can depend on format and document, causing formatting and documentation commands to run through one entry point. section 7.2.2
  • Keep dependency relationships acyclic; circular relationships prevent Terraform from producing a valid execution order. section 5.2

Grouping formatting and documentation

A Makefile can define `chores: format document`, then define `format` to run `terraform fmt` and `document` to run `terraform-docs`. Running `make chores` uses the declared dependencies to invoke both tasks from one command. section 7.2.2

Listing 7.3 makefile syntax
.PHONY: target                            #1
target:                                   #2
    command                               #3

Use the compact Makefile listing to inspect the syntax of a target and its command before adding dependency targets. section 7.2.2

How Terraform in Depth: Infrastructure as Code with Terraform and OpenTofu covers it

How deep it goes
Defines directed acyclic dependencies, explains attribute links and cycle failures, and demonstrates target prerequisites without detailing graph algorithms.
Examples
Uses Terraform resource relationships and a Makefile whose chores target depends on format and document.
What it assumes
Assumes basic Terraform resources and commands, while defining graph direction, edges, cycles, and acyclicity.
What you can do after
Diagnose Terraform cycle failures and configure Make targets that run prerequisite commands in a repeatable order.
How it connects
Connects dependency with resource graphs, directed acyclic graphs, Terraform state, resource attributes, Make targets, and continuous integration.

Also explained in

Compare how 27 books explain dependency →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Terraform in Depth: Infrastructure as Code with Terraform and OpenTofu. The section links point to the parts of the book it draws on.