Skip to content

Commit dfa17ab

Browse files
committed
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.
1 parent 852ef25 commit dfa17ab

3 files changed

Lines changed: 6 additions & 0 deletions

File tree

lib/deploy.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ func deployService(ctx log.Interface, cluster, imageTag string, imageTags []stri
8181
// then describe the task definition to get a copy of it
8282
describeTaskResult, err := svc.DescribeTaskDefinition(&ecs.DescribeTaskDefinitionInput{
8383
TaskDefinition: describeResult.Services[0].TaskDefinition,
84+
Include: aws.StringSlice([]string{"TAGS"}),
8485
})
8586
if err != nil {
8687
ctx.WithError(err).Error("Can't get task definition")
@@ -107,6 +108,7 @@ func deployService(ctx log.Interface, cluster, imageTag string, imageTags []stri
107108
RequiresCompatibilities: taskDefinition.Compatibilities,
108109
TaskRoleArn: taskDefinition.TaskRoleArn,
109110
Volumes: taskDefinition.Volumes,
111+
Tags: describeTaskResult.Tags,
110112
})
111113
if err != nil {
112114
ctx.WithError(err).Error("Can't register task definition")

lib/run.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ func RunTask(profile, cluster, service, taskDefinitionName, imageTag string, ima
2323

2424
describeResult, err := svc.DescribeTaskDefinition(&ecs.DescribeTaskDefinitionInput{
2525
TaskDefinition: aws.String(taskDefinitionName),
26+
Include: aws.StringSlice([]string{"TAGS"}),
2627
})
2728
if err != nil {
2829
ctx.WithError(err).Error("Can't get task definition")
@@ -67,6 +68,7 @@ func RunTask(profile, cluster, service, taskDefinitionName, imageTag string, ima
6768
RequiresCompatibilities: taskDefinition.Compatibilities,
6869
TaskRoleArn: taskDefinition.TaskRoleArn,
6970
Volumes: taskDefinition.Volumes,
71+
Tags: describeResult.Tags,
7072
})
7173
if err != nil {
7274
ctx.WithError(err).Error("Can't register task definition")

lib/runFargate.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ func RunFargate(profile, cluster, service, taskDefinitionName, imageTag string,
6363

6464
describeResult, err := svc.DescribeTaskDefinition(&ecs.DescribeTaskDefinitionInput{
6565
TaskDefinition: aws.String(taskDefinitionName),
66+
Include: aws.StringSlice([]string{"TAGS"}),
6667
})
6768
if err != nil {
6869
ctx.WithError(err).Error("Can't get task definition")
@@ -111,6 +112,7 @@ func RunFargate(profile, cluster, service, taskDefinitionName, imageTag string,
111112
RequiresCompatibilities: taskDefinition.Compatibilities,
112113
TaskRoleArn: taskDefinition.TaskRoleArn,
113114
Volumes: taskDefinition.Volumes,
115+
Tags: describeResult.Tags,
114116
})
115117
if err != nil {
116118
ctx.WithError(err).Error("Can't register task definition")

0 commit comments

Comments
 (0)