Added backend preference to global application load balancers (#3139)

This commit is contained in:
apichick
2025-06-10 08:49:47 +02:00
committed by GitHub
parent df0ed1a73c
commit 12b206a72f
3 changed files with 12 additions and 1 deletions

File diff suppressed because one or more lines are too long

View File

@@ -78,6 +78,7 @@ resource "google_compute_backend_service" "default" {
for_each = { for b in coalesce(each.value.backends, []) : b.backend => b }
content {
group = lookup(local.group_ids, backend.key, backend.key)
preference = backend.value.preference
balancing_mode = backend.value.balancing_mode # UTILIZATION, RATE
capacity_scaler = backend.value.capacity_scaler
description = backend.value.description

View File

@@ -37,6 +37,7 @@ variable "backend_service_configs" {
backends = list(object({
# group renamed to backend
backend = string
preference = optional(string, "DEFAULT")
balancing_mode = optional(string, "UTILIZATION")
capacity_scaler = optional(number, 1)
description = optional(string, "Terraform managed.")
@@ -163,6 +164,15 @@ variable "backend_service_configs" {
]))
error_message = "When specified, balancing mode needs to be 'RATE' or 'UTILIZATION'."
}
validation {
condition = alltrue(flatten([
for backend_service in values(var.backend_service_configs) : [
for backend in backend_service.backends : contains(
["DEFAULT", "PREFERRED"], coalesce(backend.preference, "DEFAULT")
)]
]))
error_message = "When specified, balancing mode needs to be 'DEFAULT' or 'PREFERRED'."
}
validation {
condition = alltrue([
for backend_service in values(var.backend_service_configs) :