This module allows managing a GCE Network Load Balancer and integrates the forwarding rule, regional backend, and optional health check resources. It's designed to be a simple match for the [`compute-vm`](../compute-vm) module, which can be used to manage instance templates and instance groups.
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 "nlb" {
source = "./fabric/modules/net-nlb"
project_id = var.project_id
region = "europe-west1"
name = "nlb-test"
group_configs = {
my-group = {
zone = "europe-west1-b"
instances = [
"instance-1-self-link",
"instance-2-self-link"
]
}
}
backends = [{
group = module.nlb.groups.my-group.self_link
}]
health_check_config = {
http = {
port = 80
}
}
}
# tftest modules=1 resources=4
```
### End to end example
This example spins up a simple HTTP server and combines four modules:
- [`nginx`](../cloud-config-container/nginx) from the `cloud-config-container` collection, to manage instance configuration
- [`compute-vm`](../compute-vm) to manage the instance template and unmanaged instance group
- this module to create a Network Load Balancer in front of the managed instance group
Note that the example uses the GCE default service account. You might want to create an ad-hoc service account by combining the [`iam-service-account`](../iam-service-account) module, or by having the GCE VM module create one for you. In both cases, remember to set at least logging write permissions for the service account, or the container on the instances won't be able to start.
| [backends](variables.tf#L72) | Load balancer backends, balancing mode is one of 'CONNECTION' or 'UTILIZATION'. | <codetitle="list(object({ group = string description = optional(string, "Terraform managed.") failover = optional(bool, false) }))">list(object({…}))</code> | | <code>[]</code> |
| [description](variables.tf#L83) | Optional description used for resources. | <code>string</code> | | <code>"Terraform managed."</code> |
| [group_configs](variables.tf#L89) | Optional unmanaged groups to create. Can be referenced in backends via outputs. | <codetitle="map(object({ zone = string instances = optional(list(string), []) named_ports = optional(map(number), {}) }))">map(object({…}))</code> | | <code>{}</code> |
| [health_check](variables.tf#L100) | Name of existing health check to use, disables auto-created health check. | <code>string</code> | | <code>null</code> |
| [labels](variables.tf#L180) | Labels set on resources. | <code>map(string)</code> | | <code>{}</code> |
| [ports](variables.tf#L191) | Comma-separated ports, leave null to use all ports. | <code>list(string)</code> | | <code>null</code> |
| [protocol](variables.tf#L202) | IP protocol used, defaults to TCP. UDP or L3_DEFAULT can also be used. | <code>string</code> | | <code>"TCP"</code> |