diff --git a/README.md b/README.md index 3764bfb..9619e6e 100644 --- a/README.md +++ b/README.md @@ -12,3 +12,40 @@ Includes: * CloudWatch Dashboard (optional) * Cloudflare DNS Record (optional) * Adminer database manager (optional) + +## Inputs + +- `health_check` + +Defines health checks for load balancer target groups. See [AWS Documentation](https://docs.aws.amazon.com/elasticloadbalancing/latest/network/target-group-health-checks.html) for details. + +Example: + +```hcl +health_check = { + enabled = true + healthy_threshold = 3 + interval = 30 + matcher = "200-399" + path = "/" + port = "traffic-port" + protocol = "HTTP" + timeout = 10 + unhealthy_threshold = 3 + } +``` + +- (TODO) + +## Outputs + +(TODO) + + +## Example + +A working [example](https://github.com/silinternational/terraform-aws-ecs-app/tree/main/test) usage of this module is included in the source repository. + +## More info + +More information is available at the [Terraform Registry](https://registry.terraform.io/modules/silinternational/ecs-app/aws/latest) diff --git a/main.tf b/main.tf index e28e0f5..e5eb48b 100644 --- a/main.tf +++ b/main.tf @@ -113,9 +113,19 @@ resource "aws_alb_target_group" "tg" { type = "lb_cookie" } - health_check { - path = "/" - matcher = "302" + dynamic "health_check" { + for_each = [var.health_check] + content { + enabled = try(health_check.value.enabled, null) + healthy_threshold = try(health_check.value.healthy_threshold, null) + interval = try(health_check.value.interval, null) + matcher = try(health_check.value.matcher, null) + path = try(health_check.value.path, null) + port = try(health_check.value.port, null) + protocol = try(health_check.value.protocol, null) + timeout = try(health_check.value.timeout, null) + unhealthy_threshold = try(health_check.value.unhealthy_threshold, null) + } } } @@ -195,7 +205,7 @@ module "adminer" { app_env = var.app_env vpc_id = module.vpc.id alb_https_listener_arn = module.alb.https_listener_arn - subdomain = "adminer" + subdomain = "adminer-${local.app_name_and_env}" cloudflare_domain = var.domain_name ecs_cluster_id = module.ecsasg.ecs_cluster_id ecsServiceRole_arn = module.ecsasg.ecsServiceRole_arn diff --git a/test/test.tf b/test/test.tf index 28fc346..28f8d44 100644 --- a/test/test.tf +++ b/test/test.tf @@ -32,6 +32,17 @@ module "full" { instance_type = "t3.micro" create_adminer = true enable_adminer = true + health_check = { + enabled = true + healthy_threshold = 3 + interval = 30 + matcher = "200-399" + path = "/" + port = "traffic-port" + protocol = "HTTP" + timeout = 10 + unhealthy_threshold = 3 + } } provider "aws" { diff --git a/variables.tf b/variables.tf index 24b9c9b..87f3a7b 100644 --- a/variables.tf +++ b/variables.tf @@ -134,6 +134,14 @@ variable "default_cert_domain_name" { type = string } +variable "health_check" { + description = "Elastic Load Balancer health check configuration" + type = map(string) + default = { + path = "/" + matcher = "200-399" + } +} /* * Database configuration