2022-09-26 08:11:52 -04:00
|
|
|
terraform {
|
|
|
|
required_providers {
|
|
|
|
google = {
|
|
|
|
source = "hashicorp/google"
|
2023-10-27 06:06:17 -04:00
|
|
|
version = "4.83.0"
|
2022-09-26 08:11:52 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
locals {
|
|
|
|
name = "${var.name}-${var.backend_port_name}"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_health_check" "health" {
|
|
|
|
name = local.name
|
|
|
|
check_interval_sec = 1
|
|
|
|
timeout_sec = 1
|
|
|
|
|
|
|
|
dynamic "tcp_health_check" {
|
|
|
|
for_each = var.health_check == "TCP" ? [1] : []
|
|
|
|
content {
|
|
|
|
port = var.port
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dynamic "https_health_check" {
|
|
|
|
for_each = var.health_check == "HTTPS" ? [1] : []
|
|
|
|
content {
|
|
|
|
host = ""
|
|
|
|
port = var.port
|
|
|
|
request_path = "/readyz"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_backend_service" "backend" {
|
|
|
|
name = local.name
|
|
|
|
protocol = "TCP"
|
|
|
|
load_balancing_scheme = "EXTERNAL"
|
|
|
|
health_checks = [google_compute_health_check.health.self_link]
|
|
|
|
port_name = var.backend_port_name
|
2022-10-06 21:22:44 -04:00
|
|
|
timeout_sec = 240
|
2022-09-26 08:11:52 -04:00
|
|
|
|
2023-06-19 07:02:01 -04:00
|
|
|
dynamic "backend" {
|
|
|
|
for_each = var.backend_instance_groups
|
|
|
|
content {
|
|
|
|
group = backend.value
|
|
|
|
balancing_mode = "UTILIZATION"
|
|
|
|
}
|
2022-09-26 08:11:52 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_target_tcp_proxy" "proxy" {
|
|
|
|
name = local.name
|
|
|
|
backend_service = google_compute_backend_service.backend.self_link
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_global_forwarding_rule" "forwarding" {
|
|
|
|
name = local.name
|
|
|
|
ip_address = var.ip_address
|
|
|
|
ip_protocol = "TCP"
|
|
|
|
load_balancing_scheme = "EXTERNAL"
|
|
|
|
port_range = var.port
|
|
|
|
target = google_compute_target_tcp_proxy.proxy.self_link
|
|
|
|
labels = var.frontend_labels
|
|
|
|
}
|