Add support for regional health checks to net-lb-int module (#3770)
This commit is contained in:
committed by
GitHub
parent
efd8439788
commit
c20fe4871a
@@ -10,6 +10,7 @@ This module allows managing a GCE Internal Load Balancer and integrates the forw
|
||||
- [Multiple forwarding rules](#multiple-forwarding-rules)
|
||||
- [Dual stack (IPv4 and IPv6)](#dual-stack-ipv4-and-ipv6)
|
||||
- [PSC service attachments](#psc-service-attachments)
|
||||
- [Regional health check](#regional-health-check)
|
||||
- [End to end example](#end-to-end-example)
|
||||
- [Deploying changes to load balancer configurations](#deploying-changes-to-load-balancer-configurations)
|
||||
- [Issues](#issues)
|
||||
@@ -280,6 +281,31 @@ module "ilb" {
|
||||
# tftest modules=1 resources=7
|
||||
```
|
||||
|
||||
### Regional health check
|
||||
|
||||
The `is_regional` flag in the `health_check_config` block allows creating a regional health check instead of a global one.
|
||||
|
||||
```hcl
|
||||
module "ilb" {
|
||||
source = "./fabric/modules/net-lb-int"
|
||||
project_id = var.project_id
|
||||
region = "europe-west1"
|
||||
name = "ilb-test"
|
||||
service_label = "ilb-test"
|
||||
vpc_config = {
|
||||
network = var.vpc.self_link
|
||||
subnetwork = var.subnet.self_link
|
||||
}
|
||||
health_check_config = {
|
||||
is_regional = true
|
||||
http = {
|
||||
port = 80
|
||||
}
|
||||
}
|
||||
}
|
||||
# tftest modules=1 resources=3
|
||||
```
|
||||
|
||||
### End to end example
|
||||
|
||||
This example spins up a simple HTTP server and combines four modules:
|
||||
@@ -374,10 +400,10 @@ One other issue is a `Provider produced inconsistent final plan` error which is
|
||||
|
||||
| name | description | type | required | default |
|
||||
|---|---|:---:|:---:|:---:|
|
||||
| [name](variables.tf#L202) | Name used for all resources. | <code>string</code> | ✓ | |
|
||||
| [project_id](variables.tf#L207) | Project id where resources will be created. | <code>string</code> | ✓ | |
|
||||
| [region](variables.tf#L212) | GCP region. | <code>string</code> | ✓ | |
|
||||
| [vpc_config](variables.tf#L238) | VPC-level configuration. | <code title="object({ network = string subnetwork = string })">object({…})</code> | ✓ | |
|
||||
| [name](variables.tf#L203) | Name used for all resources. | <code>string</code> | ✓ | |
|
||||
| [project_id](variables.tf#L208) | Project id where resources will be created. | <code>string</code> | ✓ | |
|
||||
| [region](variables.tf#L213) | GCP region. | <code>string</code> | ✓ | |
|
||||
| [vpc_config](variables.tf#L239) | VPC-level configuration. | <code title="object({ network = string subnetwork = string })">object({…})</code> | ✓ | |
|
||||
| [backend_service_config](variables.tf#L17) | Backend service level configuration. | <code title="object({ connection_draining_timeout_sec = optional(number) connection_tracking = optional(object({ idle_timeout_sec = optional(number) persist_conn_on_unhealthy = optional(string) track_per_session = optional(bool) })) enable_subsetting = optional(bool) failover_config = optional(object({ disable_conn_drain = optional(bool) drop_traffic_if_unhealthy = optional(bool) ratio = optional(number) })) log_sample_rate = optional(number) name = optional(string) description = optional(string, "Terraform managed.") protocol = optional(string, "UNSPECIFIED") session_affinity = optional(string) timeout_sec = optional(number) })">object({…})</code> | | <code>{}</code> |
|
||||
| [backends](variables.tf#L53) | Load balancer backends. | <code title="list(object({ group = string description = optional(string, "Terraform managed.") failover = optional(bool, false) }))">list(object({…}))</code> | | <code>[]</code> |
|
||||
| [context](variables.tf#L64) | Context-specific interpolations. | <code title="object({ addresses = optional(map(string), {}) locations = optional(map(string), {}) networks = optional(map(string), {}) project_ids = optional(map(string), {}) subnets = optional(map(string), {}) })">object({…})</code> | | <code>{}</code> |
|
||||
@@ -385,10 +411,10 @@ One other issue is a `Provider produced inconsistent final plan` error which is
|
||||
| [forwarding_rules_config](variables.tf#L83) | The optional forwarding rules configuration. | <code title="map(object({ address = optional(string) description = optional(string) global_access = optional(bool, true) ipv6 = optional(bool, false) name = optional(string) ports = optional(list(string), null) protocol = optional(string, "TCP") }))">map(object({…}))</code> | | <code title="{ "" = {} }">{…}</code> |
|
||||
| [group_configs](variables.tf#L99) | Optional unmanaged groups to create. Can be referenced in backends via outputs. | <code title="map(object({ zone = string name = optional(string) description = optional(string, "Terraform managed.") instances = optional(list(string)) named_ports = optional(map(number), {}) }))">map(object({…}))</code> | | <code>{}</code> |
|
||||
| [health_check](variables.tf#L112) | Name of existing health check to use, disables auto-created health check. Also set `health_check_config = null` when cross-referencing an health check from another load balancer module to avoid a Terraform error. | <code>string</code> | | <code>null</code> |
|
||||
| [health_check_config](variables.tf#L118) | Optional auto-created health check configuration, use the output self-link to set it in the auto healing policy. Refer to examples for usage. | <code title="object({ check_interval_sec = optional(number) description = optional(string, "Terraform managed.") enable_logging = optional(bool, false) healthy_threshold = optional(number) name = optional(string) timeout_sec = optional(number) unhealthy_threshold = optional(number) grpc = optional(object({ port = optional(number) port_name = optional(string) port_specification = optional(string) # USE_FIXED_PORT USE_NAMED_PORT USE_SERVING_PORT service_name = optional(string) })) http = optional(object({ host = optional(string) port = optional(number) port_name = optional(string) port_specification = optional(string) # USE_FIXED_PORT USE_NAMED_PORT USE_SERVING_PORT proxy_header = optional(string) request_path = optional(string) response = optional(string) })) http2 = optional(object({ host = optional(string) port = optional(number) port_name = optional(string) port_specification = optional(string) # USE_FIXED_PORT USE_NAMED_PORT USE_SERVING_PORT proxy_header = optional(string) request_path = optional(string) response = optional(string) })) https = optional(object({ host = optional(string) port = optional(number) port_name = optional(string) port_specification = optional(string) # USE_FIXED_PORT USE_NAMED_PORT USE_SERVING_PORT proxy_header = optional(string) request_path = optional(string) response = optional(string) })) tcp = optional(object({ port = optional(number) port_name = optional(string) port_specification = optional(string) # USE_FIXED_PORT USE_NAMED_PORT USE_SERVING_PORT proxy_header = optional(string) request = optional(string) response = optional(string) })) ssl = optional(object({ port = optional(number) port_name = optional(string) port_specification = optional(string) # USE_FIXED_PORT USE_NAMED_PORT USE_SERVING_PORT proxy_header = optional(string) request = optional(string) response = optional(string) })) })">object({…})</code> | | <code title="{ tcp = { port_specification = "USE_SERVING_PORT" } }">{…}</code> |
|
||||
| [labels](variables.tf#L196) | Labels set on resources. | <code>map(string)</code> | | <code>{}</code> |
|
||||
| [service_attachments](variables.tf#L217) | PSC service attachments, keyed by forwarding rule. | <code title="map(object({ nat_subnets = list(string) automatic_connection = optional(bool, false) consumer_accept_lists = optional(map(string), {}) consumer_reject_lists = optional(list(string)) description = optional(string) domain_name = optional(string) enable_proxy_protocol = optional(bool, false) reconcile_connections = optional(bool) }))">map(object({…}))</code> | | <code>null</code> |
|
||||
| [service_label](variables.tf#L232) | Optional prefix of the fully qualified forwarding rule name. | <code>string</code> | | <code>null</code> |
|
||||
| [health_check_config](variables.tf#L118) | Optional auto-created health check configuration, use the output self-link to set it in the auto healing policy. Refer to examples for usage. | <code title="object({ check_interval_sec = optional(number) description = optional(string, "Terraform managed.") enable_logging = optional(bool, false) healthy_threshold = optional(number) is_regional = optional(bool, false) name = optional(string) timeout_sec = optional(number) unhealthy_threshold = optional(number) grpc = optional(object({ port = optional(number) port_name = optional(string) port_specification = optional(string) # USE_FIXED_PORT USE_NAMED_PORT USE_SERVING_PORT service_name = optional(string) })) http = optional(object({ host = optional(string) port = optional(number) port_name = optional(string) port_specification = optional(string) # USE_FIXED_PORT USE_NAMED_PORT USE_SERVING_PORT proxy_header = optional(string) request_path = optional(string) response = optional(string) })) http2 = optional(object({ host = optional(string) port = optional(number) port_name = optional(string) port_specification = optional(string) # USE_FIXED_PORT USE_NAMED_PORT USE_SERVING_PORT proxy_header = optional(string) request_path = optional(string) response = optional(string) })) https = optional(object({ host = optional(string) port = optional(number) port_name = optional(string) port_specification = optional(string) # USE_FIXED_PORT USE_NAMED_PORT USE_SERVING_PORT proxy_header = optional(string) request_path = optional(string) response = optional(string) })) tcp = optional(object({ port = optional(number) port_name = optional(string) port_specification = optional(string) # USE_FIXED_PORT USE_NAMED_PORT USE_SERVING_PORT proxy_header = optional(string) request = optional(string) response = optional(string) })) ssl = optional(object({ port = optional(number) port_name = optional(string) port_specification = optional(string) # USE_FIXED_PORT USE_NAMED_PORT USE_SERVING_PORT proxy_header = optional(string) request = optional(string) response = optional(string) })) })">object({…})</code> | | <code title="{ tcp = { port_specification = "USE_SERVING_PORT" } }">{…}</code> |
|
||||
| [labels](variables.tf#L197) | Labels set on resources. | <code>map(string)</code> | | <code>{}</code> |
|
||||
| [service_attachments](variables.tf#L218) | PSC service attachments, keyed by forwarding rule. | <code title="map(object({ nat_subnets = list(string) automatic_connection = optional(bool, false) consumer_accept_lists = optional(map(string), {}) consumer_reject_lists = optional(list(string)) description = optional(string) domain_name = optional(string) enable_proxy_protocol = optional(bool, false) reconcile_connections = optional(bool) }))">map(object({…}))</code> | | <code>null</code> |
|
||||
| [service_label](variables.tf#L233) | Optional prefix of the fully qualified forwarding rule name. | <code>string</code> | | <code>null</code> |
|
||||
|
||||
## Outputs
|
||||
|
||||
@@ -403,8 +429,8 @@ One other issue is a `Provider produced inconsistent final plan` error which is
|
||||
| [group_self_links](outputs.tf#L57) | Optional unmanaged instance group self links. | |
|
||||
| [groups](outputs.tf#L64) | Optional unmanaged instance group resources. | |
|
||||
| [health_check](outputs.tf#L69) | Auto-created health-check resource. | |
|
||||
| [health_check_id](outputs.tf#L74) | Auto-created health-check id. | |
|
||||
| [health_check_self_link](outputs.tf#L79) | Auto-created health-check self link. | |
|
||||
| [id](outputs.tf#L84) | Fully qualified forwarding rule ids. | |
|
||||
| [service_attachment_ids](outputs.tf#L92) | Service attachment ids. | |
|
||||
| [health_check_id](outputs.tf#L78) | Auto-created health-check id. | |
|
||||
| [health_check_self_link](outputs.tf#L87) | Auto-created health-check self link. | |
|
||||
| [id](outputs.tf#L96) | Fully qualified forwarding rule ids. | |
|
||||
| [service_attachment_ids](outputs.tf#L104) | Service attachment ids. | |
|
||||
<!-- END TFDOC -->
|
||||
|
||||
@@ -30,7 +30,7 @@ locals {
|
||||
|
||||
resource "google_compute_health_check" "default" {
|
||||
provider = google-beta
|
||||
count = local.hc != null ? 1 : 0
|
||||
count = local.hc != null && !try(local.hc.is_regional, false) ? 1 : 0
|
||||
project = local.project_id
|
||||
name = coalesce(local.hc.name, var.name)
|
||||
description = local.hc.description
|
||||
@@ -119,3 +119,95 @@ resource "google_compute_health_check" "default" {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resource "google_compute_region_health_check" "default" {
|
||||
count = local.hc != null && try(local.hc.is_regional, false) ? 1 : 0
|
||||
project = local.project_id
|
||||
region = local.region
|
||||
name = coalesce(local.hc.name, var.name)
|
||||
description = local.hc.description
|
||||
check_interval_sec = local.hc.check_interval_sec
|
||||
healthy_threshold = local.hc.healthy_threshold
|
||||
timeout_sec = local.hc.timeout_sec
|
||||
unhealthy_threshold = local.hc.unhealthy_threshold
|
||||
|
||||
dynamic "grpc_health_check" {
|
||||
for_each = local.hc_grpc ? [""] : []
|
||||
content {
|
||||
port = local.hc.grpc.port
|
||||
port_name = local.hc.grpc.port_name
|
||||
port_specification = local.hc.grpc.port_specification
|
||||
grpc_service_name = local.hc.grpc.service_name
|
||||
}
|
||||
}
|
||||
|
||||
dynamic "http_health_check" {
|
||||
for_each = local.hc_http ? [""] : []
|
||||
content {
|
||||
host = local.hc.http.host
|
||||
port = local.hc.http.port
|
||||
port_name = local.hc.http.port_name
|
||||
port_specification = local.hc.http.port_specification
|
||||
proxy_header = local.hc.http.proxy_header
|
||||
request_path = local.hc.http.request_path
|
||||
response = local.hc.http.response
|
||||
}
|
||||
}
|
||||
|
||||
dynamic "http2_health_check" {
|
||||
for_each = local.hc_http2 ? [""] : []
|
||||
content {
|
||||
host = local.hc.http2.host
|
||||
port = local.hc.http2.port
|
||||
port_name = local.hc.http2.port_name
|
||||
port_specification = local.hc.http2.port_specification
|
||||
proxy_header = local.hc.http2.proxy_header
|
||||
request_path = local.hc.http2.request_path
|
||||
response = local.hc.http2.response
|
||||
}
|
||||
}
|
||||
|
||||
dynamic "https_health_check" {
|
||||
for_each = local.hc_https ? [""] : []
|
||||
content {
|
||||
host = local.hc.https.host
|
||||
port = local.hc.https.port
|
||||
port_name = local.hc.https.port_name
|
||||
port_specification = local.hc.https.port_specification
|
||||
proxy_header = local.hc.https.proxy_header
|
||||
request_path = local.hc.https.request_path
|
||||
response = local.hc.https.response
|
||||
}
|
||||
}
|
||||
|
||||
dynamic "ssl_health_check" {
|
||||
for_each = local.hc_ssl ? [""] : []
|
||||
content {
|
||||
port = local.hc.ssl.port
|
||||
port_name = local.hc.ssl.port_name
|
||||
port_specification = local.hc.ssl.port_specification
|
||||
proxy_header = local.hc.ssl.proxy_header
|
||||
request = local.hc.ssl.request
|
||||
response = local.hc.ssl.response
|
||||
}
|
||||
}
|
||||
|
||||
dynamic "tcp_health_check" {
|
||||
for_each = local.hc_tcp ? [""] : []
|
||||
content {
|
||||
port = local.hc.tcp.port
|
||||
port_name = local.hc.tcp.port_name
|
||||
port_specification = local.hc.tcp.port_specification
|
||||
proxy_header = local.hc.tcp.proxy_header
|
||||
request = local.hc.tcp.request
|
||||
response = local.hc.tcp.response
|
||||
}
|
||||
}
|
||||
|
||||
dynamic "log_config" {
|
||||
for_each = try(local.hc.enable_logging, null) == true ? [""] : []
|
||||
content {
|
||||
enable = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,10 +31,10 @@ locals {
|
||||
}
|
||||
}
|
||||
ctx_p = "$"
|
||||
health_check = (
|
||||
var.health_check != null
|
||||
? var.health_check
|
||||
: google_compute_health_check.default[0].self_link
|
||||
health_check = coalesce(
|
||||
var.health_check,
|
||||
try(google_compute_health_check.default[0].self_link, null),
|
||||
try(google_compute_region_health_check.default[0].self_link, null)
|
||||
)
|
||||
network = lookup(
|
||||
local.ctx.networks, var.vpc_config.network, var.vpc_config.network
|
||||
|
||||
@@ -68,17 +68,29 @@ output "groups" {
|
||||
|
||||
output "health_check" {
|
||||
description = "Auto-created health-check resource."
|
||||
value = try(google_compute_health_check.default[0], null)
|
||||
value = try(
|
||||
google_compute_health_check.default[0],
|
||||
google_compute_region_health_check.default[0],
|
||||
null
|
||||
)
|
||||
}
|
||||
|
||||
output "health_check_id" {
|
||||
description = "Auto-created health-check id."
|
||||
value = try(google_compute_health_check.default[0].id, null)
|
||||
value = try(
|
||||
google_compute_health_check.default[0].id,
|
||||
google_compute_region_health_check.default[0].id,
|
||||
null
|
||||
)
|
||||
}
|
||||
|
||||
output "health_check_self_link" {
|
||||
description = "Auto-created health-check self link."
|
||||
value = try(google_compute_health_check.default[0].self_link, null)
|
||||
value = try(
|
||||
google_compute_health_check.default[0].self_link,
|
||||
google_compute_region_health_check.default[0].self_link,
|
||||
null
|
||||
)
|
||||
}
|
||||
|
||||
output "id" {
|
||||
|
||||
@@ -122,6 +122,7 @@ variable "health_check_config" {
|
||||
description = optional(string, "Terraform managed.")
|
||||
enable_logging = optional(bool, false)
|
||||
healthy_threshold = optional(number)
|
||||
is_regional = optional(bool, false)
|
||||
name = optional(string)
|
||||
timeout_sec = optional(number)
|
||||
unhealthy_threshold = optional(number)
|
||||
|
||||
Reference in New Issue
Block a user