Skip to main content

Google Cloud HTTP/HTTPS External Global Load Balancer

A simplified GLB, which assumes that all participating instances are equally capable and that all participating groups are equally capable as well.

GitHub Logo Terraform Logo

Example


module "glb" {
source = "../modules/lb_http_ext_global"
name = "my-glb"
backend_groups = module.vmseries.instance_group_self_links
max_rate_per_instance = 50000
}

Caveat emptor

Currently Google Cloud GLB can only send traffic to the primary network interface (nic0) of a backend instance. One way to work around this is to use NEGs instead of IGs.

Instance Group (IG) re-use

IG that backs an Internal TCP/UDP Load Balancer (ILB) enforces balancing_mode=CONNECTIONS:

Invalid value for field 'resource.backends[0].balancingMode': 'UTILIZATION'. Balancing mode must be CONNECTION for an INTERNAL backend service

Thus if you re-use the same IG for this module (HTTP LB) you need balancing_mode=RATE (and specify the max rate - don't worry it's not a circuit breaker). The balancing_mode=UTILIZATION is incompatible with ILB.

Reference

Requirements

NameVersion
terraform>= 1.3, < 2.0
google~> 4.54

Providers

NameVersion
google~> 4.54

Modules

No modules.

Resources

NameType
google_compute_backend_service.defaultresource
google_compute_global_address.defaultresource
google_compute_global_forwarding_rule.httpresource
google_compute_global_forwarding_rule.httpsresource
google_compute_health_check.defaultresource
google_compute_ssl_certificate.defaultresource
google_compute_target_http_proxy.defaultresource
google_compute_target_https_proxy.defaultresource
google_compute_url_map.defaultresource

Inputs

NameDescriptionTypeDefaultRequired
backend_groupsThe map containing the names of instance groups (IGs) or network endpoint groups (NEGs) to serve. The IGs can be managed or unmanaged or a mix of both. All IGs must handle named port backend_port_name. The NEGs just handle unnamed port.map(string){}no
backend_port_nameThe port_name of the backend groups that this load balancer will serve (default is 'http')string"http"no
backend_protocolThe protocol used to talk to the backend servicestring"HTTP"no
balancing_moden/astring"RATE"no
capacity_scalern/anumbernullno
cdnSet to true to enable cdn on backend.boolfalseno
certificateContent of the SSL certificate. Required if ssl is true and ssl_certificates is empty.string""no
custom_request_headers(Optional) Headers that the HTTP/S load balancer should add to proxied responses.list(string)[]no
health_check_nameName for the health check. If not provided, defaults to <var.name>-healthcheck.stringnullno
health_check_portTCP port to use for health check.number80no
http_forwardSet to false to disable HTTP port 80 forwardbooltrueno
ip_versionIP version for the Global address (IPv4 or v6) - Empty defaults to IPV4string""no
max_connections_per_instancen/anumbernullno
max_rate_per_instancen/anumbernullno
max_utilizationn/anumbernullno
nameName for the forwarding rule and prefix for supporting resourcesstringn/ayes
private_keyContent of the private SSL key. Required if ssl is true and ssl_certificates is empty.string""no
security_policyThe resource URL for the security policy to associate with the backend servicestring""no
sslSet to true to enable SSL support, requires variable ssl_certificates - a list of self_link certsboolfalseno
ssl_certificatesSSL cert self_link list. Required if ssl is true and no private_key and certificate is provided.list(string)[]no
timeout_secTimeout to consider a connection dead, in seconds (default 30)numbernullno
url_mapThe url_map resource to use. Default is to send all traffic to first backend.stringnullno
use_ssl_certificatesIf true, use the certificates provided by ssl_certificates, otherwise, create cert from private_key and certificateboolfalseno

Outputs

NameDescription
addressn/a
allIntended mainly for depends_on but currently succeeds prematurely (while forwarding rules and healtchecks are not yet usable).