Skip to content

Commit

Permalink
r/aws_batch_job_definition: Suppress unnecessary environment variable…
Browse files Browse the repository at this point in the history
… diffs.
  • Loading branch information
ewbankkit committed Oct 9, 2024
1 parent 2d07daa commit b710358
Showing 1 changed file with 10 additions and 4 deletions.
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

0 comments on commit b710358

Please sign in to comment.