Skip to content

Commit

Permalink
Merge pull request #35778 from bruceharrison1984/datasync-task-fix
Browse files Browse the repository at this point in the history
Fix bug in `aws_datasync_task`
  • Loading branch information
jar-b authored Feb 14, 2024
2 parents 6db9841 + 6248752 commit 46a7e24
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 20 deletions.
6 changes: 6 additions & 0 deletions .changelog/35778.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
```release-note:bug
resource/aws_datasync_task: Prevent ValidationErrors when empty values are sent with `report_override` arguments
```
```release-note:bug
resource/aws_datasync_task: Fix crash when reading empty `report_override` values
```
70 changes: 50 additions & 20 deletions internal/service/datasync/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -564,15 +564,26 @@ func flattenTaskReportConfig(options *datasync.TaskReportConfig) []interface{} {
}

func flattenTaskReportConfigReportOverrides(options *datasync.ReportOverrides) []interface{} {
m := make(map[string]interface{})

if options == nil {
return []interface{}{}
return []interface{}{m}
}

m := map[string]interface{}{
"deleted_override": aws.StringValue(options.Deleted.ReportLevel),
"skipped_override": aws.StringValue(options.Skipped.ReportLevel),
"transferred_override": aws.StringValue(options.Transferred.ReportLevel),
"verified_override": aws.StringValue(options.Verified.ReportLevel),
if options.Deleted != nil && options.Deleted.ReportLevel != nil {
m["deleted_override"] = aws.StringValue(options.Deleted.ReportLevel)
}

if options.Skipped != nil && options.Skipped.ReportLevel != nil {
m["skipped_override"] = aws.StringValue(options.Skipped.ReportLevel)
}

if options.Transferred != nil && options.Transferred.ReportLevel != nil {
m["transferred_override"] = aws.StringValue(options.Transferred.ReportLevel)
}

if options.Verified != nil && options.Verified.ReportLevel != nil {
m["verified_override"] = aws.StringValue(options.Verified.ReportLevel)
}

return []interface{}{m}
Expand Down Expand Up @@ -686,24 +697,43 @@ func expandTaskReportDestination(l []interface{}) *datasync.ReportDestination {
}

func expandTaskReportOverrides(l []interface{}) *datasync.ReportOverrides {
var overrides = &datasync.ReportOverrides{}

if len(l) == 0 || l[0] == nil {
return nil
return overrides
}

m := l[0].(map[string]interface{})
return &datasync.ReportOverrides{
Deleted: &datasync.ReportOverride{
ReportLevel: aws.String(m["deleted_override"].(string)),
},
Skipped: &datasync.ReportOverride{
ReportLevel: aws.String(m["skipped_override"].(string)),
},
Transferred: &datasync.ReportOverride{
ReportLevel: aws.String(m["transferred_override"].(string)),
},
Verified: &datasync.ReportOverride{
ReportLevel: aws.String(m["verified_override"].(string)),
},

deleteOverride := m["deleted_override"].(string)
if deleteOverride != "" {
overrides.SetDeleted(&datasync.ReportOverride{
ReportLevel: aws.String(deleteOverride),
})
}

skippedOverride := m["skipped_override"].(string)
if skippedOverride != "" {
overrides.SetSkipped(&datasync.ReportOverride{
ReportLevel: aws.String(skippedOverride),
})
}

transferredOverride := m["transferred_override"].(string)
if transferredOverride != "" {
overrides.SetTransferred(&datasync.ReportOverride{
ReportLevel: aws.String(transferredOverride),
})
}

verifiedOverride := m["verified_override"].(string)
if verifiedOverride != "" {
overrides.SetVerified(&datasync.ReportOverride{
ReportLevel: aws.String(verifiedOverride),
})
}

return overrides
}

func expandFilterRules(l []interface{}) []*datasync.FilterRule {
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/datasync_task.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ The following arguments are supported inside the `report_overrides` configuratio
* `transferred_override` - (Optional) Specifies the level of reporting for the files, objects, and directories that DataSync attempted to transfer. Valid values: `ERRORS_ONLY` and `SUCCESSES_AND_ERRORS`.
* `verified_override` - (Optional) Specifies the level of reporting for the files, objects, and directories that DataSync attempted to verify at the end of your transfer. Valid values: `ERRORS_ONLY` and `SUCCESSES_AND_ERRORS`.

~> **NOTE:** If any `report_overrides` are set to the same value as `task_report_config.report_level`, they will always be flagged as changed. Only set overrides to a value that differs from `task_report_config.report_level`.

### Schedule

* `schedule_expression` - (Required) Specifies the schedule you want your task to use for repeated executions. For more information, see [Schedule Expressions for Rules](https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/ScheduledEvents.html).
Expand Down

0 comments on commit 46a7e24

Please sign in to comment.