Skip to content

Commit

Permalink
fix: Don't look up latest task definition by default (closes #72)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
domcleal committed Oct 30, 2020
1 parent 05b9dc7 commit fbeb565
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
11 changes: 7 additions & 4 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ locals {
},
]

# ECS task definition
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

# Secret access tokens
container_definition_secrets_1 = local.secret_name_key != "" && local.secret_name_value_from != "" ? [
{
Expand Down Expand Up @@ -563,6 +566,8 @@ resource "aws_ecs_task_definition" "atlantis" {
}

data "aws_ecs_task_definition" "atlantis" {
count = var.external_task_definition_updates ? 1 : 0

task_definition = var.name

depends_on = [aws_ecs_task_definition.atlantis]
Expand All @@ -571,10 +576,8 @@ data "aws_ecs_task_definition" "atlantis" {
resource "aws_ecs_service" "atlantis" {
name = var.name
cluster = module.ecs.this_ecs_cluster_id
task_definition = "${data.aws_ecs_task_definition.atlantis.family}:${max(
aws_ecs_task_definition.atlantis.revision,
data.aws_ecs_task_definition.atlantis.revision,
)}"

task_definition = "${var.name}:${local.latest_task_definition_rev}"
desired_count = var.ecs_service_desired_count
launch_type = "FARGATE"
deployment_maximum_percent = var.ecs_service_deployment_maximum_percent
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,12 @@ variable "ulimits" {
default = null
}

variable "external_task_definition_updates" {
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."
type = bool
default = false
}

# https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_FirelensConfiguration.html
variable "firelens_configuration" {
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"
Expand Down

0 comments on commit fbeb565

Please sign in to comment.