Skip to content

Commit

Permalink
Merge pull request #17 from nsbno/service-timeouts
Browse files Browse the repository at this point in the history
Add variable for timeouts for the ecs service
  • Loading branch information
halvorhm authored May 13, 2024
2 parents fcb300a + fe5bce3 commit 33fd088
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
14 changes: 13 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,12 @@ resource "aws_ecs_service" "service" {
weight = capacity_provider_strategy.value.weight
}
}

timeouts {
create = var.ecs_service_timeouts.create
update = var.ecs_service_timeouts.update
delete = var.ecs_service_timeouts.delete
}
}

resource "aws_ecs_service" "service_with_autoscaling" {
Expand Down Expand Up @@ -507,6 +513,12 @@ resource "aws_ecs_service" "service_with_autoscaling" {
lifecycle {
ignore_changes = [desired_count]
}

timeouts {
create = var.ecs_service_timeouts.create
update = var.ecs_service_timeouts.update
delete = var.ecs_service_timeouts.delete
}
}

/*
Expand Down Expand Up @@ -588,7 +600,7 @@ resource "aws_appautoscaling_policy" "ecs_service" {

lifecycle {
precondition {
condition = !(var.autoscaling_resource_label != "" && length(var.custom_metrics) > 0)
condition = !(var.autoscaling_resource_label != "" && length(var.custom_metrics) > 0)
error_message = "Cannot define autoscaling resource label and custom metrics at the same time"
}
}
Expand Down
18 changes: 18 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,24 @@ variable "launch_type" {
}
}

variable "ecs_service_timeouts" {
description = <<EOF
Default 20m. The timeouts for terraform update of the ECS service. If adjusted down, remember to also adjust health_check_grace_period_seconds.
Normally this should allow the ECS to at least do one retry of starting the container before timing out. The timeout is the whole rollout, not only the container startup.
I.e. health_check_grace_period_seconds * 2 + a bit extra > ecs_service_timeouts.
EOF
type = object({
create = optional(string, null)
update = optional(string, null)
delete = optional(string, null)
})
default = {
create = "20m"
update = "20m"
delete = "20m"
}
}

variable "use_spot" {
description = "NB! NOT RECOMMENDED FOR PROD. Whether to use spot instances for the service. Requirement: FARGATE_SPOT enabled capacity providers. Mutually exclusive with \"launch_type\"."
type = bool
Expand Down

0 comments on commit 33fd088

Please sign in to comment.