Skip to content

Commit

Permalink
fix: Optionally lookup for the latest task definition (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
domcleal authored Mar 16, 2021
1 parent 87aea73 commit 0d84ed4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: git://github.com/antonbabenko/pre-commit-terraform
rev: v1.47.0
rev: v1.48.0
hooks:
- id: terraform_fmt
- id: terraform_validate
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ allow_github_webhooks = true
| enable\_ecs\_managed\_tags | Specifies whether to enable Amazon ECS managed tags for the tasks within the service | `bool` | `false` | 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. 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. | `bool` | `false` | no |
| extra\_container\_definitions | A list of valid container definitions provided as a single valid JSON document. These will be provided as supplimentary to the main Atlantis container definition | `list(any)` | `[]` | 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 |
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 @@ -571,6 +574,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 @@ -579,10 +584,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 = var.ecs_fargate_spot ? null : "FARGATE"
platform_version = var.ecs_service_platform_version
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,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 0d84ed4

Please sign in to comment.