Built-in Dependency Management

Learn how built-in dependencies are managed in Terraform.

Resource graph

When Terraform is analyzing a configuration, it creates a resource graph that lists out all the resources in the configuration and their dependencies. This allows Terraform to create the physical resources in the proper order, and when possible, create resources in parallel if they aren’t interdependent. Let’s consider an example configuration where we’ve defined the following resources:

  • Virtual network
  • Virtual machine
  • Virtual NIC
  • Database as a service
  • DNS record

Dependencies and resource creation order

The virtual NIC attaches to the virtual network. One argument in the configuration block of the virtual NIC references the virtual network, and thus Terraform knows that the virtual NIC is dependent on the virtual network. Following the same logic, the virtual machine (VM in the image below) references the virtual NIC. The DNS record references the public IP address of the virtual machine, creating a new dependency. Terraform evaluates this and determines that it must create resources in this order:

Get hands-on with 1400+ tech skills courses.