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

resource/aws_datasync_task: Add excludes argument, missing options arguments #16204

Merged
merged 4 commits into from
May 13, 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/16204.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_datasync_task: Add `excludes` argument and `overwrite_mode`, `task_queueing`, and `transfer_mode` to the `options` configuration block
```
6 changes: 6 additions & 0 deletions aws/datasync.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,12 @@ func expandDataSyncOptions(l []interface{}) *datasync.Options {
Gid: aws.String(m["gid"].(string)),
LogLevel: aws.String(m["log_level"].(string)),
Mtime: aws.String(m["mtime"].(string)),
OverwriteMode: aws.String(m["overwrite_mode"].(string)),
PreserveDeletedFiles: aws.String(m["preserve_deleted_files"].(string)),
PreserveDevices: aws.String(m["preserve_devices"].(string)),
PosixPermissions: aws.String(m["posix_permissions"].(string)),
TaskQueueing: aws.String(m["task_queueing"].(string)),
TransferMode: aws.String(m["transfer_mode"].(string)),
Uid: aws.String(m["uid"].(string)),
VerifyMode: aws.String(m["verify_mode"].(string)),
}
Expand Down Expand Up @@ -149,9 +152,12 @@ func flattenDataSyncOptions(options *datasync.Options) []interface{} {
"gid": aws.StringValue(options.Gid),
"log_level": aws.StringValue(options.LogLevel),
"mtime": aws.StringValue(options.Mtime),
"overwrite_mode": aws.StringValue(options.OverwriteMode),
"posix_permissions": aws.StringValue(options.PosixPermissions),
"preserve_deleted_files": aws.StringValue(options.PreserveDeletedFiles),
"preserve_devices": aws.StringValue(options.PreserveDevices),
"task_queueing": aws.StringValue(options.TaskQueueing),
"transfer_mode": aws.StringValue(options.TransferMode),
"uid": aws.StringValue(options.Uid),
"verify_mode": aws.StringValue(options.VerifyMode),
}
Expand Down
91 changes: 85 additions & 6 deletions aws/resource_aws_datasync_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,24 @@ func resourceAwsDataSyncTask() *schema.Resource {
ForceNew: true,
ValidateFunc: validateArn,
},
"excludes": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"filter_type": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice(datasync.FilterType_Values(), false),
},
"value": {
Type: schema.TypeString,
Optional: true,
},
},
},
},
"name": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -86,6 +104,12 @@ func resourceAwsDataSyncTask() *schema.Resource {
Default: datasync.MtimePreserve,
ValidateFunc: validation.StringInSlice(datasync.Mtime_Values(), false),
},
"overwrite_mode": {
Type: schema.TypeString,
Optional: true,
Default: datasync.OverwriteModeAlways,
ValidateFunc: validation.StringInSlice(datasync.OverwriteMode_Values(), false),
},
"posix_permissions": {
Type: schema.TypeString,
Optional: true,
Expand All @@ -104,6 +128,18 @@ func resourceAwsDataSyncTask() *schema.Resource {
Default: datasync.PreserveDevicesNone,
ValidateFunc: validation.StringInSlice(datasync.PreserveDevices_Values(), false),
},
"task_queueing": {
Type: schema.TypeString,
Optional: true,
Default: datasync.TaskQueueingEnabled,
ValidateFunc: validation.StringInSlice(datasync.TaskQueueing_Values(), false),
},
"transfer_mode": {
Type: schema.TypeString,
Optional: true,
Default: datasync.TransferModeChanged,
ValidateFunc: validation.StringInSlice(datasync.TransferMode_Values(), false),
},
"uid": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -163,18 +199,22 @@ func resourceAwsDataSyncTaskCreate(d *schema.ResourceData, meta interface{}) err
Tags: tags.IgnoreAws().DatasyncTags(),
}

if v, ok := d.GetOk("schedule"); ok {
input.Schedule = expandAwsDataSyncTaskSchedule(v.([]interface{}))
}

if v, ok := d.GetOk("cloudwatch_log_group_arn"); ok {
input.CloudWatchLogGroupArn = aws.String(v.(string))
}

if v, ok := d.GetOk("excludes"); ok {
input.Excludes = expandAwsDataSyncFilterRules(v.([]interface{}))
}

if v, ok := d.GetOk("name"); ok {
input.Name = aws.String(v.(string))
}

if v, ok := d.GetOk("schedule"); ok {
input.Schedule = expandAwsDataSyncTaskSchedule(v.([]interface{}))
}

log.Printf("[DEBUG] Creating DataSync Task: %s", input)
output, err := conn.CreateTask(input)

Expand Down Expand Up @@ -211,6 +251,9 @@ func resourceAwsDataSyncTaskRead(d *schema.ResourceData, meta interface{}) error
d.Set("arn", output.TaskArn)
d.Set("cloudwatch_log_group_arn", output.CloudWatchLogGroupArn)
d.Set("destination_location_arn", output.DestinationLocationArn)
if err := d.Set("excludes", flattenAwsDataSyncFilterRules(output.Excludes)); err != nil {
return fmt.Errorf("error setting excludes: %w", err)
}
d.Set("name", output.Name)
if err := d.Set("options", flattenDataSyncOptions(output.Options)); err != nil {
return fmt.Errorf("error setting options: %w", err)
Expand Down Expand Up @@ -252,8 +295,8 @@ func resourceAwsDataSyncTaskUpdate(d *schema.ResourceData, meta interface{}) err
input.CloudWatchLogGroupArn = aws.String(d.Get("cloudwatch_log_group_arn").(string))
}

if d.HasChanges("schedule") {
input.Schedule = expandAwsDataSyncTaskSchedule(d.Get("schedule").([]interface{}))
if d.HasChanges("excludes") {
input.Excludes = expandAwsDataSyncFilterRules(d.Get("excludes").([]interface{}))
}

if d.HasChanges("name") {
Expand All @@ -264,6 +307,10 @@ func resourceAwsDataSyncTaskUpdate(d *schema.ResourceData, meta interface{}) err
input.Options = expandDataSyncOptions(d.Get("options").([]interface{}))
}

if d.HasChanges("schedule") {
input.Schedule = expandAwsDataSyncTaskSchedule(d.Get("schedule").([]interface{}))
}

log.Printf("[DEBUG] Updating DataSync Task: %s", input)
if _, err := conn.UpdateTask(input); err != nil {
return fmt.Errorf("error updating DataSync Task (%s): %w", d.Id(), err)
Expand Down Expand Up @@ -327,3 +374,35 @@ func flattenAwsDataSyncTaskSchedule(schedule *datasync.TaskSchedule) []interface

return []interface{}{m}
}

func expandAwsDataSyncFilterRules(l []interface{}) []*datasync.FilterRule {
filterRules := []*datasync.FilterRule{}

for _, mRaw := range l {
if mRaw == nil {
continue
}
m := mRaw.(map[string]interface{})
filterRule := &datasync.FilterRule{
FilterType: aws.String(m["filter_type"].(string)),
Value: aws.String(m["value"].(string)),
}
filterRules = append(filterRules, filterRule)
}

return filterRules
}

func flattenAwsDataSyncFilterRules(filterRules []*datasync.FilterRule) []interface{} {
l := []interface{}{}

for _, filterRule := range filterRules {
m := map[string]interface{}{
"filter_type": aws.StringValue(filterRule.FilterType),
"value": aws.StringValue(filterRule.Value),
}
l = append(l, m)
}

return l
}
Loading