Skip to main content

Internally-Facing Regional TCP/UDP Load Balancer on GCP

GitHub Logo Terraform Logo

Reference

Requirements

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

Providers

NameVersion
google~> 4.54
google-betan/a

Modules

No modules.

Resources

NameType
google-beta_google_compute_region_backend_service.thisresource
google_compute_forwarding_rule.thisresource
google_compute_health_check.thisresource

Inputs

NameDescriptionTypeDefaultRequired
all_portsForward all ports of the ip_protocol from the frontend to the backends. Needs to be null if ports are provided.boolnullno
allow_global_access(Optional) If true, clients can access ILB from all regions. By default false, only allow from the ILB's local region; useful if the ILB is a next hop of a route.boolfalseno
backendsNames of primary backend groups (IGs or IGMs). Typically use module.vmseries.instance_group_self_links here.map(string)n/ayes
connection_draining_timeout_sec(Optional) Time for which instance will be drained (not accept new connections, but still work to finish started).numbernullno
connection_tracking_policyConnection tracking policy settings. Following options are available:
- mode - (Optional|string) PER_CONNECTION (default) or PER_SESSION
- idle_timeout_sec - (Optional|number) Defaults to 600 seconds, can only be modified in specific conditions (see link below)
- persistence_on_unhealthy_backends - (Optional|string) DEFAULT_FOR_PROTOCOL (default), ALWAYS_PERSIST or NEVER_PERSIST

More information about supported configurations in conjunction with session_affinity is available in Internal TCP/UDP Load Balancing documentation.
map(any)nullno
disable_connection_drain_on_failover(Optional) On failover or failback, this field indicates whether connection drain will be honored. Setting this to true has the following effect: connections to the old active pool are not drained. Connections to the new active pool use the timeout of 10 min (currently fixed). Setting to false has the following effect: both old and new connections will have a drain timeout of 10 min. This can be set to true only if the protocol is TCP. The default is false.boolnullno
drop_traffic_if_unhealthy(Optional) Used only when no healthy VMs are detected in the primary and backup instance groups. When set to true, traffic is dropped. When set to false, new connections are sent across all VMs in the primary group. The default is false.boolnullno
failover_backends(Optional) Names of failover backend groups (IGs or IGMs). Failover groups are ignored unless the primary groups do not meet collective health threshold.map(string){}no
failover_ratio(Optional) The value of the field must be in [0, 1]. If the ratio of the healthy VMs in the primary backend is at or below this number, traffic arriving at the load-balanced IP will be directed to the failover_backends. In case where 'failoverRatio' is not set or all the VMs in the backup backend are unhealthy, the traffic will be directed back to the primary backend in the force mode, where traffic will be spread to the healthy VMs with the best effort, or to all VMs when no VM is healthy. This field is only used with l4 load balancing.numbernullno
health_check(Optional) Name of either the global google_compute_health_check or google_compute_region_health_check to use. Conflicts with health_check_port.stringnullno
health_check_port(Optional) Port number for TCP healthchecking, default 22. This setting is ignored when health_check is provided.number22no
ip_addressn/aanynullno
ip_protocolThe IP protocol for the frontend forwarding rule, valid values are TCP and UDP.string"TCP"no
nameName of the load balancer (that is, both the forwarding rule and the backend service)stringn/ayes
networkn/aanynullno
portsWhich port numbers are forwarded to the backends (up to 5 ports). Conflicts with all_ports.list(number)[]no
projectThe project to deploy to. If unset the default provider project is used.stringnullno
regionRegion to create ILB in.stringnullno
session_affinityControls distribution of new connections (or fragmented UDP packets) from clients to the backends, can influence available connection tracking configurations.
Valid values are: NONE (default), CLIENT_IP_NO_DESTINATION, CLIENT_IP, CLIENT_IP_PROTO, CLIENT_IP_PORT_PROTO.
stringnullno
subnetworkn/astringn/ayes
timeout_sec(Optional) How many seconds to wait for the backend before dropping the connection. Default is 30 seconds. Valid range is [1, 86400].numbernullno

Outputs

NameDescription
addressn/a
forwarding_rulen/a