Deploying a 3 Nic VM in Aure with Terraform

I am trying to use terraform to deploy a 3 NIC VM in Azure that will be used by an F5. I am using the following: I am receiving the following error:
Virtual Machine Name: “vm_f5npncus_vm02.corp.local”): performing CreateOrUpdate: unexpected status 400 (400 Bad Request) with error: VirtualMachineMustHaveOneNetworkInterfaceAsPrimary: Virtual machine vm_f5npncus_vm02.corp.local must have one network interface set as the primary.

Snippet:

Network Interfaces

resource “azurerm_network_interface” “nic_f5npncus_vm02_mgmt” {
name = “nic-f5npncus-vm02-mgmt”
location = azurerm_resource_group.richard_playground.location
resource_group_name = azurerm_resource_group.richard_playground.name

ip_configuration {
primary = true
name = “ipconfig1”
subnet_id = azurerm_subnet.snet_edge_ncus_f5_mgmt.id
private_ip_address_allocation = “Static”
private_ip_address = “172.20.12.37”
}
}

resource “azurerm_network_interface” “nic_f5npncus_vm02_external” {
name = “nic-f5npncus-vm02-external”
location = azurerm_resource_group.richard_playground.location
resource_group_name = azurerm_resource_group.richard_playground.name

ip_configuration {
primary = false
name = “ipconfig1”
subnet_id = azurerm_subnet.snet_edge_ncus_f5_external.id
private_ip_address_allocation = “Static”
private_ip_address = “172.20.14.37”
}
}

resource “azurerm_network_interface” “nic_f5npncus_vm02_internal” {
name = “nic-f5npncus-vm02-internal”
location = azurerm_resource_group.richard_playground.location
resource_group_name = azurerm_resource_group.richard_playground.name

ip_configuration {
primary = false
name = “ipconfig1”
subnet_id = azurerm_subnet.snet_edge_ncus_f5_internal.id
private_ip_address_allocation = “Static”
private_ip_address = “172.20.100.37”
}
}

Virtual Machine

resource “azurerm_virtual_machine” “vm_f5npncus_vm02” {
name = “vm_f5npncus_vm02.corp.local”
location = azurerm_resource_group.richard_playground.location
resource_group_name = azurerm_resource_group.richard_playground.name
network_interface_ids = [
azurerm_network_interface.nic_f5npncus_vm02_mgmt.id, # Primary NIC
azurerm_network_interface.nic_f5npncus_vm02_external.id,
azurerm_network_interface.nic_f5npncus_vm02_internal.id
]

@rcorey1996

I believe that the azurerm_virtual_machine resource requires that you specify the primary_network_interface_id argument since you are providing a list more than length 1 for the network_interface_ids argument.

primary_network_interface_id - (Optional) The ID of the Network Interface (which must be attached to the Virtual Machine) which should be the Primary Network Interface for this Virtual Machine.

I’ve not had this issue with the subsequent azurerm_windows_virtual_machine or azurerm_linux_virtual_machine resources that superseded the resource you’re currently using. In fact it seems like that is what you’re trying to accomplish given your comment in the resource on the first line of network_interface_ids.

I think either specifying the primary_network_interface_id argument or swapping over to one of the newer resources might help. Let me know either way!