0

Using terraform to build out a set of azure vms; cannot for the life of me figure out this error. I've wandered into a maze of twisty passages all alike ...

This code produces the following error. Doesn't look wrong, but is.

resource "azurerm_virtual_network" "TW-PROD-AZR-NETDB-network" {
  name = "TW-PROD-AZR-NETDB-Network"
  address_space = ["10.240.0.0/16"]
  location = "${var.location}"
  resource_group_name = "${azurerm_resource_group.TW-PROD-AZR-NETDB.name}"

resource "azurerm_subnet" "TW-PROD-AZR-NETDB-subnet1-private" {
  name = "TW-PROD-AZR-NETDB-subnet1-private"
  resource_group_name = "${azurerm_resource_group.TW-PROD-AZR-NETDB.name}"
  virutal_network_name = "${azurerm_virtual_network.TW-PROD-AZR-NETDB-network.name}"
  address_prefix = "10.240.1.0/24"
}

# Create VNIC DB01
resource "azurerm_network_interface" "TW-PROD-AZR-DB01-NIC01" {
  name = "TW-PROD-AZR-DB01-NIC01"
  location = "${var.location}"
  resource_group_name = "TW-PROD-AZR-NETD"
  network_security_group_id = "${azurerm_network_security_group.TW-PROD-AZRDB-SG.id}"

  ip_configuration {
    name = "TW-PROD-AZR-DB01-NIC01-CONFIG"
    subnet_id = "${azurerm_subnet.TW-PROD-AZR-NETDB-subnet1-private.id}"
    private_ip_address_allocation = "dynamic"
    public_ip_address_id = "TW-PROD-AZR-DB01-IP"
  }

  tags {
    Env = "Production"
    Group = "NETDB"
  }
}
  • resource 'azurerm_network_interface.TW-PROD-AZR-DB01-NIC01' config: unknown resource 'azurerm_subnet.TW-PROD-AZR-NETDB-subnet1-private' referenced in variable azurerm_subnet.TW-PROD-AZR-NETDB-subnet1-private.id 

1

There are two mistakes in your tf file.

1.resource azurerm_virtual_network lost } at the end.

2.In resource azurerm_subnet, virutal_network_name is wrong, it should be virtual_network_name.

The following tf file works for me. Note: For test easily, I delete NSG and public IP.

resource "azurerm_virtual_network" "TW-PROD-AZR-NETDB-network" {
  name = "TW-PROD-AZR-NETDB-Network"
  address_space = ["10.240.0.0/16"]
  location = "West US"
  resource_group_name = "TW-PROD-AZR-NETD"
}
resource "azurerm_subnet" "TW-PROD-AZR-NETDB-subnet1-private" {
  name = "TW-PROD-AZR-NETDB-subnet1-private"
  resource_group_name = "TW-PROD-AZR-NETD"
  virtual_network_name = "${azurerm_virtual_network.TW-PROD-AZR-NETDB-network.name}"
  address_prefix = "10.240.1.0/24"
}

# Create VNIC DB01
resource "azurerm_network_interface" "TW-PROD-AZR-DB01-NIC01" {
  name = "TW-PROD-AZR-DB01-NIC01"
  location = "West US"
  resource_group_name = "TW-PROD-AZR-NETD"


  ip_configuration {
    name = "TW-PROD-AZR-DB01-NIC01-CONFIG"
    subnet_id = "${azurerm_subnet.TW-PROD-AZR-NETDB-subnet1-private.id}"
    private_ip_address_allocation = "dynamic"

  }

  tags {
    Env = "Production"
    Group = "TW-PROD-AZR-NETD"
  }
}

If you use Compare tool, you will see the difference clear.

enter image description here

  • 1
    @BrianDunbar For similar issue, you could use Compare tool to check difference. – Shui shengbao Oct 30 '17 at 2:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.