From c65e242685471a5eaf4d88dc25439026b1fccd8b Mon Sep 17 00:00:00 2001 From: dibaskar-google <131877501+dibaskar-google@users.noreply.github.com> Date: Fri, 8 Dec 2023 10:04:07 +0100 Subject: [PATCH] net_lb_ext module e2e and example testing changes (#1909) E2E tests for net_lb_ext --- modules/net-lb-ext/README.md | 77 ++++++++---- .../net_lb_ext/examples/dual_stack.yaml | 103 ++++++++++++++++ tests/modules/net_lb_ext/examples/e2e.yaml | 86 ++++++++++++++ .../modules/net_lb_ext/examples/ext_migs.yaml | 93 +++++++++++++++ .../net_lb_ext/examples/fwd_rules.yaml | 112 ++++++++++++++++++ tests/modules/net_lb_ext/examples/migs.yaml | 86 ++++++++++++++ 6 files changed, 535 insertions(+), 22 deletions(-) create mode 100644 tests/modules/net_lb_ext/examples/dual_stack.yaml create mode 100644 tests/modules/net_lb_ext/examples/e2e.yaml create mode 100644 tests/modules/net_lb_ext/examples/ext_migs.yaml create mode 100644 tests/modules/net_lb_ext/examples/fwd_rules.yaml create mode 100644 tests/modules/net_lb_ext/examples/migs.yaml diff --git a/modules/net-lb-ext/README.md b/modules/net-lb-ext/README.md index 020c11046..4e0d7d8af 100644 --- a/modules/net-lb-ext/README.md +++ b/modules/net-lb-ext/README.md @@ -16,7 +16,7 @@ This example shows how to reference existing Managed Infrastructure Groups (MIGs module "instance_template" { source = "./fabric/modules/compute-vm" project_id = var.project_id - zone = "europe-west1-b" + zone = "${var.region}-b" name = "vm-test" create_template = true service_account = { @@ -36,7 +36,7 @@ module "instance_template" { module "mig" { source = "./fabric/modules/compute-mig" project_id = var.project_id - location = "europe-west1" + location = var.region name = "mig-test" target_size = 1 instance_template = module.instance_template.template.self_link @@ -45,7 +45,7 @@ module "mig" { module "nlb" { source = "./fabric/modules/net-lb-ext" project_id = var.project_id - region = "europe-west1" + region = var.region name = "nlb-test" backends = [{ group = module.mig.group_manager.instance_group @@ -56,7 +56,7 @@ module "nlb" { } } } -# tftest modules=3 resources=6 +# tftest modules=3 resources=6 inventory=migs.yaml e2e ``` ### Externally managed instances @@ -64,17 +64,28 @@ module "nlb" { This examples shows how to create an NLB by combining externally managed instances (in a custom module or even outside of the current root module) in an unmanaged group. When using internally managed groups, remember to run `terraform apply` each time group instances change. ```hcl +module "instance" { + source = "./fabric/modules/compute-vm" + for_each = toset(["b", "c"]) + name = "instance-${each.key}" + project_id = var.project_id + zone = "${var.region}-b" + network_interfaces = [{ + network = var.vpc.self_link + subnetwork = var.subnet.self_link + }] +} + module "nlb" { source = "./fabric/modules/net-lb-ext" project_id = var.project_id - region = "europe-west1" + region = var.region name = "nlb-test" group_configs = { my-group = { - zone = "europe-west1-b" + zone = "${var.region}-b" instances = [ - "instance-1-self-link", - "instance-2-self-link" + for z in ["b", "c"] : module.instance[z].id ] } } @@ -87,7 +98,7 @@ module "nlb" { } } } -# tftest modules=1 resources=4 +# tftest modules=3 resources=6 inventory=ext_migs.yaml e2e ``` ### Mutiple forwarding rules @@ -100,10 +111,22 @@ The example adds two forwarding rules: - the second one, called `nlb-test-vip-two` exposes an IPv4 address, it listens on port 80 and allows connections from the same region only. ```hcl +module "instance" { + source = "./fabric/modules/compute-vm" + for_each = toset(["b", "c"]) + name = "instance-${each.key}" + project_id = var.project_id + zone = "${var.region}-b" + network_interfaces = [{ + network = var.vpc.self_link + subnetwork = var.subnet.self_link + }] +} + module "nlb" { source = "./fabric/modules/net-lb-ext" project_id = var.project_id - region = "europe-west1" + region = var.region name = "nlb-test" backends = [{ group = module.nlb.groups.my-group.self_link @@ -116,15 +139,14 @@ module "nlb" { } group_configs = { my-group = { - zone = "europe-west1-b" + zone = "${var.region}-b" instances = [ - "instance-1-self-link", - "instance-2-self-link" + for z in ["b", "c"] : module.instance[z].id ] } } } -# tftest modules=1 resources=5 +# tftest modules=3 resources=7 inventory=fwd_rules.yaml e2e ``` ### Dual stack (IPv4 and IPv6) @@ -133,10 +155,22 @@ Your load balancer can use a combination of either or both IPv4 and IPv6 forward In this example we set the load balancer to work as dual stack, meaning it exposes both an IPv4 and an IPv6 address. ```hcl +module "instance" { + source = "./fabric/modules/compute-vm" + for_each = toset(["b", "c"]) + name = "instance-${each.key}" + project_id = var.project_id + zone = "${var.region}-b" + network_interfaces = [{ + network = var.vpc.self_link + subnetwork = var.subnet.self_link + }] +} + module "nlb" { source = "./fabric/modules/net-lb-ext" project_id = var.project_id - region = "europe-west1" + region = var.region name = "nlb-test" backends = [{ group = module.nlb.groups.my-group.self_link @@ -151,15 +185,14 @@ module "nlb" { } group_configs = { my-group = { - zone = "europe-west1-b" + zone = "${var.region}-b" instances = [ - "instance-1-self-link", - "instance-2-self-link" + for z in ["b", "c"] : module.instance[z].id ] } } } -# tftest modules=1 resources=5 +# tftest modules=3 resources=7 inventory=dual_stack.yaml e2e ``` ### End to end example @@ -181,7 +214,7 @@ module "instance-group" { source = "./fabric/modules/compute-vm" for_each = toset(["b", "c"]) project_id = var.project_id - zone = "europe-west1-${each.key}" + zone = "${var.region}-${each.key}" name = "nlb-test-${each.key}" network_interfaces = [{ network = var.vpc.self_link @@ -206,7 +239,7 @@ module "instance-group" { module "nlb" { source = "./fabric/modules/net-lb-ext" project_id = var.project_id - region = "europe-west1" + region = var.region name = "nlb-test" backends = [ for z, mod in module.instance-group : { @@ -224,7 +257,7 @@ module "nlb" { } } } -# tftest modules=3 resources=7 +# tftest modules=3 resources=7 inventory=e2e.yaml e2e ``` ## Variables diff --git a/tests/modules/net_lb_ext/examples/dual_stack.yaml b/tests/modules/net_lb_ext/examples/dual_stack.yaml new file mode 100644 index 000000000..631c93d06 --- /dev/null +++ b/tests/modules/net_lb_ext/examples/dual_stack.yaml @@ -0,0 +1,103 @@ +# Copyright 2023 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +values: + module.nlb.google_compute_forwarding_rule.forwarding_rules["ipv4"]: + all_ports: true + allow_global_access: null + allow_psc_global_access: null + description: null + ip_protocol: TCP + is_mirroring_collector: null + labels: null + load_balancing_scheme: EXTERNAL + name: nlb-test-ipv4 + no_automate_dns_zone: null + ports: null + project: project-id + recreate_closed_psc: false + region: region + service_label: null + source_ip_ranges: null + target: null + timeouts: null + module.nlb.google_compute_forwarding_rule.forwarding_rules["ipv6"]: + all_ports: true + allow_global_access: null + allow_psc_global_access: null + description: null + ip_protocol: TCP + is_mirroring_collector: null + labels: null + load_balancing_scheme: EXTERNAL + name: nlb-test-ipv6 + no_automate_dns_zone: null + ports: null + project: project-id + recreate_closed_psc: false + region: region + service_label: null + source_ip_ranges: null + target: null + timeouts: null + module.nlb.google_compute_region_backend_service.default: + affinity_cookie_ttl_sec: null + circuit_breakers: [] + connection_draining_timeout_sec: 0 + connection_tracking_policy: [] + consistent_hash: [] + description: Terraform managed. + enable_cdn: null + failover_policy: [] + iap: [] + load_balancing_scheme: EXTERNAL + locality_lb_policy: null + name: nlb-test + network: null + outlier_detection: [] + project: project-id + protocol: UNSPECIFIED + region: region + security_policy: null + subsetting: [] + timeouts: null + module.nlb.google_compute_region_health_check.default[0]: + check_interval_sec: 5 + description: Terraform managed. + grpc_health_check: [] + healthy_threshold: 2 + http2_health_check: [] + http_health_check: [] + https_health_check: [] + name: nlb-test + project: project-id + region: region + ssl_health_check: [] + tcp_health_check: + - port: null + port_name: null + port_specification: USE_SERVING_PORT + proxy_header: NONE + request: null + response: null + timeout_sec: 5 + timeouts: null + unhealthy_threshold: 2 + +counts: + google_compute_forwarding_rule: 2 + google_compute_region_backend_service: 1 + google_compute_region_health_check: 1 + modules: 3 + resources: 7 \ No newline at end of file diff --git a/tests/modules/net_lb_ext/examples/e2e.yaml b/tests/modules/net_lb_ext/examples/e2e.yaml new file mode 100644 index 000000000..4d19c3386 --- /dev/null +++ b/tests/modules/net_lb_ext/examples/e2e.yaml @@ -0,0 +1,86 @@ +# Copyright 2023 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +values: + module.nlb.google_compute_forwarding_rule.forwarding_rules[""]: + all_ports: null + allow_global_access: null + allow_psc_global_access: null + description: null + ip_protocol: TCP + is_mirroring_collector: null + labels: null + load_balancing_scheme: EXTERNAL + name: nlb-test + no_automate_dns_zone: null + ports: + - '80' + project: project-id + recreate_closed_psc: false + region: region + service_label: null + source_ip_ranges: null + target: null + timeouts: null + module.nlb.google_compute_region_backend_service.default: + affinity_cookie_ttl_sec: null + circuit_breakers: [] + connection_draining_timeout_sec: 0 + connection_tracking_policy: [] + consistent_hash: [] + description: Terraform managed. + enable_cdn: null + failover_policy: [] + iap: [] + load_balancing_scheme: EXTERNAL + locality_lb_policy: null + name: nlb-test + network: null + outlier_detection: [] + project: project-id + protocol: UNSPECIFIED + region: region + security_policy: null + subsetting: [] + timeouts: null + module.nlb.google_compute_region_health_check.default[0]: + check_interval_sec: 5 + description: Terraform managed. + grpc_health_check: [] + healthy_threshold: 2 + http2_health_check: [] + http_health_check: + - host: null + port: 80 + port_name: null + port_specification: null + proxy_header: NONE + request_path: / + response: null + https_health_check: [] + name: nlb-test + project: project-id + region: region + ssl_health_check: [] + tcp_health_check: [] + timeout_sec: 5 + timeouts: null + unhealthy_threshold: 2 + +counts: + google_compute_forwarding_rule: 1 + google_compute_region_backend_service: 1 + google_compute_region_health_check: 1 + modules: 3 + resources: 7 \ No newline at end of file diff --git a/tests/modules/net_lb_ext/examples/ext_migs.yaml b/tests/modules/net_lb_ext/examples/ext_migs.yaml new file mode 100644 index 000000000..e7f174937 --- /dev/null +++ b/tests/modules/net_lb_ext/examples/ext_migs.yaml @@ -0,0 +1,93 @@ +# Copyright 2023 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +values: + module.nlb.google_compute_forwarding_rule.forwarding_rules[""]: + all_ports: true + allow_global_access: null + allow_psc_global_access: null + description: null + ip_protocol: TCP + is_mirroring_collector: null + labels: null + load_balancing_scheme: EXTERNAL + name: nlb-test + no_automate_dns_zone: null + ports: null + project: project-id + recreate_closed_psc: false + region: region + service_label: null + source_ip_ranges: null + target: null + timeouts: null + module.nlb.google_compute_instance_group.default["my-group"]: + description: Terraform managed. + name: nlb-test-my-group + named_port: [] + project: project-id + timeouts: null + zone: region-b + module.nlb.google_compute_region_backend_service.default: + affinity_cookie_ttl_sec: null + circuit_breakers: [] + connection_draining_timeout_sec: 0 + connection_tracking_policy: [] + consistent_hash: [] + description: Terraform managed. + enable_cdn: null + failover_policy: [] + iap: [] + load_balancing_scheme: EXTERNAL + locality_lb_policy: null + name: nlb-test + network: null + outlier_detection: [] + project: project-id + protocol: UNSPECIFIED + region: region + security_policy: null + subsetting: [] + timeouts: null + module.nlb.google_compute_region_health_check.default[0]: + check_interval_sec: 5 + description: Terraform managed. + grpc_health_check: [] + healthy_threshold: 2 + http2_health_check: [] + http_health_check: + - host: null + port: 80 + port_name: null + port_specification: null + proxy_header: NONE + request_path: / + response: null + https_health_check: [] + name: nlb-test + project: project-id + region: region + ssl_health_check: [] + tcp_health_check: [] + timeout_sec: 5 + timeouts: null + unhealthy_threshold: 2 + +counts: + google_compute_forwarding_rule: 1 + google_compute_instance_group: 1 + google_compute_region_backend_service: 1 + google_compute_region_health_check: 1 + modules: 3 + resources: 6 \ No newline at end of file diff --git a/tests/modules/net_lb_ext/examples/fwd_rules.yaml b/tests/modules/net_lb_ext/examples/fwd_rules.yaml new file mode 100644 index 000000000..6e2317103 --- /dev/null +++ b/tests/modules/net_lb_ext/examples/fwd_rules.yaml @@ -0,0 +1,112 @@ +# Copyright 2023 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +values: + module.nlb.google_compute_forwarding_rule.forwarding_rules["vip-one"]: + all_ports: true + allow_global_access: null + allow_psc_global_access: null + description: null + ip_protocol: TCP + is_mirroring_collector: null + labels: null + load_balancing_scheme: EXTERNAL + name: nlb-test-vip-one + no_automate_dns_zone: null + ports: null + project: project-id + recreate_closed_psc: false + region: region + service_label: null + source_ip_ranges: null + target: null + timeouts: null + module.nlb.google_compute_forwarding_rule.forwarding_rules["vip-two"]: + all_ports: null + allow_global_access: null + allow_psc_global_access: null + description: null + ip_protocol: TCP + is_mirroring_collector: null + labels: null + load_balancing_scheme: EXTERNAL + name: nlb-test-vip-two + no_automate_dns_zone: null + ports: + - '80' + project: project-id + recreate_closed_psc: false + region: region + service_label: null + source_ip_ranges: null + target: null + timeouts: null + module.nlb.google_compute_instance_group.default["my-group"]: + description: Terraform managed. + name: nlb-test-my-group + named_port: [] + project: project-id + timeouts: null + zone: region-b + module.nlb.google_compute_region_backend_service.default: + affinity_cookie_ttl_sec: null + circuit_breakers: [] + connection_draining_timeout_sec: 0 + connection_tracking_policy: [] + consistent_hash: [] + description: Terraform managed. + enable_cdn: null + failover_policy: [] + iap: [] + load_balancing_scheme: EXTERNAL + locality_lb_policy: null + name: nlb-test + network: null + outlier_detection: [] + project: project-id + protocol: UNSPECIFIED + region: region + security_policy: null + subsetting: [] + timeouts: null + module.nlb.google_compute_region_health_check.default[0]: + check_interval_sec: 5 + description: Terraform managed. + grpc_health_check: [] + healthy_threshold: 2 + http2_health_check: [] + http_health_check: [] + https_health_check: [] + name: nlb-test + project: project-id + region: region + ssl_health_check: [] + tcp_health_check: + - port: null + port_name: null + port_specification: USE_SERVING_PORT + proxy_header: NONE + request: null + response: null + timeout_sec: 5 + timeouts: null + unhealthy_threshold: 2 + +counts: + google_compute_forwarding_rule: 2 + google_compute_instance_group: 1 + google_compute_region_backend_service: 1 + google_compute_region_health_check: 1 + modules: 3 + resources: 7 \ No newline at end of file diff --git a/tests/modules/net_lb_ext/examples/migs.yaml b/tests/modules/net_lb_ext/examples/migs.yaml new file mode 100644 index 000000000..d69639226 --- /dev/null +++ b/tests/modules/net_lb_ext/examples/migs.yaml @@ -0,0 +1,86 @@ +# Copyright 2023 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +values: + module.nlb.google_compute_forwarding_rule.forwarding_rules[""]: + all_ports: true + allow_global_access: null + allow_psc_global_access: null + description: null + ip_protocol: TCP + is_mirroring_collector: null + labels: null + load_balancing_scheme: EXTERNAL + name: nlb-test + no_automate_dns_zone: null + ports: null + project: project-id + recreate_closed_psc: false + region: region + service_label: null + source_ip_ranges: null + target: null + timeouts: null + module.nlb.google_compute_region_backend_service.default: + affinity_cookie_ttl_sec: null + circuit_breakers: [] + connection_draining_timeout_sec: 0 + connection_tracking_policy: [] + consistent_hash: [] + description: Terraform managed. + enable_cdn: null + failover_policy: [] + iap: [] + load_balancing_scheme: EXTERNAL + locality_lb_policy: null + name: nlb-test + network: null + outlier_detection: [] + project: project-id + protocol: UNSPECIFIED + region: region + security_policy: null + subsetting: [] + timeouts: null + module.nlb.google_compute_region_health_check.default[0]: + check_interval_sec: 5 + description: Terraform managed. + grpc_health_check: [] + healthy_threshold: 2 + http2_health_check: [] + http_health_check: + - host: null + port: 80 + port_name: null + port_specification: null + proxy_header: NONE + request_path: / + response: null + https_health_check: [] + name: nlb-test + project: project-id + region: region + ssl_health_check: [] + tcp_health_check: [] + timeout_sec: 5 + timeouts: null + unhealthy_threshold: 2 + +counts: + google_compute_forwarding_rule: 1 + google_compute_region_backend_service: 1 + google_compute_region_health_check: 1 + google_service_account: 1 + modules: 3 + resources: 6 \ No newline at end of file