By Morgan Lucas (she/her)

I was doing a walkthrough of this project before realizing...I forgot what this line did;

network_interface_ids = ["${element(azurerm_network_interface.CA-NetInt.*.id, 01)}"] 

My theory is that it ties into the depends_on segment. Here is the relevant part of the resource.

resource "azurerm_virtual_machine" "CloudAvailServ" {
  name                  = "WS201901"
  location              = var.location
  resource_group_name   = var.resourceGroupName
  network_interface_ids = ["${element(azurerm_network_interface.CA-NetInt.*.id, 01)}"] 
  depends_on            = [azurerm_network_interface.CA-NetInt] #placeholder for when a network interface is made 
  vm_size               = "Standard_B1s"

The depends_on is there because the Virtual Machine will look for an aspect that does not exist at the time of it’s creation. That is essentially a placeholder, as the machine is made before the id.

I asked the Terraform Users Group on LinkedIn and was told depends_on was possibly not necessary. In hindsight, it’s true - the network_interface_ids is calling to the same faux-variable. It will be placed there as it’s created.

So I commented out depends_on and applied it - While it did work, it didn’t destroy as easily:

Error waiting for update of Network Interface "Net-Connection" (Resource Group "Home"): Code="OperationNotAllowConnection" ed" Message="Operation 'startTenantUpdate' is not allowed on"Operation ' VM 'WS201901' since the VM is marked for deletion.

While it said the VM was marked for deletion, it didn’t delete until I ran terraform destroy a second time.

My Guess: Terraform destroyed what it could so I didn’t have to wait, and destroyed the rest when I ran it again. Minor, but if it means less redundant code, ok.