From 09e6e8f4d2900e061fff26dc39b2b4ed0efbb841 Mon Sep 17 00:00:00 2001 From: Dave Gulli Date: Wed, 13 Sep 2023 16:49:14 +1000 Subject: [PATCH] created passing test, fixed logic --- modules/net-vpc/README.md | 9 ++++++++- modules/net-vpc/subnets.tf | 11 ++++++++--- tests/modules/net_vpc/examples/factory.yaml | 15 +++++++++++++-- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/modules/net-vpc/README.md b/modules/net-vpc/README.md index d6617118..3be4d37d 100644 --- a/modules/net-vpc/README.md +++ b/modules/net-vpc/README.md @@ -355,7 +355,7 @@ module "vpc" { name = "my-network" data_folder = "config/subnets" } -# tftest modules=1 resources=9 files=subnet-simple,subnet-simple-2,subnet-detailed,subnet-proxy,subnet-psc inventory=factory.yaml +# tftest modules=1 resources=10 files=subnet-simple,subnet-simple-2,subnet-detailed,subnet-proxy,subnet-proxy-global,subnet-psc inventory=factory.yaml ``` ```yaml @@ -399,6 +399,13 @@ ip_cidr_range: 10.1.0.0/24 purpose: REGIONAL_MANAGED_PROXY ``` +```yaml +# tftest-file id=subnet-proxy-global path=config/subnets/subnet-proxy-global.yaml +region: australia-southeast2 +ip_cidr_range: 10.4.0.0/24 +purpose: GLOBAL_MANAGED_PROXY +``` + ```yaml # tftest-file id=subnet-psc path=config/subnets/subnet-psc.yaml region: europe-west4 diff --git a/modules/net-vpc/subnets.tf b/modules/net-vpc/subnets.tf index e3655f70..1e3206e0 100644 --- a/modules/net-vpc/subnets.tf +++ b/modules/net-vpc/subnets.tf @@ -35,7 +35,7 @@ locals { iam_members = try(v.iam_members, []) purpose = try(v.purpose, null) active = try(v.active, null) - global = try(v.purpose, null) + global = null } } _factory_subnets_iam = [ @@ -135,8 +135,13 @@ resource "google_compute_subnetwork" "proxy_only" { ? "Terraform-managed proxy-only subnet for Regional HTTPS, Internal HTTPS or Cross-Regional HTTPS Internal LB." : each.value.description ) - purpose = each.value.global != false ? "GLOBAL_MANAGED_PROXY" : "REGIONAL_MANAGED_PROXY" - role = each.value.active != false ? "ACTIVE" : "BACKUP" + purpose = try( + each.value.purpose, + each.value.global != false + ? "GLOBAL_MANAGED_PROXY" + : "REGIONAL_MANAGED_PROXY") + + role = each.value.active != false ? "ACTIVE" : "BACKUP" } resource "google_compute_subnetwork" "psc" { diff --git a/tests/modules/net_vpc/examples/factory.yaml b/tests/modules/net_vpc/examples/factory.yaml index fa1f19ff..50aa01e1 100644 --- a/tests/modules/net_vpc/examples/factory.yaml +++ b/tests/modules/net_vpc/examples/factory.yaml @@ -58,6 +58,17 @@ values: region: europe-west4 role: ACTIVE timeouts: null + module.vpc.google_compute_subnetwork.proxy_only["australia-southeast2/subnet-proxy-global"]: + description: Terraform-managed proxy-only subnet for Regional HTTPS, Internal HTTPS or Cross-Regional HTTPS Internal LB. + ip_cidr_range: 10.4.0.0/24 + ipv6_access_type: null + log_config: [] + name: subnet-proxy-global + project: my-project + purpose: GLOBAL_MANAGED_PROXY + region: australia-southeast2 + role: ACTIVE + timeouts: null module.vpc.google_compute_subnetwork.psc["europe-west4/subnet-psc"]: description: Terraform-managed subnet for Private Service Connect (PSC NAT). ip_cidr_range: 10.2.0.0/24 @@ -126,9 +137,9 @@ values: counts: google_compute_network: 1 google_compute_route: 2 - google_compute_subnetwork: 5 + google_compute_subnetwork: 6 google_compute_subnetwork_iam_binding: 1 modules: 1 - resources: 9 + resources: 10 outputs: {}