Use fixtures in net-lb-ext
This commit is contained in:
parent
e10664984e
commit
af41e0fe38
|
@ -13,42 +13,13 @@ This module allows managing a GCE Network Load Balancer and integrates the forwa
|
||||||
This example shows how to reference existing Managed Infrastructure Groups (MIGs).
|
This example shows how to reference existing Managed Infrastructure Groups (MIGs).
|
||||||
|
|
||||||
```hcl
|
```hcl
|
||||||
module "instance_template" {
|
|
||||||
source = "./fabric/modules/compute-vm"
|
|
||||||
project_id = var.project_id
|
|
||||||
zone = "${var.region}-b"
|
|
||||||
name = "vm-test"
|
|
||||||
create_template = true
|
|
||||||
service_account = {
|
|
||||||
auto_create = true
|
|
||||||
}
|
|
||||||
network_interfaces = [
|
|
||||||
{
|
|
||||||
network = var.vpc.self_link
|
|
||||||
subnetwork = var.subnet.self_link
|
|
||||||
}
|
|
||||||
]
|
|
||||||
tags = [
|
|
||||||
"http-server"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
module "mig" {
|
|
||||||
source = "./fabric/modules/compute-mig"
|
|
||||||
project_id = var.project_id
|
|
||||||
location = var.region
|
|
||||||
name = "mig-test"
|
|
||||||
target_size = 1
|
|
||||||
instance_template = module.instance_template.template.self_link
|
|
||||||
}
|
|
||||||
|
|
||||||
module "nlb" {
|
module "nlb" {
|
||||||
source = "./fabric/modules/net-lb-ext"
|
source = "./fabric/modules/net-lb-ext"
|
||||||
project_id = var.project_id
|
project_id = var.project_id
|
||||||
region = var.region
|
region = var.region
|
||||||
name = "nlb-test"
|
name = "nlb-test"
|
||||||
backends = [{
|
backends = [{
|
||||||
group = module.mig.group_manager.instance_group
|
group = module.compute-mig.group_manager.instance_group
|
||||||
}]
|
}]
|
||||||
health_check_config = {
|
health_check_config = {
|
||||||
http = {
|
http = {
|
||||||
|
@ -56,7 +27,7 @@ module "nlb" {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
# tftest modules=3 resources=6 inventory=migs.yaml e2e
|
# tftest modules=3 resources=5 fixtures=fixtures/compute-mig.tf inventory=migs.yaml e2e
|
||||||
```
|
```
|
||||||
|
|
||||||
### Externally managed instances
|
### Externally managed instances
|
||||||
|
@ -64,18 +35,6 @@ 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.
|
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
|
```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" {
|
module "nlb" {
|
||||||
source = "./fabric/modules/net-lb-ext"
|
source = "./fabric/modules/net-lb-ext"
|
||||||
project_id = var.project_id
|
project_id = var.project_id
|
||||||
|
@ -85,7 +44,7 @@ module "nlb" {
|
||||||
my-group = {
|
my-group = {
|
||||||
zone = "${var.region}-b"
|
zone = "${var.region}-b"
|
||||||
instances = [
|
instances = [
|
||||||
for z in ["b", "c"] : module.instance[z].id
|
module.compute-vm-group-b.id,
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -98,10 +57,10 @@ module "nlb" {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
# tftest modules=3 resources=6 inventory=ext_migs.yaml e2e
|
# tftest modules=3 resources=8 fixtures=fixtures/compute-vm-group-bc.tf inventory=ext_migs.yaml e2e
|
||||||
```
|
```
|
||||||
|
|
||||||
### Mutiple forwarding rules
|
### Multiple forwarding rules
|
||||||
|
|
||||||
You can add more forwarding rules to your load balancer and override some forwarding rules defaults, including the global access policy, the IP protocol, the IP version and ports.
|
You can add more forwarding rules to your load balancer and override some forwarding rules defaults, including the global access policy, the IP protocol, the IP version and ports.
|
||||||
|
|
||||||
|
@ -111,18 +70,6 @@ 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.
|
- 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
|
```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" {
|
module "nlb" {
|
||||||
source = "./fabric/modules/net-lb-ext"
|
source = "./fabric/modules/net-lb-ext"
|
||||||
project_id = var.project_id
|
project_id = var.project_id
|
||||||
|
@ -141,12 +88,12 @@ module "nlb" {
|
||||||
my-group = {
|
my-group = {
|
||||||
zone = "${var.region}-b"
|
zone = "${var.region}-b"
|
||||||
instances = [
|
instances = [
|
||||||
for z in ["b", "c"] : module.instance[z].id
|
module.compute-vm-group-b.id,
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
# tftest modules=3 resources=7 inventory=fwd_rules.yaml e2e
|
# tftest modules=3 resources=9 fixtures=fixtures/compute-vm-group-bc.tf inventory=fwd_rules.yaml e2e
|
||||||
```
|
```
|
||||||
|
|
||||||
### Dual stack (IPv4 and IPv6)
|
### Dual stack (IPv4 and IPv6)
|
||||||
|
@ -155,18 +102,6 @@ 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.
|
In this example we set the load balancer to work as dual stack, meaning it exposes both an IPv4 and an IPv6 address.
|
||||||
|
|
||||||
```hcl
|
```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" {
|
module "nlb" {
|
||||||
source = "./fabric/modules/net-lb-ext"
|
source = "./fabric/modules/net-lb-ext"
|
||||||
project_id = var.project_id
|
project_id = var.project_id
|
||||||
|
@ -187,12 +122,12 @@ module "nlb" {
|
||||||
my-group = {
|
my-group = {
|
||||||
zone = "${var.region}-b"
|
zone = "${var.region}-b"
|
||||||
instances = [
|
instances = [
|
||||||
for z in ["b", "c"] : module.instance[z].id
|
module.compute-vm-group-b.id,
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
# tftest modules=3 resources=7 inventory=dual_stack.yaml e2e
|
# tftest modules=3 resources=9 fixtures=fixtures/compute-vm-group-bc.tf inventory=dual_stack.yaml e2e
|
||||||
```
|
```
|
||||||
|
|
||||||
### End to end example
|
### End to end example
|
||||||
|
@ -293,4 +228,9 @@ module "nlb" {
|
||||||
| [health_check_id](outputs.tf#L70) | Auto-created health-check id. | |
|
| [health_check_id](outputs.tf#L70) | Auto-created health-check id. | |
|
||||||
| [health_check_self_link](outputs.tf#L75) | Auto-created health-check self link. | |
|
| [health_check_self_link](outputs.tf#L75) | Auto-created health-check self link. | |
|
||||||
| [id](outputs.tf#L80) | Fully qualified forwarding rule ids. | |
|
| [id](outputs.tf#L80) | Fully qualified forwarding rule ids. | |
|
||||||
|
|
||||||
|
## Fixtures
|
||||||
|
|
||||||
|
- [compute-mig.tf](../../tests/fixtures/compute-mig.tf)
|
||||||
|
- [compute-vm-group-bc.tf](../../tests/fixtures/compute-vm-group-bc.tf)
|
||||||
<!-- END TFDOC -->
|
<!-- END TFDOC -->
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
# Copyright 2024 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.
|
||||||
|
|
||||||
|
module "_instance-template" {
|
||||||
|
source = "./fabric/modules/compute-vm"
|
||||||
|
project_id = var.project_id
|
||||||
|
name = "mig-e2e-template"
|
||||||
|
zone = "${var.region}-b"
|
||||||
|
tags = ["http-server", "ssh"]
|
||||||
|
network_interfaces = [{
|
||||||
|
network = var.vpc.self_link
|
||||||
|
subnetwork = var.subnet.self_link
|
||||||
|
nat = false
|
||||||
|
addresses = null
|
||||||
|
}]
|
||||||
|
boot_disk = {
|
||||||
|
initialize_params = {
|
||||||
|
image = "projects/cos-cloud/global/images/family/cos-stable"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
create_template = true
|
||||||
|
}
|
||||||
|
|
||||||
|
module "compute-mig" {
|
||||||
|
source = "./fabric/modules/compute-mig"
|
||||||
|
project_id = var.project_id
|
||||||
|
location = "${var.region}-b"
|
||||||
|
name = "mig-e2e-tests"
|
||||||
|
# target_size = 0
|
||||||
|
instance_template = module._instance-template.template.self_link
|
||||||
|
}
|
|
@ -100,4 +100,4 @@ counts:
|
||||||
google_compute_region_backend_service: 1
|
google_compute_region_backend_service: 1
|
||||||
google_compute_region_health_check: 1
|
google_compute_region_health_check: 1
|
||||||
modules: 3
|
modules: 3
|
||||||
resources: 7
|
resources: 9
|
||||||
|
|
|
@ -86,8 +86,8 @@ values:
|
||||||
|
|
||||||
counts:
|
counts:
|
||||||
google_compute_forwarding_rule: 1
|
google_compute_forwarding_rule: 1
|
||||||
google_compute_instance_group: 1
|
google_compute_instance_group: 3
|
||||||
google_compute_region_backend_service: 1
|
google_compute_region_backend_service: 1
|
||||||
google_compute_region_health_check: 1
|
google_compute_region_health_check: 1
|
||||||
modules: 3
|
modules: 3
|
||||||
resources: 6
|
resources: 8
|
||||||
|
|
|
@ -105,8 +105,8 @@ values:
|
||||||
|
|
||||||
counts:
|
counts:
|
||||||
google_compute_forwarding_rule: 2
|
google_compute_forwarding_rule: 2
|
||||||
google_compute_instance_group: 1
|
google_compute_instance_group: 3
|
||||||
google_compute_region_backend_service: 1
|
google_compute_region_backend_service: 1
|
||||||
google_compute_region_health_check: 1
|
google_compute_region_health_check: 1
|
||||||
modules: 3
|
modules: 3
|
||||||
resources: 7
|
resources: 9
|
||||||
|
|
|
@ -81,6 +81,5 @@ counts:
|
||||||
google_compute_forwarding_rule: 1
|
google_compute_forwarding_rule: 1
|
||||||
google_compute_region_backend_service: 1
|
google_compute_region_backend_service: 1
|
||||||
google_compute_region_health_check: 1
|
google_compute_region_health_check: 1
|
||||||
google_service_account: 1
|
|
||||||
modules: 3
|
modules: 3
|
||||||
resources: 6
|
resources: 5
|
||||||
|
|
Loading…
Reference in New Issue