Skip to content

Commit c79324e

Browse files
authored
feat: Add support for disabling connection termination for unhealthy targets and AZ DNS affinity (#315)
Co-authored-by: magreenbaum <magreenbaum>
1 parent f3eca50 commit c79324e

File tree

10 files changed

+31
-11
lines changed

10 files changed

+31
-11
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,13 +348,13 @@ See [patterns.md](https://github.com/terraform-aws-modules/terraform-aws-alb/blo
348348
| Name | Version |
349349
|------|---------|
350350
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
351-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.13 |
351+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.23 |
352352

353353
## Providers
354354

355355
| Name | Version |
356356
|------|---------|
357-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.13 |
357+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.23 |
358358

359359
## Modules
360360

@@ -390,6 +390,7 @@ No modules.
390390
| <a name="input_default_port"></a> [default\_port](#input\_default\_port) | Default port used across the listener and target group | `number` | `80` | no |
391391
| <a name="input_default_protocol"></a> [default\_protocol](#input\_default\_protocol) | Default protocol used across the listener and target group | `string` | `"HTTP"` | no |
392392
| <a name="input_desync_mitigation_mode"></a> [desync\_mitigation\_mode](#input\_desync\_mitigation\_mode) | Determines how the load balancer handles requests that might pose a security risk to an application due to HTTP desync. Valid values are `monitor`, `defensive` (default), `strictest` | `string` | `null` | no |
393+
| <a name="input_dns_record_client_routing_policy"></a> [dns\_record\_client\_routing\_policy](#input\_dns\_record\_client\_routing\_policy) | Indicates how traffic is distributed among the load balancer Availability Zones. Possible values are any\_availability\_zone (default), availability\_zone\_affinity, or partial\_availability\_zone\_affinity. Only valid for network type load balancers. | `string` | `null` | no |
393394
| <a name="input_drop_invalid_header_fields"></a> [drop\_invalid\_header\_fields](#input\_drop\_invalid\_header\_fields) | Indicates whether HTTP headers with header fields that are not valid are removed by the load balancer (`true`) or routed to targets (`false`). The default is `true`. Elastic Load Balancing requires that message header names contain only alphanumeric characters and hyphens. Only valid for Load Balancers of type `application` | `bool` | `true` | no |
394395
| <a name="input_enable_cross_zone_load_balancing"></a> [enable\_cross\_zone\_load\_balancing](#input\_enable\_cross\_zone\_load\_balancing) | If `true`, cross-zone load balancing of the load balancer will be enabled. For application load balancer this feature is always enabled (`true`) and cannot be disabled. Defaults to `true` | `bool` | `true` | no |
395396
| <a name="input_enable_deletion_protection"></a> [enable\_deletion\_protection](#input\_enable\_deletion\_protection) | If `true`, deletion of the load balancer will be disabled via the AWS API. This will prevent Terraform from deleting the load balancer. Defaults to `true` | `bool` | `true` | no |

examples/complete-alb/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ Note that this example may create resources which cost money. Run `terraform des
2020
| Name | Version |
2121
|------|---------|
2222
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
23-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.13 |
23+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.23 |
2424
| <a name="requirement_null"></a> [null](#requirement\_null) | >= 2.0 |
2525

2626
## Providers
2727

2828
| Name | Version |
2929
|------|---------|
30-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.13 |
30+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.23 |
3131
| <a name="provider_null"></a> [null](#provider\_null) | >= 2.0 |
3232

3333
## Modules

examples/complete-alb/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 5.13"
7+
version = ">= 5.23"
88
}
99
null = {
1010
source = "hashicorp/null"

examples/complete-nlb/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ Note that this example may create resources which cost money. Run `terraform des
2020
| Name | Version |
2121
|------|---------|
2222
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
23-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.13 |
23+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.23 |
2424

2525
## Providers
2626

2727
| Name | Version |
2828
|------|---------|
29-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.13 |
29+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.23 |
3030

3131
## Modules
3232

examples/complete-nlb/main.tf

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ module "nlb" {
2727

2828
name = local.name
2929

30-
load_balancer_type = "network"
31-
vpc_id = module.vpc.vpc_id
30+
load_balancer_type = "network"
31+
vpc_id = module.vpc.vpc_id
32+
dns_record_client_routing_policy = "availability_zone_affinity"
3233

3334
# https://github.com/hashicorp/terraform-provider-aws/issues/17281
3435
# subnets = module.vpc.private_subnets
@@ -158,6 +159,9 @@ module "nlb" {
158159
port = 84
159160
target_type = "instance"
160161
target_id = aws_instance.this.id
162+
target_health_state = {
163+
enable_unhealthy_connection_termination = false
164+
}
161165
}
162166
}
163167

examples/complete-nlb/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 5.13"
7+
version = ">= 5.23"
88
}
99
}
1010
}

main.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ resource "aws_lb" "this" {
2424

2525
customer_owned_ipv4_pool = var.customer_owned_ipv4_pool
2626
desync_mitigation_mode = var.desync_mitigation_mode
27+
dns_record_client_routing_policy = var.dns_record_client_routing_policy
2728
drop_invalid_header_fields = var.drop_invalid_header_fields
2829
enable_cross_zone_load_balancing = var.enable_cross_zone_load_balancing
2930
enable_deletion_protection = var.enable_deletion_protection
@@ -482,6 +483,13 @@ resource "aws_lb_target_group" "this" {
482483
}
483484
}
484485

486+
dynamic "target_health_state" {
487+
for_each = try([each.value.target_health_state], [])
488+
content {
489+
enable_unhealthy_connection_termination = try(target_health_state.value.enable_unhealthy_connection_termination, true)
490+
}
491+
}
492+
485493
target_type = try(each.value.target_type, null)
486494
vpc_id = try(each.value.vpc_id, var.vpc_id)
487495

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ variable "desync_mitigation_mode" {
3232
default = null
3333
}
3434

35+
variable "dns_record_client_routing_policy" {
36+
description = "Indicates how traffic is distributed among the load balancer Availability Zones. Possible values are any_availability_zone (default), availability_zone_affinity, or partial_availability_zone_affinity. Only valid for network type load balancers."
37+
type = string
38+
default = null
39+
}
40+
3541
variable "drop_invalid_header_fields" {
3642
description = "Indicates whether HTTP headers with header fields that are not valid are removed by the load balancer (`true`) or routed to targets (`false`). The default is `true`. Elastic Load Balancing requires that message header names contain only alphanumeric characters and hyphens. Only valid for Load Balancers of type `application`"
3743
type = bool

versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 5.13"
7+
version = ">= 5.23"
88
}
99
}
1010
}

wrappers/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module "wrapper" {
1111
default_port = try(each.value.default_port, var.defaults.default_port, 80)
1212
default_protocol = try(each.value.default_protocol, var.defaults.default_protocol, "HTTP")
1313
desync_mitigation_mode = try(each.value.desync_mitigation_mode, var.defaults.desync_mitigation_mode, null)
14+
dns_record_client_routing_policy = try(each.value.dns_record_client_routing_policy, var.defaults.dns_record_client_routing_policy, null)
1415
drop_invalid_header_fields = try(each.value.drop_invalid_header_fields, var.defaults.drop_invalid_header_fields, true)
1516
enable_cross_zone_load_balancing = try(each.value.enable_cross_zone_load_balancing, var.defaults.enable_cross_zone_load_balancing, true)
1617
enable_deletion_protection = try(each.value.enable_deletion_protection, var.defaults.enable_deletion_protection, true)

0 commit comments

Comments
 (0)