Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net_lb_ext module e2e and example testing changes #1909

Merged
merged 3 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
77 changes: 55 additions & 22 deletions modules/net-lb-ext/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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
Expand All @@ -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
Expand All @@ -56,25 +56,36 @@ module "nlb" {
}
}
}
# tftest modules=3 resources=6
# tftest modules=3 resources=6 inventory=migs.yaml e2e
```

### Externally managed instances

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
]
}
}
Expand All @@ -87,7 +98,7 @@ module "nlb" {
}
}
}
# tftest modules=1 resources=4
# tftest modules=3 resources=6 inventory=ext_migs.yaml e2e
```

### Mutiple forwarding rules
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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 : {
Expand All @@ -224,7 +257,7 @@ module "nlb" {
}
}
}
# tftest modules=3 resources=7
# tftest modules=3 resources=7 inventory=e2e.yaml e2e
```
<!-- BEGIN TFDOC -->
## Variables
Expand Down
103 changes: 103 additions & 0 deletions tests/modules/net_lb_ext/examples/dual_stack.yaml
Original file line number Diff line number Diff line change
@@ -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
86 changes: 86 additions & 0 deletions tests/modules/net_lb_ext/examples/e2e.yaml
Original file line number Diff line number Diff line change
@@ -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