diff --git a/.changelog/35778.txt b/.changelog/35778.txt new file mode 100644 index 00000000000..b696ba4dde3 --- /dev/null +++ b/.changelog/35778.txt @@ -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 +``` diff --git a/internal/service/datasync/task.go b/internal/service/datasync/task.go index 54742ada705..767e40a0af6 100644 --- a/internal/service/datasync/task.go +++ b/internal/service/datasync/task.go @@ -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} @@ -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 { diff --git a/website/docs/r/datasync_task.html.markdown b/website/docs/r/datasync_task.html.markdown index 08915caa1e4..ae81fb32a9b 100644 --- a/website/docs/r/datasync_task.html.markdown +++ b/website/docs/r/datasync_task.html.markdown @@ -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).