2021年3月28日星期日

Terraform azure output of multiple network interfaces assigning to a single vm

not sure if anyone has come across this issue before, i have multiple network interfaces that i need to attach to a vm in Azure, i am passing in network interface details as a map. i need to use the output of network interfaces and apply it to the network_interface_ids in vm resource. my current code to assign network_interface_ids doesn't seem to be getting the network interface ids from output of azurerm_network_interface. Here is the short snapshot of the code i have:

 resource "azurerm_network_interface" "vmNic" {    for_each = var.network_interfaces      name                = each.value.name    resource_group_name = var.resource_group_name    location            = var.resource_group_location      ip_configuration {      name                          = "${each.value.name}-ip"      subnet_id                     = each.value.subnet_id      private_ip_address_allocation = "Static"      private_ip_address            = each.value.private_ip    }    }    resource "azurerm_virtual_machine" "vm" {       count = length(azurerm_network_interface.vmNic)    name                = var.vm_name    location            = var.resource_group_location    resource_group_name = var.resource_group_name    network_interface_ids = try(azurerm_network_interface.vmNic.*.id[count.index], null)  

any ideas what i am doing wrong here in assigning the network_interface_ids?

https://stackoverflow.com/questions/66828139/terraform-azure-output-of-multiple-network-interfaces-assigning-to-a-single-vm March 27, 2021 at 12:56PM

没有评论:

发表评论