Skip to content

Commit a332684

Browse files
authored
Support traffic-port for healthcheck of target groups (#71)
1 parent b3eadab commit a332684

File tree

65 files changed

+484
-351
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+484
-351
lines changed

examples/alb-with-instance-target-group/main.tf

+10-6
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,15 @@ module "target_group_alpha" {
157157
]
158158

159159
health_check = {
160-
port = 80
161-
protocol = "HTTP"
160+
protocol = "HTTP"
161+
port = 80
162+
port_override = false
163+
path = "/health"
164+
162165
interval = 10
163166
timeout = 5
164167
healthy_threshold = 5
165168
unhealthy_threshold = 2
166-
path = "/health"
167169
}
168170

169171
tags = {
@@ -201,13 +203,15 @@ module "target_group_beta" {
201203
]
202204

203205
health_check = {
204-
port = 80
205-
protocol = "HTTP"
206+
protocol = "HTTP"
207+
port = 80
208+
port_override = false
209+
path = "/health"
210+
206211
interval = 10
207212
timeout = 5
208213
healthy_threshold = 5
209214
unhealthy_threshold = 2
210-
path = "/health"
211215
}
212216

213217
tags = {

examples/alb-with-instance-target-group/versions.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
terraform {
2-
required_version = "~> 1.1"
2+
required_version = "~> 1.3"
33

44
required_providers {
55
aws = {

examples/alb-with-ip-target-group/main.tf

+10-6
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,15 @@ module "target_group_alpha" {
162162
]
163163

164164
health_check = {
165-
port = 80
166-
protocol = "HTTP"
165+
protocol = "HTTP"
166+
port = 80
167+
port_override = false
168+
path = "/health"
169+
167170
interval = 10
168171
timeout = 5
169172
healthy_threshold = 5
170173
unhealthy_threshold = 2
171-
path = "/health"
172174
}
173175

174176
tags = {
@@ -207,13 +209,15 @@ module "target_group_beta" {
207209
]
208210

209211
health_check = {
210-
port = 80
211-
protocol = "HTTP"
212+
protocol = "HTTP"
213+
port = 80
214+
port_override = false
215+
path = "/health"
216+
212217
interval = 10
213218
timeout = 5
214219
healthy_threshold = 5
215220
unhealthy_threshold = 2
216-
path = "/health"
217221
}
218222

219223
tags = {

examples/alb-with-ip-target-group/versions.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
terraform {
2-
required_version = "~> 1.1"
2+
required_version = "~> 1.3"
33

44
required_providers {
55
aws = {

examples/gwlb-with-instance-target-group/main.tf

+5-3
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,14 @@ module "target_group" {
6767
]
6868

6969
health_check = {
70-
port = 80
71-
protocol = "HTTP"
70+
protocol = "HTTP"
71+
port = 80
72+
port_override = true
73+
path = "/health"
74+
7275
interval = 10
7376
timeout = 5
7477
healthy_threshold = 3
7578
unhealthy_threshold = 3
76-
path = "/health"
7779
}
7880
}

examples/gwlb-with-instance-target-group/versions.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
terraform {
2-
required_version = "~> 1.1"
2+
required_version = "~> 1.3"
33

44
required_providers {
55
aws = {

examples/gwlb-with-ip-target-group/main.tf

+5-3
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,14 @@ module "target_group" {
6767
]
6868

6969
health_check = {
70-
port = 80
71-
protocol = "HTTP"
70+
protocol = "TCP"
71+
port = 80
72+
port_override = true
73+
path = "/"
74+
7275
interval = 10
7376
timeout = 5
7477
healthy_threshold = 3
7578
unhealthy_threshold = 3
76-
path = "/health"
7779
}
7880
}

examples/gwlb-with-ip-target-group/versions.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
terraform {
2-
required_version = "~> 1.1"
2+
required_version = "~> 1.3"
33

44
required_providers {
55
aws = {

examples/nlb-with-alb-target-group/alb.tf

+4-3
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ module "alb" {
4444
protocol = "HTTPS"
4545
port = 443
4646
}
47-
rules = {
48-
10 = {
47+
rules = [
48+
{
49+
priority = 10
4950
conditions = [
5051
{
5152
type = "PATH"
@@ -61,7 +62,7 @@ module "alb" {
6162
EOF
6263
}
6364
}
64-
}
65+
]
6566
},
6667
# {
6768
# port = 443

examples/nlb-with-alb-target-group/main.tf

+5-3
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,14 @@ module "target_group" {
7676
]
7777

7878
health_check = {
79-
port = 80
80-
protocol = "HTTP"
79+
protocol = "HTTP"
80+
port = 80
81+
port_override = false
82+
path = "/ping"
83+
8184
interval = 10
8285
healthy_threshold = 3
8386
unhealthy_threshold = 3
84-
path = "/ping"
8587
}
8688

8789
tags = {

examples/nlb-with-alb-target-group/versions.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
terraform {
2-
required_version = "~> 1.1"
2+
required_version = "~> 1.3"
33

44
required_providers {
55
aws = {

examples/nlb-with-instance-target-group/main.tf

+5-3
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,15 @@ module "target_group" {
8585
]
8686

8787
health_check = {
88-
port = 80
89-
protocol = "HTTP"
88+
protocol = "HTTP"
89+
port = 80
90+
port_override = true
91+
path = "/health"
92+
9093
interval = 10
9194
timeout = 5
9295
healthy_threshold = 3
9396
unhealthy_threshold = 3
94-
path = "/health"
9597
}
9698

9799
tags = {

examples/nlb-with-instance-target-group/versions.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
terraform {
2-
required_version = "~> 1.1"
2+
required_version = "~> 1.3"
33

44
required_providers {
55
aws = {

examples/nlb-with-ip-target-group/main.tf

+5-3
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,15 @@ module "target_group" {
9090
]
9191

9292
health_check = {
93-
port = 80
94-
protocol = "HTTP"
93+
protocol = "HTTP"
94+
port = 443
95+
port_override = false
96+
path = "/health"
97+
9598
interval = 10
9699
timeout = 5
97100
healthy_threshold = 3
98101
unhealthy_threshold = 3
99-
path = "/health"
100102
}
101103

102104
tags = {

examples/nlb-with-ip-target-group/versions.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
terraform {
2-
required_version = "~> 1.1"
2+
required_version = "~> 1.3"
33

44
required_providers {
55
aws = {

modules/alb-instance-target-group/README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ This module creates following resources.
1010

1111
| Name | Version |
1212
|------|---------|
13-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.2 |
13+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3 |
1414
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.71 |
1515

1616
## Providers
1717

1818
| Name | Version |
1919
|------|---------|
20-
| <a name="provider_aws"></a> [aws](#provider\_aws) | 4.36.1 |
20+
| <a name="provider_aws"></a> [aws](#provider\_aws) | 4.37.0 |
2121

2222
## Modules
2323

@@ -41,7 +41,7 @@ This module creates following resources.
4141
| <a name="input_protocol"></a> [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 |
4242
| <a name="input_vpc_id"></a> [vpc\_id](#input\_vpc\_id) | (Required) The ID of the VPC which the target group belongs to. | `string` | n/a | yes |
4343
| <a name="input_deregistration_delay"></a> [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 |
44-
| <a name="input_health_check"></a> [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.<br> (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.<br> (Optional) `protocol` - Protocol to use to connect with the target. The possible values are `HTTP` and `HTTPS`. Defaults to `HTTP`.<br> (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`.<br> (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`.<br> (Optional) `interval` - Approximate amount of time, in seconds, between health checks of an individual target. Valid value range is 5 - 300. Defaults to `30`.<br> (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`.<br> (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`).<br> (Optional) `path` - Use the default path of `/` to ping the root, or specify a custom path if preferred. | `any` | `{}` | no |
44+
| <a name="input_health_check"></a> [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.<br> (Optional) `protocol` - Protocol to use to connect with the target. The possible values are `HTTP` and `HTTPS`. Defaults to `HTTP`.<br> (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.<br> (Optional) `port_override` - Whether to override the port on which each target receives trafficfrom the load balancer to a different port. Defaults to `false`.<br> (Optional) `path` - Use the default path of `/` to ping the root, or specify a custom path if preferred.<br> (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`).<br> (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`.<br> (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`.<br> (Optional) `interval` - Approximate amount of time, in seconds, between health checks of an individual target. Valid value range is 5 - 300. Defaults to `30`.<br> (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`. | <pre>object({<br> protocol = optional(string, "HTTP")<br> port = optional(number, null)<br> port_override = optional(bool, false)<br> path = optional(string, null)<br> success_codes = optional(string, null)<br><br> healthy_threshold = optional(number, 5)<br> unhealthy_threshold = optional(number, 2)<br> interval = optional(number, 30)<br> timeout = optional(number, 5)<br> })</pre> | `{}` | no |
4545
| <a name="input_load_balancing_algorithm"></a> [load\_balancing\_algorithm](#input\_load\_balancing\_algorithm) | (Optional) Determines how the load balancer selects targets when routing requests. Valid values are `ROUND_ROBIN` or `LEAST_OUTSTANDING_REQUESTS`. Defaults to `ROUND_ROBIN`. | `string` | `"ROUND_ROBIN"` | no |
4646
| <a name="input_module_tags_enabled"></a> [module\_tags\_enabled](#input\_module\_tags\_enabled) | (Optional) Whether to create AWS Resource Tags for the module informations. | `bool` | `true` | no |
4747
| <a name="input_protocol_version"></a> [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 |
@@ -54,7 +54,7 @@ This module creates following resources.
5454
| <a name="input_stickiness_enabled"></a> [stickiness\_enabled](#input\_stickiness\_enabled) | (Optional) Whether to enable the type of stickiness associated with this target group. If enabled, the load balancer binds a client’s session to a specific instance within the target group. Defaults to `false`. | `bool` | `false` | no |
5555
| <a name="input_stickiness_type"></a> [stickiness\_type](#input\_stickiness\_type) | (Optional) The type of sticky sessions. Valid values are `LB_COOKIE` or `APP_COOKIE`. Defaults to `LB_COOKIE`. | `string` | `"LB_COOKIE"` | no |
5656
| <a name="input_tags"></a> [tags](#input\_tags) | (Optional) A map of tags to add to all resources. | `map(string)` | `{}` | no |
57-
| <a name="input_targets"></a> [targets](#input\_targets) | (Optional) A set of targets to add to the target group. Each value of `targets` block as defined below.<br> (Required) `instance` - This is the Instance ID for an instance, or the container ID for an ECS container.<br> (Optional) `port` - The port on which targets receive traffic. | `set(map(string))` | `[]` | no |
57+
| <a name="input_targets"></a> [targets](#input\_targets) | (Optional) A set of targets to add to the target group. Each value of `targets` block as defined below.<br> (Required) `instance` - This is the Instance ID for an instance, or the container ID for an ECS container.<br> (Optional) `port` - The port on which targets receive traffic. | <pre>set(object({<br> instance = string<br> port = optional(number, null)<br> }))</pre> | `[]` | no |
5858

5959
## Outputs
6060

modules/alb-instance-target-group/main.tf

+17-13
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,24 @@ resource "aws_lb_target_group" "this" {
4646
health_check {
4747
enabled = true
4848

49-
port = try(var.health_check.port, var.port)
50-
protocol = try(var.health_check.protocol, "HTTP")
51-
52-
healthy_threshold = try(var.health_check.healthy_threshold, 5)
53-
unhealthy_threshold = try(var.health_check.unhealthy_threshold, 2)
54-
interval = try(var.health_check.interval, 30)
55-
timeout = try(var.health_check.timeout, 5)
56-
57-
matcher = (var.protocol_version != "GRPC"
58-
? try(var.health_check.success_codes, "200")
59-
: try(var.health_check.success_codes, "12"))
49+
protocol = var.health_check.protocol
50+
port = (var.health_check.port_override
51+
? coalesce(var.health_check.port, var.port)
52+
: "traffic-port"
53+
)
6054
path = (var.protocol_version != "GRPC"
61-
? try(var.health_check.path, "/")
62-
: try(var.health_check.path, "/AWS.ALB/healthcheck"))
55+
? coalesce(var.health_check.path, "/")
56+
: coalesce(var.health_check.path, "/AWS.ALB/healthcheck")
57+
)
58+
matcher = (var.protocol_version != "GRPC"
59+
? coalesce(var.health_check.success_codes, "200")
60+
: coalesce(var.health_check.success_codes, "12")
61+
)
62+
63+
healthy_threshold = var.health_check.healthy_threshold
64+
unhealthy_threshold = var.health_check.unhealthy_threshold
65+
interval = var.health_check.interval
66+
timeout = var.health_check.timeout
6367
}
6468

6569
tags = merge(

modules/alb-instance-target-group/outputs.tf

+4-5
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,14 @@ output "attributes" {
7171
output "health_check" {
7272
description = "Health Check configuration of the target group."
7373
value = {
74-
protocol = aws_lb_target_group.this.health_check[0].protocol
75-
port = aws_lb_target_group.this.health_check[0].port
74+
protocol = aws_lb_target_group.this.health_check[0].protocol
75+
port = aws_lb_target_group.this.health_check[0].port
76+
path = aws_lb_target_group.this.health_check[0].path
77+
success_codes = aws_lb_target_group.this.health_check[0].matcher
7678

7779
healthy_threshold = aws_lb_target_group.this.health_check[0].healthy_threshold
7880
unhealthy_threshold = aws_lb_target_group.this.health_check[0].unhealthy_threshold
7981
interval = aws_lb_target_group.this.health_check[0].interval
8082
timeout = aws_lb_target_group.this.health_check[0].timeout
81-
82-
success_codes = aws_lb_target_group.this.health_check[0].matcher
83-
path = aws_lb_target_group.this.health_check[0].path
8483
}
8584
}

0 commit comments

Comments
 (0)