From 028cf868435de859750e36a848caa7c442e5f946 Mon Sep 17 00:00:00 2001 From: Tim Hartmann Date: Tue, 13 Mar 2018 14:11:29 -0400 Subject: [PATCH] Adds health_check_grace_period_seconds to module (#4) Also update formating to pass tests Updated ECS Service to allow us to use the terraform aws provider greater then 1.0.3 --- README.md | 1 + ecs.tf | 3 ++- files/container_definition.json | 9 ++++++++- variables.tf | 5 +++++ 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f3125ec..9f1fab2 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,7 @@ Terraform module for deploying and managing a generic [ECS](https://aws.amazon.c - `app_port` - Numeric port on which application listens (unnecessary if neither alb_enable_https or alb_enable_http are true) - `ecs_deployment_maximum_percent` - Upper limit in percentage of tasks that can be running during a deployment (default 200) - `ecs_deployment_minimum_healthy_percent` - Lower limit in percentage of tasks that must remain healthy during a deployment (default 100) +- `ecs_health_check_grace_period` - Seconds to ignore failing load balancer health checks on newly instantiated tasks to prevent premature shutdown, up to 1800. (default 500) - `ecs_placement_strategy_type` - Placement strategy to use when distributing tasks (default binpack) - `ecs_placement_strategy_field` - Container metadata field to use when distributing tasks (default memory) - `ecs_log_retention` - Number of days of ECS task logs to retain (default 3) diff --git a/ecs.tf b/ecs.tf index 4b0995b..97611f7 100644 --- a/ecs.tf +++ b/ecs.tf @@ -31,7 +31,7 @@ resource "aws_ecs_task_definition" "task" { task_role_arn = "${aws_iam_role.task.arn}" volume { - name = "data" + name = "data" host_path = "${var.ecs_data_volume_path}" } } @@ -44,6 +44,7 @@ resource "aws_ecs_service" "service" { iam_role = "${aws_iam_role.service.arn}" deployment_maximum_percent = "${var.ecs_deployment_maximum_percent}" deployment_minimum_healthy_percent = "${var.ecs_deployment_minimum_healthy_percent}" + health_check_grace_period_seconds = "${var.ecs_health_check_grace_period}" placement_strategy { type = "${var.ecs_placement_strategy_type}" diff --git a/files/container_definition.json b/files/container_definition.json index ed970d6..2dbfb34 100644 --- a/files/container_definition.json +++ b/files/container_definition.json @@ -3,15 +3,22 @@ "name": "${service_identifier}-${task_identifier}", "image": "${image}", "memory": ${memory}, + "cpu": 0, + "essential": true, "memoryReservation": ${memory_reservation}, "portMappings": [ { - "containerPort": ${app_port} + "containerPort": ${app_port}, + "hostPort": 0, + "protocol": "tcp" } ], ${command_override} "environment": ${environment}, "mountPoints": ${mount_points}, + "volumesFrom": [ + + ], "logConfiguration": { "logDriver": "awslogs", "options": { diff --git a/variables.tf b/variables.tf index dfcc11e..d2a7010 100644 --- a/variables.tf +++ b/variables.tf @@ -35,6 +35,11 @@ variable "ecs_deployment_minimum_healthy_percent" { description = "Lower limit in percentage of tasks that must remain healthy during a deployment (default 100)" } +variable "ecs_health_check_grace_period" { + default = "500" + description = "Seconds to ignore failing load balancer health checks on newly instantiated tasks to prevent premature shutdown, up to 1800. (default 500)" +} + variable "docker_command" { description = "String to override CMD in Docker container (default \"\")" default = ""