Terraform – Dependenices

In our last couple of posts on Building Infrastructure and modify we created a resource group within Azure and then modified the tags. Having a single resource group is not going to add value to any organization, we need to create infrastructure within the resource group. In an upcoming post, we will create a virtual machine (VM) but before a VM is created some exiting infrastructure needs to be in place.

Below the minimum set of resources that need to in place before a VM can be created:

  • Resource group
  • Virtual network
  • Subnet
  • Network security group
  • Network interface

Let’s start with adding a Virtual network to our code

# Create a virtual network
resource "azurerm_virtual_network" "virtual_network" {
    name                = "Vnet"
    address_space       = "10.0.0.0/16"
    location            = "eastus"
    resource_group_name = azurerm_resource_group.rsg.name
}

To create the virtual network (VNet) it is dependant on a resource group. We need to specify the resource group that it will be associated with. The value resource_group_name uses an expression azurerm_resource_group.rsg.name, this gives the name of the resource group that is referenced by azurerm_resource_group resource with the name rsg. In general, the syntax of an expression is type.name.attribute.

Leave a Reply