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

bugfix/treat empty secretOptions as null to prevent batch_job_definition recreation every time #16120

Merged
merged 3 commits into from
Apr 19, 2021
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/16120.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_batch_job_definition: Treat empty `container_properties.logConfiguration.secretOptions` array as `null` to prevent continual diffs
```
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ func (cp *containerProperties) Reduce() error {
cp.Environment = nil
}

// Prevent difference of API response that adds an empty array when not configured during the request
if cp.LogConfiguration != nil {
if len(cp.LogConfiguration.SecretOptions) == 0 {
cp.LogConfiguration.SecretOptions = nil
}
}

// Prevent difference of API response that adds an empty array when not configured during the request
if len(cp.MountPoints) == 0 {
cp.MountPoints = nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func TestEquivalentBatchContainerPropertiesJSON(t *testing.T) {
ExpectEquivalent: true,
},
{
Name: "empty command, mountPoints, resourceRequirements, secrets, ulimits, volumes",
Name: "empty command, logConfiguration.secretOptions, mountPoints, resourceRequirements, secrets, ulimits, volumes",
ApiJson: `
{
"image": "123.dkr.ecr.us-east-1.amazonaws.com/my-app",
Expand All @@ -219,6 +219,10 @@ func TestEquivalentBatchContainerPropertiesJSON(t *testing.T) {
"jobRoleArn": "arn:aws:iam::123:role/role-test",
"volumes": [],
"environment": [{"name":"ENVIRONMENT","value":"test"}],
"logConfiguration": {
"logDriver": "awslogs",
"secretOptions": []
},
"mountPoints": [],
"ulimits": [],
"resourceRequirements": [],
Expand All @@ -236,7 +240,10 @@ func TestEquivalentBatchContainerPropertiesJSON(t *testing.T) {
"name": "ENVIRONMENT",
"value": "test"
}
]
],
"logConfiguration": {
"logDriver": "awslogs"
}
}
`,
ExpectEquivalent: true,
Expand Down
24 changes: 12 additions & 12 deletions aws/resource_aws_batch_job_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func resourceAwsBatchJobDefinitionCreate(d *schema.ResourceData, meta interface{
}

if v, ok := d.GetOk("retry_strategy"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil {
input.RetryStrategy = expandRetryStrategy(v.([]interface{})[0].(map[string]interface{}))
input.RetryStrategy = expandBatchRetryStrategy(v.([]interface{})[0].(map[string]interface{}))
}

if v := d.Get("tags").(map[string]interface{}); len(v) > 0 {
Expand Down Expand Up @@ -254,7 +254,7 @@ func resourceAwsBatchJobDefinitionRead(d *schema.ResourceData, meta interface{})
d.Set("propagate_tags", jobDefinition.PropagateTags)

if jobDefinition.RetryStrategy != nil {
if err := d.Set("retry_strategy", []interface{}{flattenRetryStrategy(jobDefinition.RetryStrategy)}); err != nil {
if err := d.Set("retry_strategy", []interface{}{flattenBatchRetryStrategy(jobDefinition.RetryStrategy)}); err != nil {
return fmt.Errorf("error setting retry_strategy: %w", err)
}
} else {
Expand Down Expand Up @@ -343,7 +343,7 @@ func expandJobDefinitionParameters(params map[string]interface{}) map[string]*st
return jobParams
}

func expandRetryStrategy(tfMap map[string]interface{}) *batch.RetryStrategy {
func expandBatchRetryStrategy(tfMap map[string]interface{}) *batch.RetryStrategy {
if tfMap == nil {
return nil
}
Expand All @@ -355,13 +355,13 @@ func expandRetryStrategy(tfMap map[string]interface{}) *batch.RetryStrategy {
}

if v, ok := tfMap["evaluate_on_exit"].([]interface{}); ok && len(v) > 0 {
apiObject.EvaluateOnExit = expandEvaluateOnExits(v)
apiObject.EvaluateOnExit = expandBatchEvaluateOnExits(v)
}

return apiObject
}

func expandEvaluateOnExit(tfMap map[string]interface{}) *batch.EvaluateOnExit {
func expandBatchEvaluateOnExit(tfMap map[string]interface{}) *batch.EvaluateOnExit {
if tfMap == nil {
return nil
}
Expand All @@ -387,7 +387,7 @@ func expandEvaluateOnExit(tfMap map[string]interface{}) *batch.EvaluateOnExit {
return apiObject
}

func expandEvaluateOnExits(tfList []interface{}) []*batch.EvaluateOnExit {
func expandBatchEvaluateOnExits(tfList []interface{}) []*batch.EvaluateOnExit {
if len(tfList) == 0 {
return nil
}
Expand All @@ -401,7 +401,7 @@ func expandEvaluateOnExits(tfList []interface{}) []*batch.EvaluateOnExit {
continue
}

apiObject := expandEvaluateOnExit(tfMap)
apiObject := expandBatchEvaluateOnExit(tfMap)

if apiObject == nil {
continue
Expand All @@ -413,7 +413,7 @@ func expandEvaluateOnExits(tfList []interface{}) []*batch.EvaluateOnExit {
return apiObjects
}

func flattenRetryStrategy(apiObject *batch.RetryStrategy) map[string]interface{} {
func flattenBatchRetryStrategy(apiObject *batch.RetryStrategy) map[string]interface{} {
if apiObject == nil {
return nil
}
Expand All @@ -425,13 +425,13 @@ func flattenRetryStrategy(apiObject *batch.RetryStrategy) map[string]interface{}
}

if v := apiObject.EvaluateOnExit; v != nil {
tfMap["evaluate_on_exit"] = flattenEvaluateOnExits(v)
tfMap["evaluate_on_exit"] = flattenBatchEvaluateOnExits(v)
}

return tfMap
}

func flattenEvaluateOnExit(apiObject *batch.EvaluateOnExit) map[string]interface{} {
func flattenBatchEvaluateOnExit(apiObject *batch.EvaluateOnExit) map[string]interface{} {
if apiObject == nil {
return nil
}
Expand All @@ -457,7 +457,7 @@ func flattenEvaluateOnExit(apiObject *batch.EvaluateOnExit) map[string]interface
return tfMap
}

func flattenEvaluateOnExits(apiObjects []*batch.EvaluateOnExit) []interface{} {
func flattenBatchEvaluateOnExits(apiObjects []*batch.EvaluateOnExit) []interface{} {
if len(apiObjects) == 0 {
return nil
}
Expand All @@ -469,7 +469,7 @@ func flattenEvaluateOnExits(apiObjects []*batch.EvaluateOnExit) []interface{} {
continue
}

tfList = append(tfList, flattenEvaluateOnExit(apiObject))
tfList = append(tfList, flattenBatchEvaluateOnExit(apiObject))
}

return tfList
Expand Down