Skip to content

Commit

Permalink
feat: Make ALB Health Checks configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
jbonnier committed Jan 10, 2024
1 parent 1db6303 commit 5f8a4e3
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 14 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,16 @@ module "ecs_app" {
| <a name="input_ecs_cluster_name"></a> [ecs\_cluster\_name](#input\_ecs\_cluster\_name) | The name of the ECS cluster. | `string` | n/a | yes |
| <a name="input_enabled"></a> [enabled](#input\_enabled) | Set to false to prevent the module from creating any resources | `bool` | `null` | no |
| <a name="input_environment"></a> [environment](#input\_environment) | ID element. Usually used for region e.g. 'uw2', 'us-west-2', OR role 'prod', 'staging', 'dev', 'UAT' | `string` | `null` | no |
| <a name="input_health_check_matcher"></a> [health\_check\_matcher](#input\_health\_check\_matcher) | The HTTP response codes to indicate a healthy check. | `string` | n/a | yes |
| <a name="input_healthcheck_path"></a> [healthcheck\_path](#input\_healthcheck\_path) | Path for the ALB health checks. | `string` | n/a | yes |
| <a name="input_health_check_enabled"></a> [health\_check\_enabled](#input\_health\_check\_enabled) | Indicates whether health checks are enabled. Defaults to `true` | `bool` | `true` | no |
| <a name="input_health_check_healthy_threshold"></a> [health\_check\_healthy\_threshold](#input\_health\_check\_healthy\_threshold) | The number of consecutive health checks successes required before healthy | `number` | `2` | no |
| <a name="input_health_check_interval"></a> [health\_check\_interval](#input\_health\_check\_interval) | The duration in seconds in between health checks | `number` | `15` | no |
| <a name="input_health_check_matcher"></a> [health\_check\_matcher](#input\_health\_check\_matcher) | The HTTP response codes to indicate a healthy check.<br>Example: `"200-399"` | `string` | n/a | yes |
| <a name="input_health_check_path"></a> [health\_check\_path](#input\_health\_check\_path) | The destination for the health check request | `string` | `"/"` | no |
| <a name="input_health_check_port"></a> [health\_check\_port](#input\_health\_check\_port) | The port to use to connect with the target. Valid values are either ports 1-65536, or `traffic-port`. Defaults to `traffic-port` | `string` | `"traffic-port"` | no |
| <a name="input_health_check_protocol"></a> [health\_check\_protocol](#input\_health\_check\_protocol) | The protocol to use to connect with the target. Defaults to `HTTP`. Not applicable when `target_type` is `lambda` | `string` | `"HTTP"` | no |
| <a name="input_health_check_timeout"></a> [health\_check\_timeout](#input\_health\_check\_timeout) | The amount of time to wait in seconds before failing a health check request | `number` | `10` | no |
| <a name="input_health_check_unhealthy_threshold"></a> [health\_check\_unhealthy\_threshold](#input\_health\_check\_unhealthy\_threshold) | The number of consecutive health check failures required before unhealthy | `number` | `2` | no |
| <a name="input_healthcheck_path"></a> [healthcheck\_path](#input\_healthcheck\_path) | DEPRECATED: Use `health_check_path` instead.<br>Path for the ALB health checks. | `string` | `null` | no |
| <a name="input_id_length_limit"></a> [id\_length\_limit](#input\_id\_length\_limit) | Limit `id` to this many characters (minimum 6).<br>Set to `0` for unlimited length.<br>Set to `null` for keep the existing setting, which defaults to `0`.<br>Does not affect `id_full`. | `number` | `null` | no |
| <a name="input_kms_key_arn"></a> [kms\_key\_arn](#input\_kms\_key\_arn) | KMS Key ARN for Cloudwatch logs. | `string` | `null` | no |
| <a name="input_label_key_case"></a> [label\_key\_case](#input\_label\_key\_case) | Controls the letter case of the `tags` keys (label names) for tags generated by this module.<br>Does not affect keys of tags passed in via the `tags` input.<br>Possible values: `lower`, `title`, `upper`.<br>Default value: `title`. | `string` | `null` | no |
Expand Down
26 changes: 16 additions & 10 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ locals {
url = "${local.protocol}://${local.address}:${aws_lb_listener.app[0].port}"
enabled = module.this.enabled
ecs_service_task_sg_name = "${module.this.id}-ecs-service-task"
health_check_path = var.healthcheck_path != null ? var.healthcheck_path : var.health_check_path
}

data "aws_lb" "alb" {
Expand All @@ -26,16 +27,21 @@ module "alb_ingress" {
source = "cloudposse/alb-ingress/aws"
version = "0.25.1"

vpc_id = var.vpc_id
port = var.service_container_port
protocol = var.service_container_protocol
health_check_path = var.healthcheck_path
health_check_protocol = var.service_container_protocol
default_target_group_enabled = true
health_check_matcher = var.health_check_matcher
stickiness_type = var.alb_ingress_stickiness_type
stickiness_cookie_duration = var.alb_ingress_stickiness_cookie_duration
stickiness_enabled = var.alb_ingress_stickiness_enabled
vpc_id = var.vpc_id
port = var.service_container_port
protocol = var.service_container_protocol
health_check_enabled = var.health_check_enabled
health_check_path = local.health_check_path
health_check_matcher = var.health_check_matcher
health_check_port = var.health_check_port
health_check_protocol = var.health_check_protocol
health_check_timeout = var.health_check_timeout
health_check_healthy_threshold = var.health_check_healthy_threshold
health_check_interval = var.health_check_interval
default_target_group_enabled = true
stickiness_type = var.alb_ingress_stickiness_type
stickiness_cookie_duration = var.alb_ingress_stickiness_cookie_duration
stickiness_enabled = var.alb_ingress_stickiness_enabled

context = module.this.context
attributes = concat(module.this.attributes, [lower(var.service_container_protocol), var.service_container_port])
Expand Down
60 changes: 58 additions & 2 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,77 @@ variable "service_container_protocol" {
description = "Container protocol for the service."
}

variable "health_check_enabled" {
type = bool
default = true
description = "Indicates whether health checks are enabled. Defaults to `true`"
}

variable "healthcheck_path" {
type = string
description = "Path for the ALB health checks."
default = null
description = <<-EOT
DEPRECATED: Use `health_check_path` instead.
Path for the ALB health checks.
EOT
}

variable "health_check_matcher" {
type = string
description = "The HTTP response codes to indicate a healthy check."
description = <<-EOT
The HTTP response codes to indicate a healthy check.
Example: `"200-399"`
EOT
}

variable "health_check_path" {
type = string
default = "/"
description = "The destination for the health check request"
}

variable "health_check_port" {
type = string
default = "traffic-port"
description = "The port to use to connect with the target. Valid values are either ports 1-65536, or `traffic-port`. Defaults to `traffic-port`"
}

variable "health_check_protocol" {
type = string
default = "HTTP"
description = "The protocol to use to connect with the target. Defaults to `HTTP`. Not applicable when `target_type` is `lambda`"
}

variable "health_check_timeout" {
type = number
default = 10
description = "The amount of time to wait in seconds before failing a health check request"
}

variable "health_check_healthy_threshold" {
type = number
default = 2
description = "The number of consecutive health checks successes required before healthy"
}

variable "health_check_unhealthy_threshold" {
type = number
default = 2
description = "The number of consecutive health check failures required before unhealthy"
}

variable "health_check_interval" {
type = number
default = 15
description = "The duration in seconds in between health checks"
}

variable "aliases" {
type = list(string)
description = "List of FQDN's - Used to set the Alternate Domain Names (CNAMEs)."
default = []
}

variable "dns_alias_enabled" {
type = bool
default = false
Expand Down

0 comments on commit 5f8a4e3

Please sign in to comment.