From dfa17ab20bb06fc57db6e9a2ca137aa004fbeb15 Mon Sep 17 00:00:00 2001 From: Andrei Vsiakikh Date: Tue, 12 May 2026 15:01:36 +1200 Subject: [PATCH] Propagate task definition tags through RegisterTaskDefinition DescribeTaskDefinition now requests TAGS, and RegisterTaskDefinition passes them through when registering the new revision. This keeps the tags on existing task definitions (typically set by Terraform) intact across ecs-tool deploys and run-task invocations. This unblocks deploys against AWS accounts where an SCP enforces mandatory tag keys on ecs:RegisterTaskDefinition: the new revision inherits the tags from the previous one, so aws:TagKeys is populated in the API request. Behaviour for projects that don't tag their task definitions is unchanged - DescribeTaskDefinition returns an empty Tags slice, and the RegisterTaskDefinition call passes nil tags as before. --- lib/deploy.go | 2 ++ lib/run.go | 2 ++ lib/runFargate.go | 2 ++ 3 files changed, 6 insertions(+) diff --git a/lib/deploy.go b/lib/deploy.go index 24e7b33..f6ce141 100644 --- a/lib/deploy.go +++ b/lib/deploy.go @@ -81,6 +81,7 @@ func deployService(ctx log.Interface, cluster, imageTag string, imageTags []stri // then describe the task definition to get a copy of it describeTaskResult, err := svc.DescribeTaskDefinition(&ecs.DescribeTaskDefinitionInput{ TaskDefinition: describeResult.Services[0].TaskDefinition, + Include: aws.StringSlice([]string{"TAGS"}), }) if err != nil { ctx.WithError(err).Error("Can't get task definition") @@ -107,6 +108,7 @@ func deployService(ctx log.Interface, cluster, imageTag string, imageTags []stri RequiresCompatibilities: taskDefinition.Compatibilities, TaskRoleArn: taskDefinition.TaskRoleArn, Volumes: taskDefinition.Volumes, + Tags: describeTaskResult.Tags, }) if err != nil { ctx.WithError(err).Error("Can't register task definition") diff --git a/lib/run.go b/lib/run.go index 4d6e548..aafc05c 100644 --- a/lib/run.go +++ b/lib/run.go @@ -23,6 +23,7 @@ func RunTask(profile, cluster, service, taskDefinitionName, imageTag string, ima describeResult, err := svc.DescribeTaskDefinition(&ecs.DescribeTaskDefinitionInput{ TaskDefinition: aws.String(taskDefinitionName), + Include: aws.StringSlice([]string{"TAGS"}), }) if err != nil { ctx.WithError(err).Error("Can't get task definition") @@ -67,6 +68,7 @@ func RunTask(profile, cluster, service, taskDefinitionName, imageTag string, ima RequiresCompatibilities: taskDefinition.Compatibilities, TaskRoleArn: taskDefinition.TaskRoleArn, Volumes: taskDefinition.Volumes, + Tags: describeResult.Tags, }) if err != nil { ctx.WithError(err).Error("Can't register task definition") diff --git a/lib/runFargate.go b/lib/runFargate.go index b3c06a8..4c9b6ea 100644 --- a/lib/runFargate.go +++ b/lib/runFargate.go @@ -63,6 +63,7 @@ func RunFargate(profile, cluster, service, taskDefinitionName, imageTag string, describeResult, err := svc.DescribeTaskDefinition(&ecs.DescribeTaskDefinitionInput{ TaskDefinition: aws.String(taskDefinitionName), + Include: aws.StringSlice([]string{"TAGS"}), }) if err != nil { ctx.WithError(err).Error("Can't get task definition") @@ -111,6 +112,7 @@ func RunFargate(profile, cluster, service, taskDefinitionName, imageTag string, RequiresCompatibilities: taskDefinition.Compatibilities, TaskRoleArn: taskDefinition.TaskRoleArn, Volumes: taskDefinition.Volumes, + Tags: describeResult.Tags, }) if err != nil { ctx.WithError(err).Error("Can't register task definition")