From 5936c47dc2463d56c8d848d4fdafc860bba97092 Mon Sep 17 00:00:00 2001 From: Jared Holgate Date: Fri, 29 Nov 2024 08:13:31 +0000 Subject: [PATCH] Fix sub resource checks --- .../modules/hub-and-spoke-vnet/locals.bastion.tf | 2 +- .../modules/hub-and-spoke-vnet/locals.ddos.tf | 2 +- .../modules/hub-and-spoke-vnet/locals.dns.tf | 2 +- .../modules/hub-and-spoke-vnet/locals.gateways.tf | 4 ++-- .../modules/hub-and-spoke-vnet/locals.subnets.tf | 2 +- .../modules/virtual-wan/locals.bastion.tf | 2 +- .../platform_landing_zone/modules/virtual-wan/locals.ddos.tf | 2 +- .../platform_landing_zone/modules/virtual-wan/locals.dns.tf | 2 +- .../modules/virtual-wan/locals.virtual.network.tf | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/templates/platform_landing_zone/modules/hub-and-spoke-vnet/locals.bastion.tf b/templates/platform_landing_zone/modules/hub-and-spoke-vnet/locals.bastion.tf index 3d6030f..2f288f4 100644 --- a/templates/platform_landing_zone/modules/hub-and-spoke-vnet/locals.bastion.tf +++ b/templates/platform_landing_zone/modules/hub-and-spoke-vnet/locals.bastion.tf @@ -1,5 +1,5 @@ locals { - bastions_enabled = { for key, value in var.hub_virtual_networks : key => can(value.bastion) } + bastions_enabled = { for key, value in var.hub_virtual_networks : key => try(value.bastion, null) != null } } locals { diff --git a/templates/platform_landing_zone/modules/hub-and-spoke-vnet/locals.ddos.tf b/templates/platform_landing_zone/modules/hub-and-spoke-vnet/locals.ddos.tf index c38a86e..20e7788 100644 --- a/templates/platform_landing_zone/modules/hub-and-spoke-vnet/locals.ddos.tf +++ b/templates/platform_landing_zone/modules/hub-and-spoke-vnet/locals.ddos.tf @@ -1,4 +1,4 @@ locals { - ddos_protection_plan = can(var.hub_and_spoke_networks_settings.ddos_protection_plan.name) ? var.hub_and_spoke_networks_settings.ddos_protection_plan : null + ddos_protection_plan = try(var.hub_and_spoke_networks_settings.ddos_protection_plan.name, null) != null ? var.hub_and_spoke_networks_settings.ddos_protection_plan : null ddos_protection_plan_enabled = local.ddos_protection_plan != null } diff --git a/templates/platform_landing_zone/modules/hub-and-spoke-vnet/locals.dns.tf b/templates/platform_landing_zone/modules/hub-and-spoke-vnet/locals.dns.tf index c718d43..b2d1710 100644 --- a/templates/platform_landing_zone/modules/hub-and-spoke-vnet/locals.dns.tf +++ b/templates/platform_landing_zone/modules/hub-and-spoke-vnet/locals.dns.tf @@ -1,5 +1,5 @@ locals { - private_dns_zones_enabled = { for key, value in var.hub_virtual_networks : key => can(value.private_dns_zones) } + private_dns_zones_enabled = { for key, value in var.hub_virtual_networks : key => try(value.private_dns_zones, null) != null } } locals { diff --git a/templates/platform_landing_zone/modules/hub-and-spoke-vnet/locals.gateways.tf b/templates/platform_landing_zone/modules/hub-and-spoke-vnet/locals.gateways.tf index fd2578e..a544c9d 100644 --- a/templates/platform_landing_zone/modules/hub-and-spoke-vnet/locals.gateways.tf +++ b/templates/platform_landing_zone/modules/hub-and-spoke-vnet/locals.gateways.tf @@ -5,7 +5,7 @@ locals { virtual_network_gateway = merge({ type = "ExpressRoute" }, hub_network_value.virtual_network_gateways.express_route) - } if can(hub_network_value.virtual_network_gateways.express_route) + } if try(hub_network_value.virtual_network_gateways.express_route, null) != null } virtual_network_gateways_vpn = { for hub_network_key, hub_network_value in var.hub_virtual_networks : "${hub_network_key}-vpn" => { @@ -13,7 +13,7 @@ locals { virtual_network_gateway = merge({ type = "Vpn" }, hub_network_value.virtual_network_gateways.vpn) - } if can(hub_network_value.virtual_network_gateways.vpn) + } if try(hub_network_value.virtual_network_gateways.vpn, null) != null } virtual_network_gateways = merge(local.virtual_network_gateways_express_route, local.virtual_network_gateways_vpn) } diff --git a/templates/platform_landing_zone/modules/hub-and-spoke-vnet/locals.subnets.tf b/templates/platform_landing_zone/modules/hub-and-spoke-vnet/locals.subnets.tf index 6f85f9a..618929e 100644 --- a/templates/platform_landing_zone/modules/hub-and-spoke-vnet/locals.subnets.tf +++ b/templates/platform_landing_zone/modules/hub-and-spoke-vnet/locals.subnets.tf @@ -35,7 +35,7 @@ locals { route_table = { assign_generated_route_table = false } - } } if can(value.virtual_network_gateways.express_route) || can(value.virtual_network_gateways.vpn) + } } if try(value.virtual_network_gateways, null) != null && (can(value.virtual_network_gateways.express_route) || can(value.virtual_network_gateways.vpn)) } subnets = { for key, value in var.hub_virtual_networks : key => merge(local.private_dns_resolver_subnets[key], local.bastion_subnets[key], local.gateway_subnets[key]) } diff --git a/templates/platform_landing_zone/modules/virtual-wan/locals.bastion.tf b/templates/platform_landing_zone/modules/virtual-wan/locals.bastion.tf index 5e933ec..98bd1a4 100644 --- a/templates/platform_landing_zone/modules/virtual-wan/locals.bastion.tf +++ b/templates/platform_landing_zone/modules/virtual-wan/locals.bastion.tf @@ -1,5 +1,5 @@ locals { - bastions_enabled = { for key, value in var.virtual_hubs : key => can(value.bastion) } + bastions_enabled = { for key, value in var.virtual_hubs : key => try(value.bastion, null) != null } } locals { diff --git a/templates/platform_landing_zone/modules/virtual-wan/locals.ddos.tf b/templates/platform_landing_zone/modules/virtual-wan/locals.ddos.tf index 4218898..d35d29c 100644 --- a/templates/platform_landing_zone/modules/virtual-wan/locals.ddos.tf +++ b/templates/platform_landing_zone/modules/virtual-wan/locals.ddos.tf @@ -1,4 +1,4 @@ locals { - ddos_protection_plan = can(var.virtual_wan_settings.ddos_protection_plan.name) ? var.virtual_wan_settings.ddos_protection_plan : null + ddos_protection_plan = try(var.virtual_wan_settings.ddos_protection_plan.name, null) != null ? var.virtual_wan_settings.ddos_protection_plan : null ddos_protection_plan_enabled = local.ddos_protection_plan != null } diff --git a/templates/platform_landing_zone/modules/virtual-wan/locals.dns.tf b/templates/platform_landing_zone/modules/virtual-wan/locals.dns.tf index e174a35..fb5a914 100644 --- a/templates/platform_landing_zone/modules/virtual-wan/locals.dns.tf +++ b/templates/platform_landing_zone/modules/virtual-wan/locals.dns.tf @@ -1,5 +1,5 @@ locals { - private_dns_zones_enabled = { for key, value in var.virtual_hubs : key => can(value.private_dns_zones) } + private_dns_zones_enabled = { for key, value in var.virtual_hubs : key => try(value.private_dns_zones, null) != null } } locals { diff --git a/templates/platform_landing_zone/modules/virtual-wan/locals.virtual.network.tf b/templates/platform_landing_zone/modules/virtual-wan/locals.virtual.network.tf index 181ce98..0876a2b 100644 --- a/templates/platform_landing_zone/modules/virtual-wan/locals.virtual.network.tf +++ b/templates/platform_landing_zone/modules/virtual-wan/locals.virtual.network.tf @@ -1,5 +1,5 @@ locals { - side_car_virtual_networks_enabled = { for key, value in var.virtual_hubs : key => can(value.side_car_virtual_network) } + side_car_virtual_networks_enabled = { for key, value in var.virtual_hubs : key => try(value.side_car_virtual_network, null) != null } } locals {