From 140cf689f8c7efd2a73e10a1244a0ea1e5f7b1e0 Mon Sep 17 00:00:00 2001 From: ilkan Date: Tue, 13 Feb 2024 12:06:50 -0100 Subject: [PATCH 1/3] resource/aws_ecs_task_definition: prevent spurious secret diffs --- internal/service/ecs/task_definition.go | 2 ++ internal/service/ecs/task_definition_equivalency.go | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/internal/service/ecs/task_definition.go b/internal/service/ecs/task_definition.go index fa69ac4cd6e..a80f14a3a33 100644 --- a/internal/service/ecs/task_definition.go +++ b/internal/service/ecs/task_definition.go @@ -84,6 +84,7 @@ func ResourceTaskDefinition() *schema.Resource { // but they still show in the plan if some other property changes). orderedCDs, _ := expandContainerDefinitions(v.(string)) containerDefinitions(orderedCDs).OrderEnvironmentVariables() + containerDefinitions(orderedCDs).OrderSecrets() unnormalizedJson, _ := flattenContainerDefinitions(orderedCDs) json, _ := structure.NormalizeJsonString(unnormalizedJson) return json @@ -613,6 +614,7 @@ func resourceTaskDefinitionRead(ctx context.Context, d *schema.ResourceData, met // (diff is suppressed if the environment variables haven't changed, but they still show in the plan if // some other property changes). containerDefinitions(taskDefinition.ContainerDefinitions).OrderEnvironmentVariables() + containerDefinitions(taskDefinition.ContainerDefinitions).OrderSecrets() defs, err := flattenContainerDefinitions(taskDefinition.ContainerDefinitions) if err != nil { diff --git a/internal/service/ecs/task_definition_equivalency.go b/internal/service/ecs/task_definition_equivalency.go index 43a649a594f..815987ab305 100644 --- a/internal/service/ecs/task_definition_equivalency.go +++ b/internal/service/ecs/task_definition_equivalency.go @@ -61,6 +61,7 @@ type containerDefinitions []*ecs.ContainerDefinition func (cd containerDefinitions) Reduce(isAWSVPC bool) error { // Deal with fields which may be re-ordered in the API cd.OrderEnvironmentVariables() + cd.OrderSecrets() for i, def := range cd { // Deal with special fields which have defaults @@ -112,3 +113,11 @@ func (cd containerDefinitions) OrderEnvironmentVariables() { }) } } + +func (cd containerDefinitions) OrderSecrets() { + for _, def := range cd { + sort.Slice(def.Secrets, func(i, j int) bool { + return aws.StringValue(def.Secrets[i].Name) < aws.StringValue(def.Secrets[j].Name) + }) + } +} \ No newline at end of file From 9a2ede2f8913778b23c5b12d3e76291553569d2f Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 13 Feb 2024 09:11:07 -0500 Subject: [PATCH 2/3] Add CHANGELOG entry. --- .changelog/35792.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/35792.txt diff --git a/.changelog/35792.txt b/.changelog/35792.txt new file mode 100644 index 00000000000..14c81b357ce --- /dev/null +++ b/.changelog/35792.txt @@ -0,0 +1,3 @@ +```release-note:bug +resource/aws_ecs_task_definition: Fix perpetual `container_definitions` diffs when `Secrets` are ordered differently +``` \ No newline at end of file From 300ca52fe8cbb729c40e23b53f9ff9f9d1c43c62 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 13 Feb 2024 09:16:49 -0500 Subject: [PATCH 3/3] Run 'make fmt'. --- internal/service/ecs/task_definition_equivalency.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/ecs/task_definition_equivalency.go b/internal/service/ecs/task_definition_equivalency.go index 815987ab305..d668113d2c1 100644 --- a/internal/service/ecs/task_definition_equivalency.go +++ b/internal/service/ecs/task_definition_equivalency.go @@ -120,4 +120,4 @@ func (cd containerDefinitions) OrderSecrets() { return aws.StringValue(def.Secrets[i].Name) < aws.StringValue(def.Secrets[j].Name) }) } -} \ No newline at end of file +}