Skip to content

Commit 72ffb66

Browse files
Merge pull request #1 from gaussb-labs/feature/add-healthcheck-support-in-alb
feat: add healthcheck block to target group configuration
2 parents 465124f + 086b8de commit 72ffb66

File tree

2 files changed

+69
-14
lines changed

2 files changed

+69
-14
lines changed

main.tf

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
locals {
2-
managed_by = "Terraform"
3-
target_group_app_name = "app"
4-
alb_listener_app_http_name = "app_http"
5-
alb_listener_app_https_name = "app_https"
6-
alb_listener_rule_app_name = "app"
2+
managed_by = "Terraform"
3+
target_group_app_name = "app"
4+
alb_listener_app_http_name = "app_http"
5+
alb_listener_app_https_name = "app_https"
6+
alb_listener_rule_app_name = "app"
77
}
88

99
resource "aws_lb" "alb" {
@@ -30,6 +30,17 @@ resource "aws_lb_target_group" "app" {
3030
port = var.app_port
3131
protocol = "HTTP"
3232
vpc_id = var.vpc_id
33+
health_check {
34+
enabled = var.target_group_app_enabled
35+
healthy_threshold = var.target_group_app_healthy_threshold
36+
unhealthy_threshold = var.target_group_app_unhealthy_threshold
37+
interval = var.target_group_app_interval
38+
matcher = var.target_group_app_matcher
39+
path = var.target_group_app_path
40+
port = var.target_group_app_port
41+
protocol = var.target_group_app_protocol
42+
timeout = var.target_group_app_timeout
43+
}
3344
tags = {
3445
"Name" = "${var.environment}-${local.target_group_app_name}"
3546
"ManagedBy" = local.managed_by

variables.tf

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ variable "app_subdomain_name" {
1111
description = "The domain name for the public facing app. Application load balancer will be attached to this domain. Should be different for staging and production applications."
1212
}
1313
variable "alb_name" {
14-
type = string
14+
type = string
1515
description = "Name of the application load balancer."
1616
}
1717
variable "alb_access_logs_prefix" {
@@ -23,34 +23,78 @@ variable "alb_access_logs_expiry_days" {
2323
description = "Number of days to retain application load balancer access logs."
2424
}
2525
variable "app_port" {
26-
type = number
26+
type = number
2727
description = "The port number app is running on."
2828
}
2929
variable "alb_default_static_response" {
3030
type = object({
31-
content_type = string
31+
content_type = string
3232
encoded_message_body = string
33-
status_code = string
33+
status_code = string
3434
})
3535
description = "The default static response to return if no rules match in alb."
3636
}
3737
variable "vpc_id" {
38-
type = string
38+
type = string
3939
description = "Identifier for AWS VPC where the resources will be created."
4040
}
4141
variable "http_https_ingress_sg_id" {
42-
type = string
42+
type = string
4343
description = "Identifier for the security group allowing access to HTTP(80) and HTTPS(443) ingress. This is used for ingress traffic to load balancer."
4444
}
4545
variable "alb_subnets" {
46-
type = list(string)
46+
type = list(string)
4747
description = "List of subnet identifiers to associate subnets to load balancer."
4848
}
4949
variable "alb_aws_account_arn" {
50-
type = string
50+
type = string
5151
description = "AWS account ARN for the account containing load balancer."
5252
}
5353
variable "alb_access_logs_bucket_name" {
54-
type = string
54+
type = string
5555
description = "S3 bucket name which will be used to store load balancer access logs. Prefix <var.environment> will be added. The bucket name should be unique globally."
5656
}
57+
variable "target_group_app_enabled" {
58+
type = bool
59+
description = "Enable /Disable target health check."
60+
default = true
61+
}
62+
variable "target_group_app_healthy_threshold" {
63+
type = number
64+
description = "Number of consecutive health checks successes required before considering an unhealthy target healthy."
65+
default = 3
66+
}
67+
variable "target_group_app_unhealthy_threshold" {
68+
type = number
69+
description = "Number of consecutive health check failures required before considering the target unhealthy."
70+
default = 3
71+
}
72+
variable "target_group_app_interval" {
73+
type = number
74+
description = "Approximate amount of time, in seconds, between health checks of an individual target."
75+
default = 30
76+
}
77+
variable "target_group_app_matcher" {
78+
type = string
79+
description = "Response codes to use when checking for a healthy responses from a target."
80+
}
81+
variable "target_group_app_path" {
82+
type = string
83+
description = "Destination for the health check request."
84+
}
85+
variable "target_group_app_port" {
86+
type = string
87+
description = "Port to use to connect with the target."
88+
default = "traffic-port"
89+
}
90+
variable "target_group_app_protocol" {
91+
type = string
92+
description = "Protocol to use to connect with the target."
93+
default = "HTTP"
94+
95+
}
96+
variable "target_group_app_timeout" {
97+
type = number
98+
description = "Amount of time, in seconds, during which no response means a failed health check."
99+
default = 5
100+
}

0 commit comments

Comments
 (0)