From 538fa3f5baf5bbfc05c29894de29d7f8e7707271 Mon Sep 17 00:00:00 2001 From: George Taylor Date: Fri, 22 Nov 2024 14:11:38 +0000 Subject: [PATCH 1/4] feat: add option to pin service to task def revision --- service/service.tf | 6 +++--- service/variables.tf | 11 ++++++----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/service/service.tf b/service/service.tf index 8093552..419f573 100644 --- a/service/service.tf +++ b/service/service.tf @@ -3,7 +3,7 @@ resource "aws_ecs_service" "default" { cluster = var.cluster_arn - task_definition = aws_ecs_task_definition.default.arn + task_definition = var.pin_task_definition_revision != 0 ? "${aws_ecs_task_definition.default.arn}:${aws_ecs_task_definition.default.revision}" : aws_ecs_task_definition.default.arn launch_type = "FARGATE" network_configuration { @@ -20,8 +20,8 @@ resource "aws_ecs_service" "default" { force_new_deployment = var.force_new_deployment triggers = var.force_new_deployment ? { - update = plantimestamp() # force update in-place every apply that has force_new_deployment set to true - } : null + redeployment = plantimestamp() # force update in-place every apply that has force_new_deployment set to true + } : {} dynamic "load_balancer" { for_each = var.service_load_balancers diff --git a/service/variables.tf b/service/variables.tf index 5cc7724..238a277 100644 --- a/service/variables.tf +++ b/service/variables.tf @@ -20,11 +20,6 @@ variable "container_definitions" { sensitive = false } -variable "ignore_changes" { - type = bool - description = "Whether to ignore changes to the service, task definition, container definition" -} - variable "efs_volumes" { type = list(object({ host_path = string @@ -151,3 +146,9 @@ variable "deployment_circuit_breaker" { rollback = false } } + +variable "pin_task_definition_revision" { + type = number + description = "The revision of the task definition to use" + default = 0 +} From d11489272c0512921f2633e2c491b533455b3abf Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 22 Nov 2024 14:12:18 +0000 Subject: [PATCH 2/4] terraform-docs: automated action --- service/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/README.md b/service/README.md index c9c9e53..e30173d 100644 --- a/service/README.md +++ b/service/README.md @@ -94,8 +94,8 @@ No modules. | [ephemeral\_storage\_size\_in\_gib](#input\_ephemeral\_storage\_size\_in\_gib) | The size of the ephemeral storage to use for the task definition | `number` | `30` | no | | [force\_new\_deployment](#input\_force\_new\_deployment) | Whether to force a new deployment of the service | `bool` | `false` | no | | [health\_check\_grace\_period\_seconds](#input\_health\_check\_grace\_period\_seconds) | The grace period to allow for healthy instances to warm up before checking them | `number` | `0` | no | -| [ignore\_changes](#input\_ignore\_changes) | Whether to ignore changes to the service, task definition, container definition | `bool` | n/a | yes | | [name](#input\_name) | The name of the ECS service | `string` | n/a | yes | +| [pin\_task\_definition\_revision](#input\_pin\_task\_definition\_revision) | The revision of the task definition to use | `number` | `0` | no | | [security\_groups](#input\_security\_groups) | A list of security group IDs to associate with the service | `list(string)` | n/a | yes | | [service\_load\_balancers](#input\_service\_load\_balancers) | A list of load balancers to associate with the service |
list(object({
container_name = string
container_port = number
elb_name = optional(string)
target_group_arn = string
}))
| n/a | yes | | [service\_role\_arn](#input\_service\_role\_arn) | The ARN of the IAM role to use for the service | `string` | n/a | yes | From 1c35cce7e864e7d62bfa798c45cd5a93a4d0d4fb Mon Sep 17 00:00:00 2001 From: George Taylor Date: Fri, 22 Nov 2024 14:14:58 +0000 Subject: [PATCH 3/4] Update service.tf --- service/service.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/service.tf b/service/service.tf index 419f573..b707caa 100644 --- a/service/service.tf +++ b/service/service.tf @@ -3,7 +3,7 @@ resource "aws_ecs_service" "default" { cluster = var.cluster_arn - task_definition = var.pin_task_definition_revision != 0 ? "${aws_ecs_task_definition.default.arn}:${aws_ecs_task_definition.default.revision}" : aws_ecs_task_definition.default.arn + task_definition = var.pin_task_definition_revision != 0 ? "${aws_ecs_task_definition.default.arn}:${var.pin_task_definition_revision}" : aws_ecs_task_definition.default.arn launch_type = "FARGATE" network_configuration { From 869791e4ffbc8b9b921f265abd6bc97b34bcc6bc Mon Sep 17 00:00:00 2001 From: George Taylor Date: Fri, 22 Nov 2024 15:10:24 +0000 Subject: [PATCH 4/4] correct templating of arn --- service/service.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/service.tf b/service/service.tf index b707caa..7060e26 100644 --- a/service/service.tf +++ b/service/service.tf @@ -3,7 +3,7 @@ resource "aws_ecs_service" "default" { cluster = var.cluster_arn - task_definition = var.pin_task_definition_revision != 0 ? "${aws_ecs_task_definition.default.arn}:${var.pin_task_definition_revision}" : aws_ecs_task_definition.default.arn + task_definition = var.pin_task_definition_revision != 0 ? "${aws_ecs_task_definition.default.arn_without_revision}:${var.pin_task_definition_revision}" : aws_ecs_task_definition.default.arn launch_type = "FARGATE" network_configuration {