From 7f7d249da7e8b649a20ad6afef0ce4423888df43 Mon Sep 17 00:00:00 2001 From: Rupal Sharma Date: Tue, 27 Feb 2024 18:34:49 +0530 Subject: [PATCH] fix:change in count condition --- example/point-to-site-with-ad/main.tf | 38 ++++++++++--------- example/point-to-site-with-ad/output.tf | 2 +- .../point-to-site-with-certificate/main.tf | 34 ++++++++++------- .../point-to-site-with-certificate/output.tf | 2 +- example/site-to-site/main.tf | 33 +++++++++------- example/site-to-site/output.tf | 6 +-- main.tf | 6 +-- output.tf | 8 ++-- 8 files changed, 72 insertions(+), 57 deletions(-) diff --git a/example/point-to-site-with-ad/main.tf b/example/point-to-site-with-ad/main.tf index e8fb5a3..304fdd0 100644 --- a/example/point-to-site-with-ad/main.tf +++ b/example/point-to-site-with-ad/main.tf @@ -26,33 +26,38 @@ module "resource_group" { ## Virtual Network in which vpn subnet(Gateway Subnet) will be created. ##----------------------------------------------------------------------------- module "vnet" { - source = "clouddrove/vnet/azure" - version = "1.0.3" - name = local.name - environment = local.environment + source = "clouddrove/vnet/azure" + version = "1.0.4" + + name = "app" + environment = "test" + label_order = ["name", "environment"] resource_group_name = module.resource_group.resource_group_name location = module.resource_group.resource_group_location - address_space = "10.0.0.0/16" + address_spaces = ["10.30.0.0/16"] } ##----------------------------------------------------------------------------- ## Subnet module call. ## Name specific subnet for vpn will be created. ##----------------------------------------------------------------------------- + module "subnet" { - source = "clouddrove/subnet/azure" - version = "1.0.2" - name = local.name - environment = local.environment + source = "clouddrove/subnet/azure" + version = "1.1.0" + + name = "app" + environment = "test" + label_order = ["name", "environment"] resource_group_name = module.resource_group.resource_group_name location = module.resource_group.resource_group_location - virtual_network_name = join("", module.vnet.vnet_name) + virtual_network_name = module.vnet.vnet_name + #subnet - specific_name_subnet = true - specific_subnet_names = "GatewaySubnet" - subnet_prefixes = ["10.0.1.0/24"] + subnet_names = ["default"] + subnet_prefixes = ["10.30.0.0/20"] + # route_table - enable_route_table = false routes = [ { name = "rt-test" @@ -61,7 +66,6 @@ module "subnet" { } ] } - ##----------------------------------------------------------------------------- ## VPN module call. ## Following module will deploy point to site vpn in azure infratsructure. @@ -78,9 +82,9 @@ module "vpn" { address_space = "172.16.200.0/24" vpn_client_protocols = ["OpenVPN"] vpn_auth_types = ["AAD"] - aad_tenant = "https://login.microsoftonline.com/bcffb719XXXXXXXXXXXX7ebfb2f7bdd" + aad_tenant = "https://login.microsoftonline.com/" aad_audience = "41b23e61-6c1e-4545-b367-cd054e0ed4b4" - aad_issuer = "https://sts.windows.net/bcffb719XXXXXXXXXXXX7ebfb2f7bdd/" + aad_issuer = "https://sts.windows.net//" } #### enable diagnostic setting diagnostic_setting_enable = false diff --git a/example/point-to-site-with-ad/output.tf b/example/point-to-site-with-ad/output.tf index f5cb2bd..8c94297 100644 --- a/example/point-to-site-with-ad/output.tf +++ b/example/point-to-site-with-ad/output.tf @@ -1,5 +1,5 @@ output "vpn_gw_id" { - value = join("", module.vpn.*.vpn_gw_id) + value = module.vpn.vpn_gw_id description = "The ID of the Virtual Network Gateway." } diff --git a/example/point-to-site-with-certificate/main.tf b/example/point-to-site-with-certificate/main.tf index 1088500..0a1716c 100644 --- a/example/point-to-site-with-certificate/main.tf +++ b/example/point-to-site-with-certificate/main.tf @@ -25,34 +25,40 @@ module "resource_group" { ## Virtual Network module call. ## Virtual Network in which vpn subnet(Gateway Subnet) will be created. ##----------------------------------------------------------------------------- + module "vnet" { - source = "clouddrove/vnet/azure" - version = "1.0.3" - name = local.name - environment = local.environment + source = "clouddrove/vnet/azure" + version = "1.0.4" + + name = "app" + environment = "test" + label_order = ["name", "environment"] resource_group_name = module.resource_group.resource_group_name location = module.resource_group.resource_group_location - address_space = "10.0.0.0/16" + address_spaces = ["10.30.0.0/16"] } + ##----------------------------------------------------------------------------- ## Subnet module call. ## Name specific subnet for vpn will be created. ##----------------------------------------------------------------------------- module "subnet" { - source = "clouddrove/subnet/azure" - version = "1.0.2" - name = local.name - environment = local.environment + source = "clouddrove/subnet/azure" + version = "1.1.0" + + name = "app" + environment = "test" + label_order = ["name", "environment"] resource_group_name = module.resource_group.resource_group_name location = module.resource_group.resource_group_location - virtual_network_name = join("", module.vnet.vnet_name) + virtual_network_name = module.vnet.vnet_name + #subnet - specific_name_subnet = true - specific_subnet_names = "GatewaySubnet" - subnet_prefixes = ["10.0.1.0/24"] + subnet_names = ["default"] + subnet_prefixes = ["10.30.0.0/20"] + # route_table - enable_route_table = false routes = [ { name = "rt-test" diff --git a/example/point-to-site-with-certificate/output.tf b/example/point-to-site-with-certificate/output.tf index 529228c..5d7bbec 100644 --- a/example/point-to-site-with-certificate/output.tf +++ b/example/point-to-site-with-certificate/output.tf @@ -1,5 +1,5 @@ output "vpn_gw_id" { - value = join("", module.vpn.*.vpn_gw_id_certificate) + value = module.vpn.vpn_gw_id_certificate description = "The ID of the Virtual Network Gateway." } diff --git a/example/site-to-site/main.tf b/example/site-to-site/main.tf index 1e3bf5c..7db0344 100644 --- a/example/site-to-site/main.tf +++ b/example/site-to-site/main.tf @@ -26,33 +26,38 @@ module "resource_group" { ## Virtual Network in which vpn subnet(Gateway Subnet) will be created. ##----------------------------------------------------------------------------- module "vnet" { - source = "clouddrove/vnet/azure" - version = "1.0.3" - name = local.name - environment = local.environment + source = "clouddrove/vnet/azure" + version = "1.0.4" + + name = "app" + environment = "test" + label_order = ["name", "environment"] resource_group_name = module.resource_group.resource_group_name location = module.resource_group.resource_group_location - address_space = "10.0.0.0/16" + address_spaces = ["10.30.0.0/16"] } + ##----------------------------------------------------------------------------- ## Subnet module call. ## Name specific subnet for vpn will be created. ##----------------------------------------------------------------------------- module "subnet" { - source = "clouddrove/subnet/azure" - version = "1.0.2" - name = local.name - environment = local.environment + source = "clouddrove/subnet/azure" + version = "1.1.0" + + name = "app" + environment = "test" + label_order = ["name", "environment"] resource_group_name = module.resource_group.resource_group_name location = module.resource_group.resource_group_location - virtual_network_name = join("", module.vnet.vnet_name) + virtual_network_name = module.vnet.vnet_name + #subnet - specific_name_subnet = true - specific_subnet_names = "GatewaySubnet" - subnet_prefixes = ["10.0.1.0/24"] + subnet_names = ["default"] + subnet_prefixes = ["10.30.0.0/20"] + # route_table - enable_route_table = false routes = [ { name = "rt-test" diff --git a/example/site-to-site/output.tf b/example/site-to-site/output.tf index 9096924..739cdd4 100644 --- a/example/site-to-site/output.tf +++ b/example/site-to-site/output.tf @@ -1,13 +1,13 @@ output "vpn_gw_id" { - value = join("", module.vpn.*.vpn_gw_id) + value = module.vpn.vpn_gw_id description = "The ID of the Virtual Network Gateway." } output "local_network_gw_id" { - value = join("", module.vpn.*.local_network_gw_id) + value = module.vpn.local_network_gw_id description = "The ID of the Local Network Gateway." } output "local_network_gw_connection_id" { - value = join("", module.vpn.*.local_network_gw_connection_id) + value = module.vpn.local_network_gw_connection_id description = "The ID of the Virtual Network Gateway Connection." } diff --git a/main.tf b/main.tf index 1bd13fb..0d41b91 100644 --- a/main.tf +++ b/main.tf @@ -173,13 +173,13 @@ resource "azurerm_local_network_gateway" "localgw" { ## Virtual Network Gateway Connection ##----------------------------------------------------------------------------- resource "azurerm_virtual_network_gateway_connection" "az-hub-onprem" { - count = var.enable && var.gateway_connection_type == "ExpressRoute" ? 1 : length(var.local_networks) + count = var.enable && var.gateway_connection_type == "ExpressRoute" ? length(var.local_networks) : 0 name = var.gateway_connection_type == "ExpressRoute" ? "localgw-expressroute-connection" : "localgw-connection-${var.local_networks[count.index].local_gw_name}" resource_group_name = data.azurerm_resource_group.rg.name location = data.azurerm_resource_group.rg.location type = var.gateway_connection_type - virtual_network_gateway_id = var.sts_vpn == true ? join("", azurerm_virtual_network_gateway.vpngw.*.id) : join("", azurerm_virtual_network_gateway.vpngw2.*.id) - local_network_gateway_id = var.gateway_connection_type != "ExpressRoute" ? azurerm_local_network_gateway.localgw[count.index].id : null + virtual_network_gateway_id = var.sts_vpn == true ? join("", azurerm_virtual_network_gateway.vpngw[0].id) : join("", azurerm_virtual_network_gateway.vpngw2[0].id) + local_network_gateway_id = var.gateway_connection_type != "ExpressRoute" && length(azurerm_local_network_gateway.localgw) > 0 ? azurerm_local_network_gateway.localgw[0].id : null express_route_circuit_id = var.gateway_connection_type == "ExpressRoute" ? var.express_route_circuit_id : null peer_virtual_network_gateway_id = var.gateway_connection_type == "Vnet2Vnet" ? var.peer_virtual_network_gateway_id : null shared_key = var.gateway_connection_type != "ExpressRoute" ? var.local_networks[count.index].shared_key : null diff --git a/output.tf b/output.tf index da7c030..789688d 100644 --- a/output.tf +++ b/output.tf @@ -1,18 +1,18 @@ output "vpn_gw_id" { - value = join("", azurerm_virtual_network_gateway.vpngw.*.id) + value = try( azurerm_virtual_network_gateway.vpngw[0].id, null) description = "The ID of the Virtual Network Gateway." } output "vpn_gw_id_certificate" { - value = join("", azurerm_virtual_network_gateway.vpngw2.*.id) + value = try( azurerm_virtual_network_gateway.vpngw2[0].id, null) description = "The ID of the Virtual Network Gateway." } output "local_network_gw_id" { - value = join("", azurerm_local_network_gateway.localgw.*.id) + value = try(azurerm_local_network_gateway.localgw[*].id, null) description = "The ID of the Local Network Gateway." } output "local_network_gw_connection_id" { - value = join("", azurerm_virtual_network_gateway_connection.az-hub-onprem.*.id) + value = try( azurerm_virtual_network_gateway_connection.az-hub-onprem[*].id, null) description = "The ID of the Virtual Network Gateway Connection." }