@@ -57,7 +57,7 @@ data "azurerm_resources" "vnets" {
5757resource "azurerm_virtual_network" "primary_virtual_network" {
5858 count = local. create_network_infrastructure ? 0 : 1
5959
60- name = " power-platform-primary-vnet- ${ random_string . name . id } "
60+ name = azurecaf_name . main_names . results [ " azurerm_virtual_network " ]
6161 resource_group_name = local. resource_group_name
6262 location = var. primary_location
6363 address_space = var. primary_vnet_address_spaces
@@ -67,7 +67,7 @@ resource "azurerm_virtual_network" "primary_virtual_network" {
6767resource "azurerm_virtual_network" "failover_virtual_network" {
6868 count = local. create_network_infrastructure ? 0 : 1
6969
70- name = " power-platform-failover-vnet- ${ random_string . name . id } "
70+ name = azurecaf_name . failover_names . results [ " azurerm_virtual_network " ]
7171 resource_group_name = local. resource_group_name
7272 location = var. failover_location
7373 address_space = var. failover_vnet_address_spaces
@@ -98,7 +98,7 @@ resource "azurerm_subnet_nat_gateway_association" "primary_subnet_nat" {
9898 count = local. create_network_infrastructure ? 0 : 1
9999
100100 subnet_id = azurerm_subnet. primary_subnet [0 ]. id
101- nat_gateway_id = azurerm_nat_gateway. nat_gateways [ " primary " ]. id
101+ nat_gateway_id = azurerm_nat_gateway. primary_nat_gateway [ 0 ]. id
102102}
103103
104104# Create failover subnets as first-class resources
@@ -125,15 +125,15 @@ resource "azurerm_subnet_nat_gateway_association" "failover_subnet_nat" {
125125 count = local. create_network_infrastructure ? 0 : 1
126126
127127 subnet_id = azurerm_subnet. failover_subnet [0 ]. id
128- nat_gateway_id = azurerm_nat_gateway. nat_gateways [ " failover " ]. id
128+ nat_gateway_id = azurerm_nat_gateway. failover_nat_gateway [ 0 ]. id
129129}
130130
131131# Create dedicated private endpoint subnets without delegations
132132resource "azurerm_subnet" "pe_primary_subnet" {
133133 count = local. create_network_infrastructure ? 0 : 1
134134
135135 # checkov:skip=CKV2_AZURE_31:"Ensure VNET subnet is configured with a Network Security Group (NSG)
136- name = " pe-primary-subnet "
136+ name = azurecaf_name . main_pe_subnet_names . results [ " azurerm_subnet " ]
137137 resource_group_name = local. resource_group_name
138138 virtual_network_name = azurerm_virtual_network. primary_virtual_network [0 ]. name
139139 address_prefixes = var. primary_pe_subnet_address_spaces
@@ -147,7 +147,7 @@ resource "azurerm_subnet" "pe_failover_subnet" {
147147 # checkov:skip=CKV2_AZURE_31:"Ensure VNET subnet is configured with a Network Security Group (NSG)
148148 count = local. create_network_infrastructure ? 0 : 1
149149
150- name = " pe-failover-subnet "
150+ name = azurecaf_name . failover_pe_subnet_names . results [ " azurerm_subnet " ]
151151 resource_group_name = local. resource_group_name
152152 virtual_network_name = azurerm_virtual_network. failover_virtual_network [0 ]. name
153153 address_prefixes = var. failover_pe_subnet_address_spaces
@@ -183,7 +183,7 @@ resource "azurerm_subnet_nat_gateway_association" "github_runner_primary_subnet_
183183 count = var. deploy_github_runner && local. create_network_infrastructure == false ? 1 : 0
184184
185185 subnet_id = azurerm_subnet. github_runner_primary_subnet [0 ]. id
186- nat_gateway_id = azurerm_nat_gateway. nat_gateways [ " primary " ]. id
186+ nat_gateway_id = azurerm_nat_gateway. primary_nat_gateway [ 0 ]. id
187187}
188188
189189resource "azurerm_subnet" "github_runner_failover_subnet" {
@@ -210,55 +210,71 @@ resource "azurerm_subnet_nat_gateway_association" "github_runner_failover_subnet
210210 count = var. deploy_github_runner && local. create_network_infrastructure == false ? 1 : 0
211211
212212 subnet_id = azurerm_subnet. github_runner_failover_subnet [0 ]. id
213- nat_gateway_id = azurerm_nat_gateway. nat_gateways [ " failover " ]. id
213+ nat_gateway_id = azurerm_nat_gateway. failover_nat_gateway [ 0 ]. id
214214}
215215
216216# Create public IP addresses for NAT gateways
217- resource "azurerm_public_ip" "nat_gateway_ips" {
218- for_each = local. create_network_infrastructure ? {} : {
219- primary = var.primary_location
220- failover = var.failover_location
221- }
217+ resource "azurerm_public_ip" "primary_nat_gateway_ip" {
218+ count = local. create_network_infrastructure ? 0 : 1
219+ name = azurecaf_name. main_names . results [" azurerm_public_ip" ]
220+ location = var. primary_location
221+ resource_group_name = local. resource_group_name
222+ allocation_method = " Static"
223+ sku = " Standard"
224+ tags = var. tags
225+ }
222226
223- name = " ${ each . key } -nat-gateway-ip"
224- location = each. value
227+ resource "azurerm_public_ip" "failover_nat_gateway_ip" {
228+ count = local. create_network_infrastructure ? 0 : 1
229+ name = azurecaf_name. failover_names . results [" azurerm_public_ip" ]
230+ location = var. failover_location
225231 resource_group_name = local. resource_group_name
226232 allocation_method = " Static"
227233 sku = " Standard"
228234 tags = var. tags
229235}
230236
231- resource "azurerm_nat_gateway" "nat_gateways" {
232- for_each = local. create_network_infrastructure ? {} : {
233- primary = var.primary_location
234- failover = var.failover_location
235- }
237+ resource "azurerm_nat_gateway" "primary_nat_gateway" {
238+ count = local. create_network_infrastructure ? 0 : 1
239+ location = var. primary_location
240+ name = azurecaf_name. main_names . results [" azurerm_virtual_network_gateway" ]
241+ resource_group_name = local. resource_group_name
242+ sku_name = " Standard"
243+ tags = var. tags
236244
237- location = each. value
238- name = " ${ each . key } -nat-gateway"
245+ # Associate the public IP address with the NAT gateway
246+ depends_on = [azurerm_public_ip . primary_nat_gateway_ip ]
247+ }
248+
249+ resource "azurerm_nat_gateway" "failover_nat_gateway" {
250+ count = local. create_network_infrastructure ? 0 : 1
251+ location = var. failover_location
252+ name = azurecaf_name. failover_names . results [" azurerm_virtual_network_gateway" ]
239253 resource_group_name = local. resource_group_name
240254 sku_name = " Standard"
241255 tags = var. tags
242256
243257 # Associate the public IP address with the NAT gateway
244- depends_on = [azurerm_public_ip . nat_gateway_ips ]
258+ depends_on = [azurerm_public_ip . failover_nat_gateway_ip ]
245259}
246260
247261# Associate public IP addresses with NAT gateways
248- resource "azurerm_nat_gateway_public_ip_association" "nat_gateway_ip_associations " {
249- for_each = local. create_network_infrastructure ? {} : {
250- primary = var.primary_location
251- failover = var.failover_location
252- }
262+ resource "azurerm_nat_gateway_public_ip_association" "primary_nat_gateway_ip_association " {
263+ count = local. create_network_infrastructure ? 0 : 1
264+ nat_gateway_id = azurerm_nat_gateway . primary_nat_gateway [ 0 ] . id
265+ public_ip_address_id = azurerm_public_ip . primary_nat_gateway_ip [ 0 ] . id
266+ }
253267
254- nat_gateway_id = azurerm_nat_gateway. nat_gateways [each . key ]. id
255- public_ip_address_id = azurerm_public_ip. nat_gateway_ips [each . key ]. id
268+ resource "azurerm_nat_gateway_public_ip_association" "failover_nat_gateway_ip_association" {
269+ count = local. create_network_infrastructure ? 0 : 1
270+ nat_gateway_id = azurerm_nat_gateway. failover_nat_gateway [0 ]. id
271+ public_ip_address_id = azurerm_public_ip. failover_nat_gateway_ip [0 ]. id
256272}
257273
258274resource "azurerm_subnet" "deployment_script_container_subnet" {
259275 count = local. create_network_infrastructure ? 0 : 1
260276
261- name = " deploymentscript-subnet "
277+ name = azurecaf_name . deployment_script_names . results [ " azurerm_subnet " ]
262278 resource_group_name = local. resource_group_name
263279 virtual_network_name = azurerm_virtual_network. primary_virtual_network [0 ]. name
264280 address_prefixes = var. deployment_script_subnet_address_spaces
@@ -278,7 +294,7 @@ resource "azurerm_subnet_nat_gateway_association" "deployment_script_nat" {
278294 count = local. create_network_infrastructure ? 0 : 1
279295
280296 subnet_id = azurerm_subnet. deployment_script_container_subnet [0 ]. id
281- nat_gateway_id = azurerm_nat_gateway. nat_gateways [ " primary " ]. id
297+ nat_gateway_id = azurerm_nat_gateway. primary_nat_gateway [ 0 ]. id
282298}
283299
284300# ============================================================================
@@ -289,7 +305,7 @@ resource "azurerm_subnet_nat_gateway_association" "deployment_script_nat" {
289305resource "azurerm_network_security_group" "power_platform_primary_nsg" {
290306 count = local. create_network_infrastructure ? 0 : 1
291307
292- name = " power-platform-primary-nsg- ${ random_string . name . id } "
308+ name = azurecaf_name . main_names . results [ " azurerm_network_security_group " ]
293309 location = var. primary_location
294310 resource_group_name = local. resource_group_name
295311 tags = var. tags
@@ -351,7 +367,7 @@ resource "azurerm_network_security_group" "power_platform_primary_nsg" {
351367resource "azurerm_network_security_group" "power_platform_failover_nsg" {
352368 count = local. create_network_infrastructure ? 0 : 1
353369
354- name = " power-platform-failover-nsg- ${ random_string . name . id } "
370+ name = azurecaf_name . failover_names . results [ " azurerm_network_security_group " ]
355371 location = var. failover_location
356372 resource_group_name = local. resource_group_name
357373 tags = var. tags
@@ -413,7 +429,7 @@ resource "azurerm_network_security_group" "power_platform_failover_nsg" {
413429resource "azurerm_network_security_group" "private_endpoint_primary_nsg" {
414430 count = local. create_network_infrastructure ? 0 : 1
415431
416- name = " private-endpoint-primary-nsg- ${ random_string . name . id } "
432+ name = azurecaf_name . main_pe_subnet_names . results [ " azurerm_subnet " ]
417433 location = var. primary_location
418434 resource_group_name = local. resource_group_name
419435 tags = var. tags
@@ -449,7 +465,7 @@ resource "azurerm_network_security_group" "private_endpoint_primary_nsg" {
449465resource "azurerm_network_security_group" "private_endpoint_failover_nsg" {
450466 count = local. create_network_infrastructure ? 0 : 1
451467
452- name = " private-endpoint-failover-nsg- ${ random_string . name . id } "
468+ name = azurecaf_name . failover_pe_subnet_names . results [ " azurerm_subnet " ]
453469 location = var. failover_location
454470 resource_group_name = local. resource_group_name
455471 tags = var. tags
@@ -558,7 +574,7 @@ resource "azurerm_network_security_group" "github_runner_nsg" {
558574resource "azurerm_network_security_group" "deployment_script_nsg" {
559575 count = local. create_network_infrastructure ? 0 : 1
560576
561- name = " deployment-script-nsg- ${ random_string . name . id } "
577+ name = azurecaf_name . deployment_script_names . results [ " azurerm_network_security_group " ]
562578 location = var. primary_location
563579 resource_group_name = local. resource_group_name
564580 tags = var. tags
0 commit comments