|
1 | 1 | locals { |
2 | 2 | create_network = var.subnet_ids == null && var.subnet_id == null |
3 | 3 |
|
4 | | - hub_subnet_id = coalesce(try(var.subnet_ids.hub_subnet_id, null), var.subnet_id, module.network[0].vnet_subnets[0]) |
5 | | - hub_dr_subnet_id = coalesce(try(var.subnet_ids.hub_dr_subnet_id, null), var.subnet_id, module.network[0].vnet_subnets[1]) |
| 4 | + hub_subnet_id = coalesce(try(var.subnet_ids.hub_subnet_id, null), var.subnet_id, try(module.network[0].vnet_subnets[0], null)) |
| 5 | + hub_dr_subnet_id = coalesce(try(var.subnet_ids.hub_dr_subnet_id, null), var.subnet_id, try(module.network[0].vnet_subnets[1], null)) |
6 | 6 |
|
7 | | - agentless_gw_subnet_id = coalesce(try(var.subnet_ids.agentless_gw_subnet_id, null), var.subnet_id, module.network[0].vnet_subnets[0]) |
8 | | - agentless_gw_dr_subnet_id = coalesce(try(var.subnet_ids.agentless_gw_dr_subnet_id, null), var.subnet_id, module.network[0].vnet_subnets[1]) |
| 7 | + agentless_gw_subnet_id = coalesce(try(var.subnet_ids.agentless_gw_subnet_id, null), var.subnet_id, try(module.network[0].vnet_subnets[0], null)) |
| 8 | + agentless_gw_dr_subnet_id = coalesce(try(var.subnet_ids.agentless_gw_dr_subnet_id, null), var.subnet_id, try(module.network[0].vnet_subnets[1], null)) |
9 | 9 |
|
10 | | - db_subnet_ids = coalescelist(try(var.subnet_ids.db_subnet_ids, []), compact([var.subnet_id]), module.network[0].vnet_subnets) |
| 10 | + db_subnet_ids = coalescelist(try(var.subnet_ids.db_subnet_ids, []), compact([var.subnet_id]), try(module.network[0].vnet_subnets, [])) |
11 | 11 |
|
12 | | - mx_subnet_id = coalesce(try(var.subnet_ids.mx_subnet_id, null), var.subnet_id, module.network[0].vnet_subnets[0]) |
13 | | - agent_gw_subnet_id = coalesce(try(var.subnet_ids.agent_gw_subnet_id, null), var.subnet_id, module.network[0].vnet_subnets[0]) |
| 12 | + mx_subnet_id = coalesce(try(var.subnet_ids.mx_subnet_id, null), var.subnet_id, try(module.network[0].vnet_subnets[0], null)) |
| 13 | + agent_gw_subnet_id = coalesce(try(var.subnet_ids.agent_gw_subnet_id, null), var.subnet_id, try(module.network[0].vnet_subnets[0], null)) |
14 | 14 |
|
15 | | - dra_admin_subnet_id = coalesce(try(var.subnet_ids.dra_admin_subnet_id, null), var.subnet_id, module.network[0].vnet_subnets[0]) |
16 | | - dra_analytics_subnet_id = coalesce(try(var.subnet_ids.dra_analytics_subnet_id, null), var.subnet_id, module.network[0].vnet_subnets[1]) |
| 15 | + dra_admin_subnet_id = coalesce(try(var.subnet_ids.dra_admin_subnet_id, null), var.subnet_id, try(module.network[0].vnet_subnets[0], null)) |
| 16 | + dra_analytics_subnet_id = coalesce(try(var.subnet_ids.dra_analytics_subnet_id, null), var.subnet_id, try(module.network[0].vnet_subnets[1], null)) |
| 17 | + |
| 18 | + all_subnet_ids = concat([ |
| 19 | + local.hub_subnet_id, |
| 20 | + local.hub_dr_subnet_id, |
| 21 | + local.agent_gw_subnet_id, |
| 22 | + local.agentless_gw_dr_subnet_id, |
| 23 | + local.mx_subnet_id, |
| 24 | + local.agent_gw_subnet_id, |
| 25 | + local.dra_admin_subnet_id, |
| 26 | + local.dra_analytics_subnet_id, |
| 27 | + ], local.db_subnet_ids) |
17 | 28 |
|
18 | 29 | subnet_prefixes = cidrsubnets(var.vnet_ip_range, 8, 8) |
| 30 | + |
| 31 | + ipv4_regex = "([0-9]{1,3}\\.){3}[0-9]{1,3}(/([0-9]|[1-2][0-9]|3[0-2]))?" |
| 32 | + |
| 33 | + _all_subnet_address_spaces = distinct(sort( |
| 34 | + concat([for subnet in data.azurerm_subnet.all_subnets : subnet.address_prefixes]...) |
| 35 | + )) |
| 36 | + |
| 37 | + # we can't currently use ipv6 IPs |
| 38 | + all_subnet_address_spaces = [ |
| 39 | + for cidr in local._all_subnet_address_spaces: cidr |
| 40 | + if can(regex(local.ipv4_regex, cidr)) |
| 41 | + ] |
| 42 | +} |
| 43 | + |
| 44 | +data "azurerm_subnet" "all_subnets" { |
| 45 | + for_each = { |
| 46 | + for index, id in local.all_subnet_ids : |
| 47 | + index => id |
| 48 | + } |
| 49 | + |
| 50 | + resource_group_name = split("/", each.value)[4] |
| 51 | + virtual_network_name = split("/", each.value)[8] |
| 52 | + name = split("/", each.value)[10] |
19 | 53 | } |
20 | 54 |
|
21 | 55 | # network |
|
0 commit comments