Closed sstjean closed 9 months ago
Also as a way to reduce debt, I think we need to rethink the way we create multiple nics.
The way I am thinking is:
Nics are created by one block
nic_configuration = { primary = { subnet_id = azurerm_subnet.temp-snet.id primary = false private_ip_address = "192.168.1.10" }, secondary= { subnet_id = azurerm_subnet.temp-snet.id primary = false private_ip_address = "192.168.1.10" } }
Code block
resource "azurerm_network_interface" "nic" {
for_each = toset(var.instances_count > 0 ? var.nic_configuration : 0)
name = var.instances_count == 1 ? lower("${local.vm_nic_name}") : lower("nic-${format("%s%s", lower(replace(local.vm_nic_name, "/[[:^alnum:]]/", "")), count.index + 1)}")
location = local.location
resource_group_name = local.resource_group_name
dns_servers = var.dns_servers
enable_ip_forwarding = var.enable_ip_forwarding
enable_accelerated_networking = var.enable_accelerated_networking
internal_dns_name_label = var.internal_dns_name_label
tags = merge({ "ResourceName" = var.instances_count == 1 ? lower("${local.vm_nic_name}") : lower("nic-${format("%s%s", lower(replace(local.vm_nic_name, "/[[:^alnum:]]/", "")), count.index + 1)}") }, var.add_tags, var.nic_add_tags, )
ip_configuration {
name = lower("ipconfig-${format("%s%s", lower(replace(local.ip_configuration_name, "/[[:^alnum:]]/", "")), count.index + 1)}")
primary = each.value.primary
subnet_id = each.value.subnet_id
private_ip_address_allocation = each.value.private_ip_address_allocation_type
private_ip_address = var.private_ip_address_allocation_type == "Static" ? element(concat(each.value.private_ip_address, [""]), count.index) : null
public_ip_address_id = var.enable_public_ip_address == true ? element(concat(azurerm_public_ip.pip.*.id, [""]), count.index) : null
}
lifecycle {
ignore_changes = [
tags,
]
}
}
Describe your changes
Issue number
None
Checklist before requesting a review
CHANGELOG.md
fileThanks for your cooperation!