DEV Community

Shakirat (Lawal) Koiki
Shakirat (Lawal) Koiki

Posted on

Implicit dependencies

In Terraform, implicit dependencies are relationships between resources that are not explicitly defined in the configuration but are inferred based on the configuration. In Azure, there are several implicit dependencies between resources that Terraform automatically handles for you. Here are some examples:

Virtual Networks and Subnets: When you create a subnet, it must be associated with a virtual network. Therefore, when you define a subnet resource in Terraform, it implicitly depends on the virtual network resource that it is associated with.

resource "azurerm_virtual_network" "mct_vnet" {
  name                = "mct-vnet"
  address_space       = ["10.0.0.0/16"]
  location            = "westus2"
  resource_group_name = "mct-rg"
}

resource "azurerm_subnet" "mct_subnet" {
  name           = "example-subnet"
  address_prefix = "10.0.1.0/24"
  virtual_network_name = azurerm_virtual_network.mct_vnet.name
  resource_group_name  = "mct-rg"
}

Enter fullscreen mode Exit fullscreen mode

Top comments (0)