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

r/aws_batch_job_definition: Suppress unnecessary environment variable diffs #21834

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions .changelog/21834.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_batch_job_definition: Suppress unnecessary differences in `container_properties.environment`
```
14 changes: 10 additions & 4 deletions internal/service/batch/container_properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ const (
type containerProperties awstypes.ContainerProperties

func (cp *containerProperties) reduce() {
// Deal with Environment objects which may be re-ordered in the API.
sort.Slice(cp.Environment, func(i, j int) bool {
return aws.ToString(cp.Environment[i].Name) < aws.ToString(cp.Environment[j].Name)
})
cp.sortEnvironment()

// Prevent difference of API response that adds an empty array when not configured during the request.
if len(cp.Command) == 0 {
Expand Down Expand Up @@ -108,6 +105,13 @@ func (cp *containerProperties) reduce() {
}
}

func (cp *containerProperties) sortEnvironment() {
// Deal with Environment objects which may be re-ordered in the API.
sort.Slice(cp.Environment, func(i, j int) bool {
return aws.ToString(cp.Environment[i].Name) < aws.ToString(cp.Environment[j].Name)
})
}

// equivalentContainerPropertiesJSON determines equality between two Batch ContainerProperties JSON strings
func equivalentContainerPropertiesJSON(str1, str2 string) (bool, error) {
if str1 == "" {
Expand Down Expand Up @@ -164,6 +168,8 @@ func flattenContainerProperties(apiObject *awstypes.ContainerProperties) (string
return "", nil
}

(*containerProperties)(apiObject).sortEnvironment()

jsonEncoder := smithyjson.NewEncoder()
err := serializeContainerProperties(apiObject, jsonEncoder.Value)

Expand Down
Loading