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 0993a8f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ allow_github_webhooks = true
| ecs\_task\_memory | The amount (in MiB) of memory used by the task | `number` | `512` | no |
| entrypoint | The entry point that is passed to the container | `list(string)` | `null` | no |
| 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 |
| external\_task\_definition\_updates | Enable to allow the task definition to be updated outside of this Terraform module | `bool` | `false` | no |
| 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 |
| 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 |
| internal | Whether the load balancer is internal or external | `bool` | `false` | no |
Expand Down
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 0993a8f

Please sign in to comment.