Skip to content

Commit fbeb565

Browse files
committed
fix: Don't look up latest task definition by default (closes #72)
A data lookup for the latest task definition revision to be used in the ECS service was enabled by default, which continually appeared in plans/applies. This is used when the task definition's updated by an external deployment tool, so this is now disabled and requires enabling the `external_task_definition_updates` variable so the default behaviour is quiet.
1 parent 05b9dc7 commit fbeb565

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

main.tf

+7-4
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ locals {
7777
},
7878
]
7979

80+
# ECS task definition
81+
latest_task_definition_rev = var.external_task_definition_updates ? max(aws_ecs_task_definition.atlantis.revision, data.aws_ecs_task_definition.atlantis[0].revision) : aws_ecs_task_definition.atlantis.revision
82+
8083
# Secret access tokens
8184
container_definition_secrets_1 = local.secret_name_key != "" && local.secret_name_value_from != "" ? [
8285
{
@@ -563,6 +566,8 @@ resource "aws_ecs_task_definition" "atlantis" {
563566
}
564567

565568
data "aws_ecs_task_definition" "atlantis" {
569+
count = var.external_task_definition_updates ? 1 : 0
570+
566571
task_definition = var.name
567572

568573
depends_on = [aws_ecs_task_definition.atlantis]
@@ -571,10 +576,8 @@ data "aws_ecs_task_definition" "atlantis" {
571576
resource "aws_ecs_service" "atlantis" {
572577
name = var.name
573578
cluster = module.ecs.this_ecs_cluster_id
574-
task_definition = "${data.aws_ecs_task_definition.atlantis.family}:${max(
575-
aws_ecs_task_definition.atlantis.revision,
576-
data.aws_ecs_task_definition.atlantis.revision,
577-
)}"
579+
580+
task_definition = "${var.name}:${local.latest_task_definition_rev}"
578581
desired_count = var.ecs_service_desired_count
579582
launch_type = "FARGATE"
580583
deployment_maximum_percent = var.ecs_service_deployment_maximum_percent

variables.tf

+6
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,12 @@ variable "ulimits" {
381381
default = null
382382
}
383383

384+
variable "external_task_definition_updates" {
385+
description = "Enable to allow the task definition to be updated outside of this Terraform module. This should be enabled when using a deployment tool such as ecs-deploy which updates the task definition and will then keep the ECS service using the latest version of the task definition."
386+
type = bool
387+
default = false
388+
}
389+
384390
# https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_FirelensConfiguration.html
385391
variable "firelens_configuration" {
386392
description = "The FireLens configuration for the container. This is used to specify and configure a log router for container logs. For more details, see https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_FirelensConfiguration.html"

0 commit comments

Comments
 (0)