Skip to content

Commit 0993a8f

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 0993a8f

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ allow_github_webhooks = true
236236
| ecs\_task\_memory | The amount (in MiB) of memory used by the task | `number` | `512` | no |
237237
| entrypoint | The entry point that is passed to the container | `list(string)` | `null` | no |
238238
| essential | Determines whether all other containers in a task are stopped, if this container fails or stops for any reason. Due to how Terraform type casts booleans in json it is required to double quote this value | `bool` | `true` | no |
239+
| external\_task\_definition\_updates | Enable to allow the task definition to be updated outside of this Terraform module | `bool` | `false` | no |
239240
| firelens\_configuration | 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 | <pre>object({<br> type = string<br> options = map(string)<br> })</pre> | `null` | no |
240241
| github\_webhooks\_cidr\_blocks | List of CIDR blocks used by GitHub webhooks | `list(string)` | <pre>[<br> "140.82.112.0/20",<br> "185.199.108.0/22",<br> "192.30.252.0/22"<br>]</pre> | no |
241242
| internal | Whether the load balancer is internal or external | `bool` | `false` | no |

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)