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
ma2gedev committed Nov 18, 2021
1 parent 889a927 commit 52f6bfa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
10 changes: 7 additions & 3 deletions internal/service/batch/container_properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ type containerProperties batch.ContainerProperties

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

// 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 @@ -145,3 +143,9 @@ func EquivalentContainerPropertiesJSON(str1, str2 string) (bool, error) {

return equal, nil
}

func (cp *containerProperties) OrderEnvironmentVariables() {
sort.Slice(cp.Environment, func(i, j int) bool {
return aws.StringValue(cp.Environment[i].Name) < aws.StringValue(cp.Environment[j].Name)
})
}
6 changes: 5 additions & 1 deletion internal/service/batch/job_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ func ResourceJobDefinition() *schema.Resource {
Optional: true,
ForceNew: true,
StateFunc: func(v interface{}) string {
json, _ := structure.NormalizeJsonString(v)
orderedProps, _ := expandBatchJobContainerProperties(v.(string))
(*containerProperties)(orderedProps).OrderEnvironmentVariables()
unnormalizedJson, _ := flattenBatchContainerProperties(orderedProps)
json, _ := structure.NormalizeJsonString(unnormalizedJson)
return json
},
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
Expand Down Expand Up @@ -245,6 +248,7 @@ func resourceJobDefinitionRead(d *schema.ResourceData, meta interface{}) error {

d.Set("arn", jobDefinition.JobDefinitionArn)

(*containerProperties)(jobDefinition.ContainerProperties).OrderEnvironmentVariables()
containerProperties, err := flattenBatchContainerProperties(jobDefinition.ContainerProperties)

if err != nil {
Expand Down

0 comments on commit 52f6bfa

Please sign in to comment.