Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resource/aws_ecs_task_definition: prevent spurious secret diffs #35792

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions internal/service/ecs/task_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
9 changes: 9 additions & 0 deletions internal/service/ecs/task_definition_equivalency.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
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
Expand Down Expand Up @@ -112,3 +113,11 @@
})
}
}

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)
})
}
}

Check failure on line 123 in internal/service/ecs/task_definition_equivalency.go

View workflow job for this annotation

GitHub Actions / 1 of 2

File is not `gofmt`-ed with `-s` (gofmt)
Loading