Skip to content

Commit

Permalink
Merge pull request #21834 from ma2gedev/f-aws_batch_job_definition-en…
Browse files Browse the repository at this point in the history
…v-var-ordering

r/aws_batch_job_definition: Suppress unnecessary environment variable diffs
  • Loading branch information
ewbankkit authored Oct 9, 2024
2 parents 4a19c19 + b710358 commit fc125af
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
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

0 comments on commit fc125af

Please sign in to comment.