diff --git a/modules/alb-instance-target-group/README.md b/modules/alb-instance-target-group/README.md index 87fd15c..86e2ac4 100644 --- a/modules/alb-instance-target-group/README.md +++ b/modules/alb-instance-target-group/README.md @@ -40,10 +40,9 @@ This module creates following resources. | [port](#input\_port) | (Required) The number of port on which targets receive traffic, unless overridden when registering a specific target. Valid values are either ports 1-65535. | `number` | n/a | yes | | [protocol](#input\_protocol) | (Required) The protocol to use for routing traffic to the targets. Valid values are `HTTP` and `HTTPS`. Defaults to `HTTP`. | `string` | n/a | yes | | [vpc\_id](#input\_vpc\_id) | (Required) The ID of the VPC which the target group belongs to. | `string` | n/a | yes | -| [anomaly\_mitigation\_enabled](#input\_anomaly\_mitigation\_enabled) | (Optional) Whether to enable target anomaly mitigation. When a target is determined to be anomalous, traffic is automatically routed away so the target has an opportunity to recover. Target anomaly mitigation is only supported by the `WEIGHTED_RANDOM` load balancing algorithm type. Not compatible with the `slow_start_duration` attribute. Defaults to `false`. | `bool` | `false` | no | | [deregistration\_delay](#input\_deregistration\_delay) | (Optional) The time to wait for in-flight requests to complete while deregistering a target. During this time, the state of the target is draining. | `number` | `300` | no | | [health\_check](#input\_health\_check) | (Optional) Health Check configuration block. The associated load balancer periodically sends requests to the registered targets to test their status. `health_check` block as defined below.
(Optional) `protocol` - Protocol to use to connect with the target. The possible values are `HTTP` and `HTTPS`. Defaults to `HTTP`.
(Optional) `port` - The port the load balancer uses when performing health checks on targets. The default is the port on which each target receives traffic from the load balancer. Valid values are either ports 1-65535.
(Optional) `port_override` - Whether to override the port on which each target receives trafficfrom the load balancer to a different port. Defaults to `false`.
(Optional) `path` - Use the default path of `/` to ping the root, or specify a custom path if preferred.
(Optional) `success_codes` - The HTTP codes to use when checking for a successful response from a target. You can specify multiple values (for example, `200,202`) or a range of values (for example, `200-299`).
(Optional) `healthy_threshold` - The number of consecutive health checks successes required before considering an unhealthy target healthy. Valid value range is 2 - 10. Defaults to `5`.
(Optional) `unhealthy_threshold` - The number of consecutive health check failures required before considering a target unhealthy. Valid value range is 2 - 10. Defaults to `2`.
(Optional) `interval` - Approximate amount of time, in seconds, between health checks of an individual target. Valid value range is 5 - 300. Defaults to `30`.
(Optional) `timeout` - The amount of time, in seconds, during which no response means a failed health check. Valid value range is 2 - 120. Defaults to `5`. |
object({
protocol = optional(string, "HTTP")
port = optional(number, null)
port_override = optional(bool, false)
path = optional(string, null)
success_codes = optional(string, null)

healthy_threshold = optional(number, 5)
unhealthy_threshold = optional(number, 2)
interval = optional(number, 30)
timeout = optional(number, 5)
})
| `{}` | no | -| [load\_balancing\_algorithm](#input\_load\_balancing\_algorithm) | (Optional) Determines how the load balancer selects targets when routing requests. Valid values are `ROUND_ROBIN`, `LEAST_OUTSTANDING_REQUESTS` or `WEIGHTED_RANDOM`. Defaults to `ROUND_ROBIN`. | `string` | `"ROUND_ROBIN"` | no | +| [load\_balancing](#input\_load\_balancing) | (Optional) A load balancing configuration of the target group. `load_balancing` block as defined below.
(Optional) `algorithm` - Determines how the load balancer selects targets when routing requests. Valid values are `ROUND_ROBIN`, `LEAST_OUTSTANDING_REQUESTS` or `WEIGHTED_RANDOM`. Defaults to `ROUND_ROBIN`.
(Optional) `anomaly_mitigation_enabled` - Whether to enable target anomaly mitigation. When a target is determined to be anomalous, traffic is automatically routed away so the target has an opportunity to recover. Target anomaly mitigation is only supported by the `WEIGHTED_RANDOM` load balancing algorithm type. Not compatible with the `slow_start_duration` attribute. Defaults to `false`.
(Optional) `cross_zone_strategy` - Determines how the load balancer routes requests across the Availability Zones. Valid values are `ENABLED`, `DISABLED` or `INHERIT`. Defaults to `INHERIT` (Use load balancer configuration). |
object({
algorithm = optional(string, "ROUND_ROBIN")
anomaly_mitigation_enabled = optional(bool, false)
cross_zone_strategy = optional(string, "INHERIT")
})
| `{}` | no | | [module\_tags\_enabled](#input\_module\_tags\_enabled) | (Optional) Whether to create AWS Resource Tags for the module informations. | `bool` | `true` | no | | [protocol\_version](#input\_protocol\_version) | (Optional) Use `HTTP1` to send requests to targets using HTTP/1.1. Supported when the request protocol is HTTP/1.1 or HTTP/2. Use `HTTP2` to send requests to targets using HTTP/2. Supported when the request protocol is HTTP/2 or gRPC, but gRPC-specific features are not available. Use `GRPC` to send requests to targets using gRPC. Supported when the request protocol is gRPC. Defaults to `HTTP1`. | `string` | `"HTTP1"` | no | | [resource\_group\_description](#input\_resource\_group\_description) | (Optional) The description of Resource Group. | `string` | `"Managed by Terraform."` | no | diff --git a/modules/alb-instance-target-group/main.tf b/modules/alb-instance-target-group/main.tf index 47f73b0..84954d4 100644 --- a/modules/alb-instance-target-group/main.tf +++ b/modules/alb-instance-target-group/main.tf @@ -14,6 +14,18 @@ locals { } : {} } +locals { + cross_zone_strategy = { + "ENABLED" = "true" + "DISABLED" = "false" + "INHERIT" = "use_load_balancer_configuration" + } +} + + +################################################### +# ALB Instance Target Group +################################################### # INFO: Not supported attributes # - `connection_termination` @@ -33,12 +45,13 @@ resource "aws_lb_target_group" "this" { ## Attributes deregistration_delay = var.deregistration_delay - load_balancing_algorithm_type = lower(var.load_balancing_algorithm) - load_balancing_anomaly_mitigation = (var.load_balancing_algorithm == "WEIGHTED_RANDOM" - ? var.anomaly_mitigation_enabled ? "on" : "off" + load_balancing_algorithm_type = lower(var.load_balancing.algorithm) + load_balancing_anomaly_mitigation = (var.load_balancing.algorithm == "WEIGHTED_RANDOM" + ? var.load_balancing.anomaly_mitigation_enabled ? "on" : "off" : null ) - slow_start = var.slow_start_duration + load_balancing_cross_zone_enabled = local.cross_zone_strategy[var.load_balancing.cross_zone_strategy] + slow_start = var.slow_start_duration stickiness { enabled = var.stickiness_enabled diff --git a/modules/alb-instance-target-group/outputs.tf b/modules/alb-instance-target-group/outputs.tf index ecf4b58..7c30a6c 100644 --- a/modules/alb-instance-target-group/outputs.tf +++ b/modules/alb-instance-target-group/outputs.tf @@ -61,13 +61,16 @@ output "targets" { output "attributes" { description = "Attributes of the Instance target group of network load balancer." value = { - anomaly_mitigation_enabled = (var.load_balancing_algorithm == "WEIGHTED_RANDOM" - ? var.anomaly_mitigation_enabled - : null - ) - deregistration_delay = aws_lb_target_group.this.deregistration_delay - load_balancing_algorithm = upper(aws_lb_target_group.this.load_balancing_algorithm_type) - slow_start_duration = aws_lb_target_group.this.slow_start + deregistration_delay = aws_lb_target_group.this.deregistration_delay + load_balancing = { + algorithm = upper(aws_lb_target_group.this.load_balancing_algorithm_type) + anomaly_mitigation_enabled = (var.load_balancing.algorithm == "WEIGHTED_RANDOM" + ? var.load_balancing.anomaly_mitigation_enabled + : null + ) + cross_zone_strategy = var.load_balancing.cross_zone_strategy + } + slow_start_duration = aws_lb_target_group.this.slow_start stickiness = { enabled = aws_lb_target_group.this.stickiness[0].enabled type = upper(aws_lb_target_group.this.stickiness[0].type) diff --git a/modules/alb-instance-target-group/variables.tf b/modules/alb-instance-target-group/variables.tf index cee5f5a..c4a3bbc 100644 --- a/modules/alb-instance-target-group/variables.tf +++ b/modules/alb-instance-target-group/variables.tf @@ -77,23 +77,30 @@ variable "deregistration_delay" { } } -variable "load_balancing_algorithm" { - description = "(Optional) Determines how the load balancer selects targets when routing requests. Valid values are `ROUND_ROBIN`, `LEAST_OUTSTANDING_REQUESTS` or `WEIGHTED_RANDOM`. Defaults to `ROUND_ROBIN`." - type = string - default = "ROUND_ROBIN" - nullable = false +variable "load_balancing" { + description = < [port](#input\_port) | (Required) The number of port on which targets receive traffic, unless overridden when registering a specific target. Valid values are either ports 1-65535. | `number` | n/a | yes | | [protocol](#input\_protocol) | (Required) The protocol to use for routing traffic to the targets. Valid values are `HTTP` and `HTTPS`. Defaults to `HTTP`. | `string` | n/a | yes | | [vpc\_id](#input\_vpc\_id) | (Required) The ID of the VPC which the target group belongs to. | `string` | n/a | yes | -| [anomaly\_mitigation\_enabled](#input\_anomaly\_mitigation\_enabled) | (Optional) Whether to enable target anomaly mitigation. When a target is determined to be anomalous, traffic is automatically routed away so the target has an opportunity to recover. Target anomaly mitigation is only supported by the `WEIGHTED_RANDOM` load balancing algorithm type. Not compatible with the `slow_start_duration` attribute. Defaults to `false`. | `bool` | `false` | no | | [deregistration\_delay](#input\_deregistration\_delay) | (Optional) The time to wait for in-flight requests to complete while deregistering a target. During this time, the state of the target is draining. | `number` | `300` | no | | [health\_check](#input\_health\_check) | (Optional) Health Check configuration block. The associated load balancer periodically sends requests to the registered targets to test their status. `health_check` block as defined below.
(Optional) `protocol` - Protocol to use to connect with the target. The possible values are `HTTP` and `HTTPS`. Defaults to `HTTP`.
(Optional) `port` - The port the load balancer uses when performing health checks on targets. The default is the port on which each target receives traffic from the load balancer. Valid values are either ports 1-65535.
(Optional) `port_override` - Whether to override the port on which each target receives trafficfrom the load balancer to a different port. Defaults to `false`.
(Optional) `path` - Use the default path of `/` to ping the root, or specify a custom path if preferred.
(Optional) `success_codes` - The HTTP codes to use when checking for a successful response from a target. You can specify multiple values (for example, `200,202`) or a range of values (for example, `200-299`).
(Optional) `healthy_threshold` - The number of consecutive health checks successes required before considering an unhealthy target healthy. Valid value range is 2 - 10. Defaults to `5`.
(Optional) `unhealthy_threshold` - The number of consecutive health check failures required before considering a target unhealthy. Valid value range is 2 - 10. Defaults to `2`.
(Optional) `interval` - Approximate amount of time, in seconds, between health checks of an individual target. Valid value range is 5 - 300. Defaults to `30`.
(Optional) `timeout` - The amount of time, in seconds, during which no response means a failed health check. Valid value range is 2 - 120. Defaults to `5`. |
object({
protocol = optional(string, "HTTP")
port = optional(number, null)
port_override = optional(bool, false)
path = optional(string, null)
success_codes = optional(string, null)

healthy_threshold = optional(number, 5)
unhealthy_threshold = optional(number, 2)
interval = optional(number, 30)
timeout = optional(number, 5)
})
| `{}` | no | | [ip\_address\_type](#input\_ip\_address\_type) | (Required) The type of IP addresses used by the target group. Valid values are `IPV4` or `IPV6`. | `string` | `"IPV4"` | no | -| [load\_balancing\_algorithm](#input\_load\_balancing\_algorithm) | (Optional) Determines how the load balancer selects targets when routing requests. Valid values are `ROUND_ROBIN`, `LEAST_OUTSTANDING_REQUESTS` or `WEIGHTED_RANDOM`. Defaults to `ROUND_ROBIN`. | `string` | `"ROUND_ROBIN"` | no | +| [load\_balancing](#input\_load\_balancing) | (Optional) A load balancing configuration of the target group. `load_balancing` block as defined below.
(Optional) `algorithm` - Determines how the load balancer selects targets when routing requests. Valid values are `ROUND_ROBIN`, `LEAST_OUTSTANDING_REQUESTS` or `WEIGHTED_RANDOM`. Defaults to `ROUND_ROBIN`.
(Optional) `anomaly_mitigation_enabled` - Whether to enable target anomaly mitigation. When a target is determined to be anomalous, traffic is automatically routed away so the target has an opportunity to recover. Target anomaly mitigation is only supported by the `WEIGHTED_RANDOM` load balancing algorithm type. Not compatible with the `slow_start_duration` attribute. Defaults to `false`.
(Optional) `cross_zone_strategy` - Determines how the load balancer routes requests across the Availability Zones. Valid values are `ENABLED`, `DISABLED` or `INHERIT`. Defaults to `INHERIT` (Use load balancer configuration). |
object({
algorithm = optional(string, "ROUND_ROBIN")
anomaly_mitigation_enabled = optional(bool, false)
cross_zone_strategy = optional(string, "INHERIT")
})
| `{}` | no | | [module\_tags\_enabled](#input\_module\_tags\_enabled) | (Optional) Whether to create AWS Resource Tags for the module informations. | `bool` | `true` | no | | [protocol\_version](#input\_protocol\_version) | (Optional) Use `HTTP1` to send requests to targets using HTTP/1.1. Supported when the request protocol is HTTP/1.1 or HTTP/2. Use `HTTP2` to send requests to targets using HTTP/2. Supported when the request protocol is HTTP/2 or gRPC, but gRPC-specific features are not available. Use `GRPC` to send requests to targets using gRPC. Supported when the request protocol is gRPC. Defaults to `HTTP1`. | `string` | `"HTTP1"` | no | | [resource\_group\_description](#input\_resource\_group\_description) | (Optional) The description of Resource Group. | `string` | `"Managed by Terraform."` | no | diff --git a/modules/alb-ip-target-group/main.tf b/modules/alb-ip-target-group/main.tf index 4cf2953..36980d7 100644 --- a/modules/alb-ip-target-group/main.tf +++ b/modules/alb-ip-target-group/main.tf @@ -19,6 +19,12 @@ data "aws_vpc" "this" { } locals { + cross_zone_strategy = { + "ENABLED" = "true" + "DISABLED" = "false" + "INHERIT" = "use_load_balancer_configuration" + } + ipv4_regex = "^(\\d+).(\\d+).(\\d+).(\\d+)$" ipv4_vpc_cidrs = data.aws_vpc.this.cidr_block_associations[*].cidr_block @@ -36,6 +42,11 @@ locals { ] } + +################################################### +# ALB IP Target Group +################################################### + # INFO: Not supported attributes # - `connection_termination` # - `lambda_multi_value_headers_enabled` @@ -54,12 +65,13 @@ resource "aws_lb_target_group" "this" { ## Attributes deregistration_delay = var.deregistration_delay - load_balancing_algorithm_type = lower(var.load_balancing_algorithm) - load_balancing_anomaly_mitigation = (var.load_balancing_algorithm == "WEIGHTED_RANDOM" - ? var.anomaly_mitigation_enabled ? "on" : "off" + load_balancing_algorithm_type = lower(var.load_balancing.algorithm) + load_balancing_anomaly_mitigation = (var.load_balancing.algorithm == "WEIGHTED_RANDOM" + ? var.load_balancing.anomaly_mitigation_enabled ? "on" : "off" : null ) - slow_start = var.slow_start_duration + load_balancing_cross_zone_enabled = local.cross_zone_strategy[var.load_balancing.cross_zone_strategy] + slow_start = var.slow_start_duration stickiness { enabled = var.stickiness_enabled diff --git a/modules/alb-ip-target-group/outputs.tf b/modules/alb-ip-target-group/outputs.tf index 5babe2d..52a69b4 100644 --- a/modules/alb-ip-target-group/outputs.tf +++ b/modules/alb-ip-target-group/outputs.tf @@ -67,13 +67,16 @@ output "targets" { output "attributes" { description = "Attributes of the Instance target group of network load balancer." value = { - anomaly_mitigation_enabled = (var.load_balancing_algorithm == "WEIGHTED_RANDOM" - ? var.anomaly_mitigation_enabled - : null - ) - deregistration_delay = aws_lb_target_group.this.deregistration_delay - load_balancing_algorithm = upper(aws_lb_target_group.this.load_balancing_algorithm_type) - slow_start_duration = aws_lb_target_group.this.slow_start + deregistration_delay = aws_lb_target_group.this.deregistration_delay + load_balancing = { + algorithm = upper(aws_lb_target_group.this.load_balancing_algorithm_type) + anomaly_mitigation_enabled = (var.load_balancing.algorithm == "WEIGHTED_RANDOM" + ? var.load_balancing.anomaly_mitigation_enabled + : null + ) + cross_zone_strategy = var.load_balancing.cross_zone_strategy + } + slow_start_duration = aws_lb_target_group.this.slow_start stickiness = { enabled = aws_lb_target_group.this.stickiness[0].enabled type = upper(aws_lb_target_group.this.stickiness[0].type) diff --git a/modules/alb-ip-target-group/variables.tf b/modules/alb-ip-target-group/variables.tf index dd04087..8b44e8f 100644 --- a/modules/alb-ip-target-group/variables.tf +++ b/modules/alb-ip-target-group/variables.tf @@ -89,23 +89,30 @@ variable "deregistration_delay" { } } -variable "load_balancing_algorithm" { - description = "(Optional) Determines how the load balancer selects targets when routing requests. Valid values are `ROUND_ROBIN`, `LEAST_OUTSTANDING_REQUESTS` or `WEIGHTED_RANDOM`. Defaults to `ROUND_ROBIN`." - type = string - default = "ROUND_ROBIN" - nullable = false +variable "load_balancing" { + description = < [vpc\_id](#input\_vpc\_id) | (Required) The ID of the VPC which the target group belongs to. | `string` | n/a | yes | | [deregistration\_delay](#input\_deregistration\_delay) | (Optional) The time to wait for in-flight requests to complete while deregistering a target. During this time, the state of the target is draining. | `number` | `300` | no | | [health\_check](#input\_health\_check) | (Optional) Health Check configuration block. The associated load balancer periodically sends requests to the registered targets to test their status. `health_check` block as defined below.
(Optional) `protocol` - Protocol to use to connect with the target. The possible values are `TCP`, `HTTP` and `HTTPS`. Defaults to `TCP`.
(Optional) `port` - The port the load balancer uses when performing health checks on targets. The default is the port on which each target receives traffic from the load balancer. Valid values are either ports 1-65535.
(Optional) `port_override` - Whether to override the port on which each target receives trafficfrom the load balancer to a different port. Defaults to `false`.
(Optional) `path` - Use the default path of `/` to ping the root, or specify a custom path if preferred. Only valid if the `protocol` is `HTTP` or `HTTPS`.
(Optional) `healthy_threshold` - The number of consecutive health checks successes required before considering an unhealthy target healthy. Valid value range is 2 - 10. Defaults to `3`.
(Optional) `unhealthy_threshold` - The number of consecutive health check failures required before considering a target unhealthy. Valid value range is 2 - 10. Defaults to `3`.
(Optional) `interval` - Approximate amount of time, in seconds, between health checks of an individual target. Valid value range is 5 - 300. Defaults to `10`.
(Optional) `timeout` - The amount of time, in seconds, during which no response means a failed health check. Valid value range is 2 - 120. Defaults to `6` when the `protocol` is `HTTP`, and `10` when the `protocol` is `TCP` or `HTTPS`. |
object({
protocol = optional(string, "TCP")
port = optional(number, null)
port_override = optional(bool, false)
path = optional(string, "/")

healthy_threshold = optional(number, 3)
unhealthy_threshold = optional(number, 3)
interval = optional(number, 10)
})
| `{}` | no | +| [load\_balancing](#input\_load\_balancing) | (Optional) A load balancing configuration of the target group. `load_balancing` block as defined below.
(Optional) `cross_zone_strategy` - Determines how the load balancer routes requests across the Availability Zones. Valid values are `ENABLED`, `DISABLED` or `INHERIT`. Defaults to `INHERIT` (Use load balancer configuration). |
object({
cross_zone_strategy = optional(string, "INHERIT")
})
| `{}` | no | | [module\_tags\_enabled](#input\_module\_tags\_enabled) | (Optional) Whether to create AWS Resource Tags for the module informations. | `bool` | `true` | no | | [preserve\_client\_ip](#input\_preserve\_client\_ip) | (Optional) Whether to preserve client IP addresses and ports in the packets forwarded to targets. Client IP preservation cannot be disabled if the target group protocol is `UDP` and `TCP_UDP`. Defaults to `true`. | `bool` | `true` | no | | [proxy\_protocol\_v2](#input\_proxy\_protocol\_v2) | (Optional) Whether to enable support for proxy protocol v2 on Network Load Balancers. Before you enable proxy protocol v2, make sure that your application targets can process proxy protocol headers otherwise your application might break. Defaults to `false`. | `bool` | `false` | no | diff --git a/modules/nlb-instance-target-group/main.tf b/modules/nlb-instance-target-group/main.tf index 4ddb556..79de604 100644 --- a/modules/nlb-instance-target-group/main.tf +++ b/modules/nlb-instance-target-group/main.tf @@ -14,6 +14,18 @@ locals { } : {} } +locals { + cross_zone_strategy = { + "ENABLED" = "true" + "DISABLED" = "false" + "INHERIT" = "use_load_balancer_configuration" + } +} + + +################################################### +# NLB Instance Target Group +################################################### # INFO: Not supported attributes # - `ip_address_type` @@ -32,10 +44,11 @@ resource "aws_lb_target_group" "this" { protocol = var.protocol ## Attributes - connection_termination = var.terminate_connection_on_deregistration - deregistration_delay = var.deregistration_delay - preserve_client_ip = var.preserve_client_ip - proxy_protocol_v2 = var.proxy_protocol_v2 + connection_termination = var.terminate_connection_on_deregistration + deregistration_delay = var.deregistration_delay + load_balancing_cross_zone_enabled = local.cross_zone_strategy[var.load_balancing.cross_zone_strategy] + preserve_client_ip = var.preserve_client_ip + proxy_protocol_v2 = var.proxy_protocol_v2 ## INFO: Not supported attributes # - `cookie_duration` diff --git a/modules/nlb-instance-target-group/outputs.tf b/modules/nlb-instance-target-group/outputs.tf index 7603661..b477b3d 100644 --- a/modules/nlb-instance-target-group/outputs.tf +++ b/modules/nlb-instance-target-group/outputs.tf @@ -58,8 +58,11 @@ output "attributes" { value = { terminate_connection_on_deregistration = aws_lb_target_group.this.connection_termination deregistration_delay = aws_lb_target_group.this.deregistration_delay - preserve_client_ip = aws_lb_target_group.this.preserve_client_ip - proxy_protocol_v2 = aws_lb_target_group.this.proxy_protocol_v2 + load_balancing = { + cross_zone_strategy = var.load_balancing.cross_zone_strategy + } + preserve_client_ip = aws_lb_target_group.this.preserve_client_ip + proxy_protocol_v2 = aws_lb_target_group.this.proxy_protocol_v2 stickiness = { enabled = aws_lb_target_group.this.stickiness[0].enabled type = upper(aws_lb_target_group.this.stickiness[0].type) diff --git a/modules/nlb-instance-target-group/variables.tf b/modules/nlb-instance-target-group/variables.tf index 765f5e8..165a2cf 100644 --- a/modules/nlb-instance-target-group/variables.tf +++ b/modules/nlb-instance-target-group/variables.tf @@ -72,6 +72,23 @@ variable "deregistration_delay" { } } +variable "load_balancing" { + description = < [deregistration\_delay](#input\_deregistration\_delay) | (Optional) The time to wait for in-flight requests to complete while deregistering a target. During this time, the state of the target is draining. | `number` | `300` | no | | [health\_check](#input\_health\_check) | (Optional) Health Check configuration block. The associated load balancer periodically sends requests to the registered targets to test their status. `health_check` block as defined below.
(Optional) `protocol` - Protocol to use to connect with the target. The possible values are `TCP`, `HTTP` and `HTTPS`. Defaults to `TCP`.
(Optional) `port` - The port the load balancer uses when performing health checks on targets. The default is the port on which each target receives traffic from the load balancer. Valid values are either ports 1-65535.
(Optional) `port_override` - Whether to override the port on which each target receives trafficfrom the load balancer to a different port. Defaults to `false`.
(Optional) `path` - Use the default path of `/` to ping the root, or specify a custom path if preferred. Only valid if the `protocol` is `HTTP` or `HTTPS`.
(Optional) `healthy_threshold` - The number of consecutive health checks successes required before considering an unhealthy target healthy. Valid value range is 2 - 10. Defaults to `3`.
(Optional) `unhealthy_threshold` - The number of consecutive health check failures required before considering a target unhealthy. Valid value range is 2 - 10. Defaults to `3`.
(Optional) `interval` - Approximate amount of time, in seconds, between health checks of an individual target. Valid value range is 5 - 300. Defaults to `10`. |
object({
protocol = optional(string, "TCP")
port = optional(number, null)
port_override = optional(bool, false)
path = optional(string, "/")

healthy_threshold = optional(number, 3)
unhealthy_threshold = optional(number, 3)
interval = optional(number, 10)
})
| `{}` | no | | [ip\_address\_type](#input\_ip\_address\_type) | (Required) The type of IP addresses used by the target group. Valid values are `IPV4` or `IPV6`. | `string` | `"IPV4"` | no | +| [load\_balancing](#input\_load\_balancing) | (Optional) A load balancing configuration of the target group. `load_balancing` block as defined below.
(Optional) `cross_zone_strategy` - Determines how the load balancer routes requests across the Availability Zones. Valid values are `ENABLED`, `DISABLED` or `INHERIT`. Defaults to `INHERIT` (Use load balancer configuration). |
object({
cross_zone_strategy = optional(string, "INHERIT")
})
| `{}` | no | | [module\_tags\_enabled](#input\_module\_tags\_enabled) | (Optional) Whether to create AWS Resource Tags for the module informations. | `bool` | `true` | no | | [preserve\_client\_ip](#input\_preserve\_client\_ip) | (Optional) Whether to preserve client IP addresses and ports in the packets forwarded to targets. Client IP preservation cannot be disabled if the target group protocol is `UDP` and `TCP_UDP`. Defaults to `true`. | `bool` | `true` | no | | [proxy\_protocol\_v2](#input\_proxy\_protocol\_v2) | (Optional) Whether to enable support for proxy protocol v2 on Network Load Balancers. Before you enable proxy protocol v2, make sure that your application targets can process proxy protocol headers otherwise your application might break. Defaults to `false`. | `bool` | `false` | no | diff --git a/modules/nlb-ip-target-group/main.tf b/modules/nlb-ip-target-group/main.tf index 10c743a..2ea6e61 100644 --- a/modules/nlb-ip-target-group/main.tf +++ b/modules/nlb-ip-target-group/main.tf @@ -19,6 +19,12 @@ data "aws_vpc" "this" { } locals { + cross_zone_strategy = { + "ENABLED" = "true" + "DISABLED" = "false" + "INHERIT" = "use_load_balancer_configuration" + } + ipv4_regex = "^(\\d+).(\\d+).(\\d+).(\\d+)$" ipv4_vpc_cidrs = data.aws_vpc.this.cidr_block_associations[*].cidr_block @@ -36,6 +42,11 @@ locals { ] } + +################################################### +# NLB IP Target Group +################################################### + # INFO: Not supported attributes # - `lambda_multi_value_headers_enabled` # - `load_balancing_algorithm_type` @@ -53,10 +64,11 @@ resource "aws_lb_target_group" "this" { protocol = var.protocol ## Attributes - connection_termination = var.terminate_connection_on_deregistration - deregistration_delay = var.deregistration_delay - preserve_client_ip = var.preserve_client_ip - proxy_protocol_v2 = var.proxy_protocol_v2 + connection_termination = var.terminate_connection_on_deregistration + deregistration_delay = var.deregistration_delay + load_balancing_cross_zone_enabled = local.cross_zone_strategy[var.load_balancing.cross_zone_strategy] + preserve_client_ip = var.preserve_client_ip + proxy_protocol_v2 = var.proxy_protocol_v2 ## INFO: Not supported attributes # - `cookie_duration` diff --git a/modules/nlb-ip-target-group/outputs.tf b/modules/nlb-ip-target-group/outputs.tf index 009d3aa..a13c860 100644 --- a/modules/nlb-ip-target-group/outputs.tf +++ b/modules/nlb-ip-target-group/outputs.tf @@ -64,8 +64,11 @@ output "attributes" { value = { terminate_connection_on_deregistration = aws_lb_target_group.this.connection_termination deregistration_delay = aws_lb_target_group.this.deregistration_delay - preserve_client_ip = aws_lb_target_group.this.preserve_client_ip - proxy_protocol_v2 = aws_lb_target_group.this.proxy_protocol_v2 + load_balancing = { + cross_zone_strategy = var.load_balancing.cross_zone_strategy + } + preserve_client_ip = aws_lb_target_group.this.preserve_client_ip + proxy_protocol_v2 = aws_lb_target_group.this.proxy_protocol_v2 stickiness = { enabled = aws_lb_target_group.this.stickiness[0].enabled type = upper(aws_lb_target_group.this.stickiness[0].type) diff --git a/modules/nlb-ip-target-group/variables.tf b/modules/nlb-ip-target-group/variables.tf index 81c028c..f8cde93 100644 --- a/modules/nlb-ip-target-group/variables.tf +++ b/modules/nlb-ip-target-group/variables.tf @@ -84,6 +84,23 @@ variable "deregistration_delay" { } } +variable "load_balancing" { + description = <