Remove incompatible balancing_mode (#1769)
## net-lb-int * Fix error on apply of example: ``` Error creating RegionBackendService: googleapi: Error 400: Invalid value for field 'resource.backends[0].balancingMode': 'UTILIZATION'. Balancing mode must be CONNECTION for an INTERNAL backend service., invalid ``` * remove unused `balancing_mode` variable, as only one value is possible anyhow ## net-lb-ext * update in the `backends` description ## net-lb-proxy-int * update in the `backends` description ## net-lb-app-int * added validation of `balancing_mode` * fixed other validations ## net-lb-app-ext * added validation of `balancing_mode` * fixed other validations * removed validation for `locality_lb_policy` as this variable is not used in this module Closes: #1767
This commit is contained in:
parent
6c48512f7e
commit
c21fa4558f
|
@ -128,23 +128,24 @@ variable "backend_service_configs" {
|
|||
default = {}
|
||||
nullable = false
|
||||
validation {
|
||||
condition = contains(
|
||||
[
|
||||
"-", "ROUND_ROBIN", "LEAST_REQUEST", "RING_HASH",
|
||||
"RANDOM", "ORIGINAL_DESTINATION", "MAGLEV"
|
||||
],
|
||||
try(var.backend_service_configs.locality_lb_policy, "-")
|
||||
)
|
||||
error_message = "Invalid locality lb policy value."
|
||||
}
|
||||
validation {
|
||||
condition = contains(
|
||||
[
|
||||
"NONE", "CLIENT_IP", "CLIENT_IP_NO_DESTINATION",
|
||||
"CLIENT_IP_PORT_PROTO", "CLIENT_IP_PROTO"
|
||||
],
|
||||
try(var.backend_service_configs.session_affinity, "NONE")
|
||||
)
|
||||
condition = alltrue([
|
||||
for backend_service in values(var.backend_service_configs) : contains(
|
||||
[
|
||||
"NONE", "CLIENT_IP", "CLIENT_IP_NO_DESTINATION",
|
||||
"CLIENT_IP_PORT_PROTO", "CLIENT_IP_PROTO"
|
||||
],
|
||||
coalesce(backend_service.session_affinity, "NONE")
|
||||
)
|
||||
])
|
||||
error_message = "Invalid session affinity value."
|
||||
}
|
||||
validation {
|
||||
condition = alltrue(flatten([
|
||||
for backend_service in values(var.backend_service_configs) : [
|
||||
for backend in backend_service.backends : contains(
|
||||
["RATE", "UTILIZATION"], coalesce(backend.balancing_mode, "UTILIZATION")
|
||||
)]
|
||||
]))
|
||||
error_message = "When specified, balancing mode needs to be 'RATE' or 'UTILIZATION'."
|
||||
}
|
||||
}
|
||||
|
|
|
@ -109,23 +109,36 @@ variable "backend_service_configs" {
|
|||
default = {}
|
||||
nullable = false
|
||||
validation {
|
||||
condition = contains(
|
||||
[
|
||||
"-", "ROUND_ROBIN", "LEAST_REQUEST", "RING_HASH",
|
||||
"RANDOM", "ORIGINAL_DESTINATION", "MAGLEV"
|
||||
],
|
||||
try(var.backend_service_configs.locality_lb_policy, "-")
|
||||
)
|
||||
condition = alltrue([
|
||||
for backend_service in values(var.backend_service_configs) : contains(
|
||||
[
|
||||
"-", "ROUND_ROBIN", "LEAST_REQUEST", "RING_HASH",
|
||||
"RANDOM", "ORIGINAL_DESTINATION", "MAGLEV"
|
||||
],
|
||||
coalesce(backend_service.locality_lb_policy, "-")
|
||||
)
|
||||
])
|
||||
error_message = "Invalid locality lb policy value."
|
||||
}
|
||||
validation {
|
||||
condition = contains(
|
||||
[
|
||||
"NONE", "CLIENT_IP", "CLIENT_IP_NO_DESTINATION",
|
||||
"CLIENT_IP_PORT_PROTO", "CLIENT_IP_PROTO"
|
||||
],
|
||||
try(var.backend_service_configs.session_affinity, "NONE")
|
||||
)
|
||||
condition = alltrue([
|
||||
for backend_service in values(var.backend_service_configs) : contains(
|
||||
[
|
||||
"NONE", "CLIENT_IP", "CLIENT_IP_NO_DESTINATION",
|
||||
"CLIENT_IP_PORT_PROTO", "CLIENT_IP_PROTO"
|
||||
],
|
||||
coalesce(backend_service.session_affinity, "NONE")
|
||||
)
|
||||
])
|
||||
error_message = "Invalid session affinity value."
|
||||
}
|
||||
validation {
|
||||
condition = alltrue(flatten([
|
||||
for backend_service in values(var.backend_service_configs) : [
|
||||
for backend in backend_service.backends : contains(
|
||||
["RATE", "UTILIZATION"], coalesce(backend.balancing_mode, "UTILIZATION")
|
||||
)]
|
||||
]))
|
||||
error_message = "When specified, balancing mode needs to be 'RATE' or 'UTILIZATION'."
|
||||
}
|
||||
}
|
||||
|
|
|
@ -160,7 +160,7 @@ module "nlb" {
|
|||
| [region](variables.tf#L216) | GCP region. | <code>string</code> | ✓ | |
|
||||
| [address](variables.tf#L17) | Optional IP address used for the forwarding rule. | <code>string</code> | | <code>null</code> |
|
||||
| [backend_service_config](variables.tf#L23) | 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) })) failover_config = optional(object({ disable_conn_drain = optional(bool) drop_traffic_if_unhealthy = optional(bool) ratio = optional(number) })) locality_lb_policy = optional(string) log_sample_rate = optional(number) port_name = optional(string) protocol = optional(string, "UNSPECIFIED") session_affinity = optional(string) timeout_sec = optional(number) })">object({…})</code> | | <code>{}</code> |
|
||||
| [backends](variables.tf#L72) | Load balancer backends, balancing mode is one of 'CONNECTION' or 'UTILIZATION'. | <code title="list(object({ group = string description = optional(string, "Terraform managed.") failover = optional(bool, false) }))">list(object({…}))</code> | | <code>[]</code> |
|
||||
| [backends](variables.tf#L72) | Load balancer backends. | <code title="list(object({ group = string description = optional(string, "Terraform managed.") failover = optional(bool, false) }))">list(object({…}))</code> | | <code>[]</code> |
|
||||
| [description](variables.tf#L83) | Optional description used for resources. | <code>string</code> | | <code>"Terraform managed."</code> |
|
||||
| [group_configs](variables.tf#L89) | Optional unmanaged groups to create. Can be referenced in backends via outputs. | <code title="map(object({ zone = string instances = optional(list(string)) named_ports = optional(map(number), {}) }))">map(object({…}))</code> | | <code>{}</code> |
|
||||
| [health_check](variables.tf#L100) | Name of existing health check to use, disables auto-created health check. | <code>string</code> | | <code>null</code> |
|
||||
|
|
|
@ -70,7 +70,7 @@ variable "backend_service_config" {
|
|||
}
|
||||
|
||||
variable "backends" {
|
||||
description = "Load balancer backends, balancing mode is one of 'CONNECTION' or 'UTILIZATION'."
|
||||
description = "Load balancer backends."
|
||||
type = list(object({
|
||||
group = string
|
||||
description = optional(string, "Terraform managed.")
|
||||
|
|
|
@ -287,8 +287,7 @@ module "ilb" {
|
|||
}
|
||||
backends = [
|
||||
for z, mod in module.instance-group : {
|
||||
group = mod.group.self_link
|
||||
balancing_mode = "UTILIZATION"
|
||||
group = mod.group.self_link
|
||||
}
|
||||
]
|
||||
health_check_config = {
|
||||
|
@ -304,20 +303,20 @@ module "ilb" {
|
|||
|
||||
| name | description | type | required | default |
|
||||
|---|---|:---:|:---:|:---:|
|
||||
| [name](variables.tf#L192) | Name used for all resources. | <code>string</code> | ✓ | |
|
||||
| [project_id](variables.tf#L197) | Project id where resources will be created. | <code>string</code> | ✓ | |
|
||||
| [region](variables.tf#L208) | GCP region. | <code>string</code> | ✓ | |
|
||||
| [vpc_config](variables.tf#L219) | VPC-level configuration. | <code title="object({ network = string subnetwork = string })">object({…})</code> | ✓ | |
|
||||
| [name](variables.tf#L184) | Name used for all resources. | <code>string</code> | ✓ | |
|
||||
| [project_id](variables.tf#L189) | Project id where resources will be created. | <code>string</code> | ✓ | |
|
||||
| [region](variables.tf#L200) | GCP region. | <code>string</code> | ✓ | |
|
||||
| [vpc_config](variables.tf#L211) | 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) protocol = optional(string, "UNSPECIFIED") session_affinity = optional(string) timeout_sec = optional(number) })">object({…})</code> | | <code>{}</code> |
|
||||
| [backends](variables.tf#L51) | Load balancer backends, balancing mode is one of 'CONNECTION' or 'UTILIZATION'. | <code title="list(object({ group = string balancing_mode = optional(string, "CONNECTION") description = optional(string, "Terraform managed.") failover = optional(bool, false) }))">list(object({…}))</code> | | <code>[]</code> |
|
||||
| [description](variables.tf#L70) | Optional description used for resources. | <code>string</code> | | <code>"Terraform managed."</code> |
|
||||
| [forwarding_rules_config](variables.tf#L76) | The optional forwarding rules configuration. | <code title="map(object({ address = optional(string) description = optional(string) global_access = optional(bool, true) ip_version = optional(string) ports = optional(list(string), null) protocol = optional(string, "TCP") }))">map(object({…}))</code> | | <code title="{ "" = {} }">{…}</code> |
|
||||
| [group_configs](variables.tf#L91) | Optional unmanaged groups to create. Can be referenced in backends via outputs. | <code title="map(object({ zone = string description = optional(string, "Terraform managed.") instances = optional(list(string)) named_ports = optional(map(number), {}) }))">map(object({…}))</code> | | <code>{}</code> |
|
||||
| [health_check](variables.tf#L103) | Name of existing health check to use, disables auto-created health check. | <code>string</code> | | <code>null</code> |
|
||||
| [health_check_config](variables.tf#L109) | 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) 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#L186) | Labels set on resources. | <code>map(string)</code> | | <code>{}</code> |
|
||||
| [protocol](variables.tf#L202) | Forwarding rule protocol used, defaults to TCP. | <code>string</code> | | <code>"TCP"</code> |
|
||||
| [service_label](variables.tf#L213) | Optional prefix of the fully qualified forwarding rule name. | <code>string</code> | | <code>null</code> |
|
||||
| [backends](variables.tf#L51) | Load balancer backends. | <code title="list(object({ group = string description = optional(string, "Terraform managed.") failover = optional(bool, false) }))">list(object({…}))</code> | | <code>[]</code> |
|
||||
| [description](variables.tf#L62) | Optional description used for resources. | <code>string</code> | | <code>"Terraform managed."</code> |
|
||||
| [forwarding_rules_config](variables.tf#L68) | The optional forwarding rules configuration. | <code title="map(object({ address = optional(string) description = optional(string) global_access = optional(bool, true) ip_version = optional(string) ports = optional(list(string), null) protocol = optional(string, "TCP") }))">map(object({…}))</code> | | <code title="{ "" = {} }">{…}</code> |
|
||||
| [group_configs](variables.tf#L83) | Optional unmanaged groups to create. Can be referenced in backends via outputs. | <code title="map(object({ zone = string description = optional(string, "Terraform managed.") instances = optional(list(string)) named_ports = optional(map(number), {}) }))">map(object({…}))</code> | | <code>{}</code> |
|
||||
| [health_check](variables.tf#L95) | Name of existing health check to use, disables auto-created health check. | <code>string</code> | | <code>null</code> |
|
||||
| [health_check_config](variables.tf#L101) | 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) 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#L178) | Labels set on resources. | <code>map(string)</code> | | <code>{}</code> |
|
||||
| [protocol](variables.tf#L194) | Forwarding rule protocol used, defaults to TCP. | <code>string</code> | | <code>"TCP"</code> |
|
||||
| [service_label](variables.tf#L205) | Optional prefix of the fully qualified forwarding rule name. | <code>string</code> | | <code>null</code> |
|
||||
|
||||
## Outputs
|
||||
|
||||
|
|
|
@ -68,7 +68,7 @@ resource "google_compute_region_backend_service" "default" {
|
|||
dynamic "backend" {
|
||||
for_each = { for b in var.backends : b.group => b }
|
||||
content {
|
||||
balancing_mode = backend.value.balancing_mode
|
||||
balancing_mode = "CONNECTION"
|
||||
description = backend.value.description
|
||||
failover = backend.value.failover
|
||||
group = backend.key
|
||||
|
|
|
@ -49,22 +49,14 @@ variable "backend_service_config" {
|
|||
}
|
||||
|
||||
variable "backends" {
|
||||
description = "Load balancer backends, balancing mode is one of 'CONNECTION' or 'UTILIZATION'."
|
||||
description = "Load balancer backends."
|
||||
type = list(object({
|
||||
group = string
|
||||
balancing_mode = optional(string, "CONNECTION")
|
||||
description = optional(string, "Terraform managed.")
|
||||
failover = optional(bool, false)
|
||||
group = string
|
||||
description = optional(string, "Terraform managed.")
|
||||
failover = optional(bool, false)
|
||||
}))
|
||||
default = []
|
||||
nullable = false
|
||||
validation {
|
||||
condition = alltrue([
|
||||
for b in var.backends : contains(
|
||||
["CONNECTION", "UTILIZATION"], coalesce(b.balancing_mode, "CONNECTION")
|
||||
)])
|
||||
error_message = "When specified balancing mode needs to be 'CONNECTION' or 'UTILIZATION'."
|
||||
}
|
||||
}
|
||||
|
||||
variable "description" {
|
||||
|
|
|
@ -68,7 +68,7 @@ variable "backend_service_config" {
|
|||
for b in var.backend_service_config.backends : contains(
|
||||
["CONNECTION", "UTILIZATION"], coalesce(b.balancing_mode, "CONNECTION")
|
||||
)])
|
||||
error_message = "When specified balancing mode needs to be 'CONNECTION' or 'UTILIZATION'."
|
||||
error_message = "When specified, balancing mode needs to be 'CONNECTION' or 'UTILIZATION'."
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@ vpc_config = {
|
|||
subnetwork = "default"
|
||||
}
|
||||
backends = [{
|
||||
balancing_mode = "CONNECTION"
|
||||
group = "foo"
|
||||
failover = false
|
||||
group = "foo"
|
||||
failover = false
|
||||
}]
|
||||
|
|
|
@ -6,9 +6,8 @@ vpc_config = {
|
|||
subnetwork = "default"
|
||||
}
|
||||
backends = [{
|
||||
balancing_mode = "CONNECTION"
|
||||
group = "foo"
|
||||
failover = false
|
||||
group = "foo"
|
||||
failover = false
|
||||
}]
|
||||
global_access = true
|
||||
|
||||
|
|
Loading…
Reference in New Issue