Azure / terraform-azurerm-caf-enterprise-scale

Azure landing zones Terraform module
https://aka.ms/alz/tf
MIT License
844 stars 554 forks source link

Renaming Connectivity Resources - Multiple Hub Virtual Networks #944

Open w2jzthr602 opened 4 months ago

w2jzthr602 commented 4 months ago

Community Note

Versions

Configure Terraform to set the required AzureRM provider version and features{} block

terraform { required_providers { azurerm = { source = "hashicorp/azurerm" version = "3.93.0"

Declare the Azure landing zones Terraform module and provide the connectivity configuration

module "alz" { source = "Azure/caf-enterprise-scale/azurerm" version = "5.1.0" providers = { azurerm = azurerm azurerm.connectivity = azurerm azurerm.management = azurerm }

Description

I'm trying to provide a custom resource names for the virtual network hub connectivity resources. I'm able to get it working with one virtual network hub but no combination that I have tried works with two virtual network hubs.

This one works:

Configure custom connectivity resources settings

locals { configure_connectivity_resources = { settings = {

Create two hub networks with hub mesh peering enabled

  # and link to DDoS protection plan if created
  hub_networks = [
    {
      config = {
        address_space                   = ["10.96.0.0/20", ]
        location                        = var.primary_location
        link_to_ddos_protection_plan    = var.enable_ddos_protection
        enable_hub_network_mesh_peering = true
      }
    }
  ]  

advanced = { custom_settings_by_resource_type = { azurerm_resource_group = { connectivity = { (var.primary_location) = { name = "rgp-network-shs" } }, dns = { (var.primary_location) = { name = "rgp-dns-shs" } } }, azurerm_virtual_network = { connectivity = { eastus2 = { name = "vnt-10_96_0_0-20-shs-us-east-2" } } }
} }

This one does not work:

Configure custom connectivity resources settings

locals { configure_connectivity_resources = { settings = {

Create two hub networks with hub mesh peering enabled

  # and link to DDoS protection plan if created
  hub_networks = [
    {
      config = {
        address_space                   = ["10.96.0.0/20", ]
        location                        = var.primary_location
        link_to_ddos_protection_plan    = var.enable_ddos_protection
        enable_hub_network_mesh_peering = true
      },
      config = {
        address_space                   = ["10.97.0.0/20", ]
        location                        = var.secondary_location
        link_to_ddos_protection_plan    = var.enable_ddos_protection
        enable_hub_network_mesh_peering = true
      }
    }
  ] 

advanced = {
  custom_settings_by_resource_type = {
    azurerm_resource_group = {
      connectivity = {
        (var.primary_location) = {
        name = "rgp-network-shs"
        }
      },
      dns = {
        (var.primary_location) = {
        name = "rgp-dns-shs"
        }
      }
    },
    azurerm_virtual_network = {
      connectivity = {
        eastus2 = {
        name = "vnt-10_96_0_0-20-shs-us-east-2"
        }
      },
      connectivity = {  
        centralus = {
        name = "vnt-10_97_0_0-20-shs-us-central-1"
        }
      }
    }  
  }
}
matt-FFFFFF commented 4 months ago
azurerm_virtual_network = {
      connectivity = {
        eastus2 = {
        name = "vnt-10_96_0_0-20-shs-us-east-2"
        }
      },
      connectivity = {  
        centralus = {
        name = "vnt-10_97_0_0-20-shs-us-central-1"
        }

You have duplicate connectivity keys in this map. Have you tried moving the centralus attribute to be a sibling of eastus2?

w2jzthr602 commented 4 months ago

@matt-FFFFFF Thanks for your response. I tried this but it still only wants to create the second VNet and RG. The first one gets ignored.

  hub_networks = [
    {
      config = {
        address_space                   = ["10.96.0.0/20", ]
        location                        = var.primary_location
        link_to_ddos_protection_plan    = var.enable_ddos_protection
        enable_hub_network_mesh_peering = true
      },
      config = {
        address_space                   = ["10.97.0.0/20", ]
        location                        = var.secondary_location
        link_to_ddos_protection_plan    = var.enable_ddos_protection
        enable_hub_network_mesh_peering = true
      },
    }
  ]

advanced = {
  custom_settings_by_resource_type = {
    azurerm_resource_group = {
      connectivity = {
        (var.primary_location) = {
        name = "rgp-network-shs-us-east-2"
        },
        (var.secondary_location) = {
        name = "rgp-network-shs-us-central-1"
        },
      },
      dns = {
        (var.primary_location) = {
        name = "rgp-dns-shs"
        }
      }
    },
    azurerm_virtual_network = {
      connectivity = {
        (var.primary_location) = {
        name = "vnt-10_96_0_0-20-shs-us-east-2"
        },
        (var.secondary_location) = {
        name = "vnt-10_97_0_0-20-shs-us-central-1"
        },
      }
    }  
  }
}