feat(net-lb-app-int): support regional health checks (#3939)
Introduce support for regional health checks in the net-lb-app-int module while maintaining backward compatibility. Added optional is_regional flag to health_check_configs (defaulting to false). When true, it creates google_compute_region_health_check instead of google_compute_health_check. Updated backend services and outputs to merge both global and regional health check IDs. Added a new test case to verify regional health check functionality. TAG=agy CONV=6aff620c-e5a5-44eb-afe0-459cff820daa
This commit is contained in:
committed by
GitHub
parent
6c9ed94602
commit
30b9d4c74f
@@ -1079,7 +1079,7 @@ For deploying changes to load balancer configuration please refer to [net-lb-app
|
||||
|---|---|---|
|
||||
| [backend-service.tf](./backend-service.tf) | Backend service resources. | <code>google_compute_region_backend_service</code> |
|
||||
| [groups.tf](./groups.tf) | None | <code>google_compute_instance_group</code> |
|
||||
| [health-check.tf](./health-check.tf) | Health check resource. | <code>google_compute_health_check</code> |
|
||||
| [health-check.tf](./health-check.tf) | Health check resources. | <code>google_compute_health_check</code> · <code>google_compute_region_health_check</code> |
|
||||
| [main.tf](./main.tf) | Module-level locals and resources. | <code>google_compute_forwarding_rule</code> · <code>google_compute_network_endpoint</code> · <code>google_compute_network_endpoint_group</code> · <code>google_compute_region_network_endpoint</code> · <code>google_compute_region_network_endpoint_group</code> · <code>google_compute_region_ssl_certificate</code> · <code>google_compute_region_target_http_proxy</code> · <code>google_compute_region_target_https_proxy</code> · <code>google_compute_service_attachment</code> |
|
||||
| [outputs.tf](./outputs.tf) | Module outputs. | |
|
||||
| [urlmap.tf](./urlmap.tf) | URL map resources. | <code>google_compute_region_url_map</code> |
|
||||
@@ -1126,11 +1126,11 @@ For deploying changes to load balancer configuration please refer to [net-lb-app
|
||||
| [forwarding_rule](outputs.tf#L36) | Forwarding rule resource. | |
|
||||
| [group_ids](outputs.tf#L41) | Autogenerated instance group ids. | |
|
||||
| [health_check_ids](outputs.tf#L48) | Autogenerated health check ids. | |
|
||||
| [id](outputs.tf#L55) | Fully qualified forwarding rule id. | |
|
||||
| [neg_ids](outputs.tf#L61) | Autogenerated network endpoint group ids. | |
|
||||
| [psc_neg_ids](outputs.tf#L68) | Autogenerated PSC network endpoint group ids. | |
|
||||
| [regional_neg_ids](outputs.tf#L75) | Autogenerated regional network endpoint group ids. | |
|
||||
| [service_attachment_id](outputs.tf#L82) | Id of the service attachment. | |
|
||||
| [id](outputs.tf#L60) | Fully qualified forwarding rule id. | |
|
||||
| [neg_ids](outputs.tf#L66) | Autogenerated network endpoint group ids. | |
|
||||
| [psc_neg_ids](outputs.tf#L73) | Autogenerated PSC network endpoint group ids. | |
|
||||
| [regional_neg_ids](outputs.tf#L80) | Autogenerated regional network endpoint group ids. | |
|
||||
| [service_attachment_id](outputs.tf#L87) | Id of the service attachment. | |
|
||||
|
||||
## Fixtures
|
||||
|
||||
|
||||
@@ -37,9 +37,14 @@ locals {
|
||||
for k, v in google_compute_region_network_endpoint.internet : k => v.id
|
||||
}
|
||||
)
|
||||
hc_ids = {
|
||||
for k, v in google_compute_health_check.default : k => v.id
|
||||
}
|
||||
hc_ids = merge(
|
||||
{
|
||||
for k, v in google_compute_health_check.default : k => v.id
|
||||
},
|
||||
{
|
||||
for k, v in google_compute_region_health_check.default : k => v.id
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
resource "google_compute_region_backend_service" "default" {
|
||||
|
||||
@@ -14,11 +14,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
# tfdoc:file:description Health check resource.
|
||||
# tfdoc:file:description Health check resources.
|
||||
|
||||
resource "google_compute_health_check" "default" {
|
||||
provider = google-beta
|
||||
for_each = var.health_check_configs
|
||||
for_each = { for k, v in var.health_check_configs : k => v if !try(v.is_regional, false) }
|
||||
project = (
|
||||
each.value.project_id == null
|
||||
? local.project_id
|
||||
@@ -111,3 +111,100 @@ resource "google_compute_health_check" "default" {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resource "google_compute_region_health_check" "default" {
|
||||
provider = google-beta
|
||||
for_each = { for k, v in var.health_check_configs : k => v if try(v.is_regional, false) }
|
||||
project = (
|
||||
each.value.project_id == null
|
||||
? local.project_id
|
||||
: each.value.project_id
|
||||
)
|
||||
name = coalesce(each.value.name, "${var.name}-${each.key}")
|
||||
region = local.region
|
||||
description = each.value.description
|
||||
check_interval_sec = each.value.check_interval_sec
|
||||
healthy_threshold = each.value.healthy_threshold
|
||||
timeout_sec = each.value.timeout_sec
|
||||
unhealthy_threshold = each.value.unhealthy_threshold
|
||||
|
||||
dynamic "grpc_health_check" {
|
||||
for_each = try(each.value.grpc, null) != null ? [""] : []
|
||||
content {
|
||||
port = each.value.grpc.port
|
||||
port_name = each.value.grpc.port_name
|
||||
port_specification = each.value.grpc.port_specification
|
||||
grpc_service_name = each.value.grpc.service_name
|
||||
}
|
||||
}
|
||||
|
||||
dynamic "http_health_check" {
|
||||
for_each = try(each.value.http, null) != null ? [""] : []
|
||||
content {
|
||||
host = each.value.http.host
|
||||
port = each.value.http.port
|
||||
port_name = each.value.http.port_name
|
||||
port_specification = each.value.http.port_specification
|
||||
proxy_header = each.value.http.proxy_header
|
||||
request_path = each.value.http.request_path
|
||||
response = each.value.http.response
|
||||
}
|
||||
}
|
||||
|
||||
dynamic "http2_health_check" {
|
||||
for_each = try(each.value.http2, null) != null ? [""] : []
|
||||
content {
|
||||
host = each.value.http2.host
|
||||
port = each.value.http2.port
|
||||
port_name = each.value.http2.port_name
|
||||
port_specification = each.value.http2.port_specification
|
||||
proxy_header = each.value.http2.proxy_header
|
||||
request_path = each.value.http2.request_path
|
||||
response = each.value.http2.response
|
||||
}
|
||||
}
|
||||
|
||||
dynamic "https_health_check" {
|
||||
for_each = try(each.value.https, null) != null ? [""] : []
|
||||
content {
|
||||
host = each.value.https.host
|
||||
port = each.value.https.port
|
||||
port_name = each.value.https.port_name
|
||||
port_specification = each.value.https.port_specification
|
||||
proxy_header = each.value.https.proxy_header
|
||||
request_path = each.value.https.request_path
|
||||
response = each.value.https.response
|
||||
}
|
||||
}
|
||||
|
||||
dynamic "ssl_health_check" {
|
||||
for_each = try(each.value.ssl, null) != null ? [""] : []
|
||||
content {
|
||||
port = each.value.ssl.port
|
||||
port_name = each.value.ssl.port_name
|
||||
port_specification = each.value.ssl.port_specification
|
||||
proxy_header = each.value.ssl.proxy_header
|
||||
request = each.value.ssl.request
|
||||
response = each.value.ssl.response
|
||||
}
|
||||
}
|
||||
|
||||
dynamic "tcp_health_check" {
|
||||
for_each = try(each.value.tcp, null) != null ? [""] : []
|
||||
content {
|
||||
port = each.value.tcp.port
|
||||
port_name = each.value.tcp.port_name
|
||||
port_specification = each.value.tcp.port_specification
|
||||
proxy_header = each.value.tcp.proxy_header
|
||||
request = each.value.tcp.request
|
||||
response = each.value.tcp.response
|
||||
}
|
||||
}
|
||||
|
||||
dynamic "log_config" {
|
||||
for_each = try(each.value.enable_logging, null) == true ? [""] : []
|
||||
content {
|
||||
enable = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,9 +47,14 @@ output "group_ids" {
|
||||
|
||||
output "health_check_ids" {
|
||||
description = "Autogenerated health check ids."
|
||||
value = {
|
||||
for k, v in google_compute_health_check.default : k => v.id
|
||||
}
|
||||
value = merge(
|
||||
{
|
||||
for k, v in google_compute_health_check.default : k => v.id
|
||||
},
|
||||
{
|
||||
for k, v in google_compute_region_health_check.default : k => v.id
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
output "id" {
|
||||
|
||||
@@ -24,6 +24,7 @@ variable "health_check_configs" {
|
||||
description = optional(string, "Terraform managed.")
|
||||
enable_logging = optional(bool, false)
|
||||
healthy_threshold = optional(number)
|
||||
is_regional = optional(bool, false)
|
||||
project_id = optional(string)
|
||||
timeout_sec = optional(number)
|
||||
unhealthy_threshold = optional(number)
|
||||
|
||||
Reference in New Issue
Block a user