Skip to content

Commit ef6cc62

Browse files
authored
fix: fetch of unexisting task definitions during tf planning (#44)
1 parent 39da430 commit ef6cc62

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

main.tf

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@ data "aws_ecs_task_definition" "this" {
156156
count = local.services_count > 0 ? local.services_count : 0
157157

158158
task_definition = element(aws_ecs_task_definition.this[*].family, count.index)
159+
160+
# This avoid fetching an unexisting task definition before its creation
161+
depends_on = ["aws_ecs_task_definition.this"]
159162
}
160163

161164
resource "aws_cloudwatch_log_group" "this" {
@@ -341,11 +344,15 @@ resource "aws_service_discovery_service" "this" {
341344
resource "aws_ecs_service" "this" {
342345
count = local.services_count > 0 ? local.services_count : 0
343346

344-
name = local.services[count.index].name
345-
cluster = aws_ecs_cluster.this.name
346-
task_definition = "${aws_ecs_task_definition.this[count.index].family}:${max("${aws_ecs_task_definition.this[count.index].revision}", "${data.aws_ecs_task_definition.this[count.index].revision}")}"
347-
desired_count = local.services[count.index].replicas
348-
launch_type = "FARGATE"
347+
name = local.services[count.index].name
348+
cluster = aws_ecs_cluster.this.name
349+
desired_count = local.services[count.index].replicas
350+
launch_type = "FARGATE"
351+
352+
task_definition = "${aws_ecs_task_definition.this[count.index].family}:${max(
353+
aws_ecs_task_definition.this[count.index].revision,
354+
length(data.aws_ecs_task_definition.this) >= count.index ? data.aws_ecs_task_definition.this[count.index].revision : 1
355+
)}"
349356

350357
deployment_minimum_healthy_percent = 100
351358
deployment_maximum_percent = 200

0 commit comments

Comments
 (0)