From bb2b811f2ca517ef925e518474d7b2162d7cf585 Mon Sep 17 00:00:00 2001 From: DrFaust92 Date: Mon, 3 Aug 2020 17:30:00 +0300 Subject: [PATCH 1/4] add support for scheduling allow updating `cloudwatch_log_group_arn` add arn validation for `cloudwatch_log_group_arn`, `source_location_arn`, `destination_location_arn` --- aws/resource_aws_datasync_task.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/aws/resource_aws_datasync_task.go b/aws/resource_aws_datasync_task.go index 7f7baa09600..7c0d01c1d01 100644 --- a/aws/resource_aws_datasync_task.go +++ b/aws/resource_aws_datasync_task.go @@ -167,6 +167,10 @@ func resourceAwsDataSyncTaskCreate(d *schema.ResourceData, meta interface{}) err input.Schedule = expandAwsDataSyncTaskSchedule(v.([]interface{})) } + 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)) } From 665674bc60d039b154f4302264329a34efc9dd3a Mon Sep 17 00:00:00 2001 From: Gareth Oakley Date: Sun, 15 Nov 2020 12:48:28 +0000 Subject: [PATCH 2/4] resource/aws_datasync_task: Add `excludes` argument, missing `options` arguments --- aws/datasync.go | 6 + aws/resource_aws_datasync_task.go | 95 ++++++++++-- aws/resource_aws_datasync_task_test.go | 170 +++++++++++++++++++++ website/docs/r/datasync_task.html.markdown | 26 +++- 4 files changed, 286 insertions(+), 11 deletions(-) diff --git a/aws/datasync.go b/aws/datasync.go index 47db96f7999..117ede5c4ef 100644 --- a/aws/datasync.go +++ b/aws/datasync.go @@ -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)), } @@ -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), } diff --git a/aws/resource_aws_datasync_task.go b/aws/resource_aws_datasync_task.go index 7c0d01c1d01..e4f0f69b214 100644 --- a/aws/resource_aws_datasync_task.go +++ b/aws/resource_aws_datasync_task.go @@ -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, @@ -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, @@ -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, @@ -163,22 +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("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) @@ -215,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) @@ -256,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") { @@ -268,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) @@ -331,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 +} diff --git a/aws/resource_aws_datasync_task_test.go b/aws/resource_aws_datasync_task_test.go index f64498a81b9..9a889a75fb5 100644 --- a/aws/resource_aws_datasync_task_test.go +++ b/aws/resource_aws_datasync_task_test.go @@ -102,10 +102,14 @@ func TestAccAWSDataSyncTask_basic(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "options.0.atime", "BEST_EFFORT"), resource.TestCheckResourceAttr(resourceName, "options.0.bytes_per_second", "-1"), resource.TestCheckResourceAttr(resourceName, "options.0.gid", "INT_VALUE"), + resource.TestCheckResourceAttr(resourceName, "options.0.log_level", "OFF"), resource.TestCheckResourceAttr(resourceName, "options.0.mtime", "PRESERVE"), + resource.TestCheckResourceAttr(resourceName, "options.0.overwrite_mode", "ALWAYS"), resource.TestCheckResourceAttr(resourceName, "options.0.posix_permissions", "PRESERVE"), resource.TestCheckResourceAttr(resourceName, "options.0.preserve_deleted_files", "PRESERVE"), resource.TestCheckResourceAttr(resourceName, "options.0.preserve_devices", "NONE"), + resource.TestCheckResourceAttr(resourceName, "options.0.task_queueing", "ENABLED"), + resource.TestCheckResourceAttr(resourceName, "options.0.transfer_mode", "CHANGED"), resource.TestCheckResourceAttr(resourceName, "options.0.uid", "INT_VALUE"), resource.TestCheckResourceAttr(resourceName, "options.0.verify_mode", "POINT_IN_TIME_CONSISTENT"), resource.TestCheckResourceAttr(resourceName, "schedule.#", "0"), @@ -215,6 +219,43 @@ func TestAccAWSDataSyncTask_CloudWatchLogGroupARN(t *testing.T) { }) } +func TestAccAWSDataSyncTask_Excludes(t *testing.T) { + var task1 datasync.DescribeTaskOutput + rName := acctest.RandomWithPrefix("tf-acc-test") + resourceName := "aws_datasync_task.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSDataSync(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSDataSyncTaskDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSDataSyncTaskExcludesConfig(rName, "/folder1|/folder2"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSDataSyncTaskExists(resourceName, &task1), + resource.TestCheckResourceAttr(resourceName, "excludes.#", "1"), + resource.TestCheckResourceAttr(resourceName, "excludes.0.filter_type", "SIMPLE_PATTERN"), + resource.TestCheckResourceAttr(resourceName, "excludes.0.value", "/folder1|/folder2"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccAWSDataSyncTaskExcludesConfig(rName, "/test"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSDataSyncTaskExists(resourceName, &task1), + resource.TestCheckResourceAttr(resourceName, "excludes.#", "1"), + resource.TestCheckResourceAttr(resourceName, "excludes.0.filter_type", "SIMPLE_PATTERN"), + resource.TestCheckResourceAttr(resourceName, "excludes.0.value", "/test"), + ), + }, + }, + }) +} + func TestAccAWSDataSyncTask_DefaultSyncOptions_AtimeMtime(t *testing.T) { var task1, task2 datasync.DescribeTaskOutput rName := acctest.RandomWithPrefix("tf-acc-test") @@ -476,6 +517,78 @@ func TestAccAWSDataSyncTask_DefaultSyncOptions_PreserveDevices(t *testing.T) { }) } +func TestAccAWSDataSyncTask_DefaultSyncOptions_TaskQueueing(t *testing.T) { + var task1, task2 datasync.DescribeTaskOutput + rName := acctest.RandomWithPrefix("tf-acc-test") + resourceName := "aws_datasync_task.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSDataSync(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSDataSyncTaskDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSDataSyncTaskConfigDefaultSyncOptionsTaskQueueing(rName, "ENABLED"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSDataSyncTaskExists(resourceName, &task1), + resource.TestCheckResourceAttr(resourceName, "options.#", "1"), + resource.TestCheckResourceAttr(resourceName, "options.0.task_queueing", "ENABLED"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccAWSDataSyncTaskConfigDefaultSyncOptionsTaskQueueing(rName, "DISABLED"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSDataSyncTaskExists(resourceName, &task2), + testAccCheckAWSDataSyncTaskNotRecreated(&task1, &task2), + resource.TestCheckResourceAttr(resourceName, "options.#", "1"), + resource.TestCheckResourceAttr(resourceName, "options.0.task_queueing", "DISABLED"), + ), + }, + }, + }) +} + +func TestAccAWSDataSyncTask_DefaultSyncOptions_TransferMode(t *testing.T) { + var task1, task2 datasync.DescribeTaskOutput + rName := acctest.RandomWithPrefix("tf-acc-test") + resourceName := "aws_datasync_task.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSDataSync(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSDataSyncTaskDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSDataSyncTaskConfigDefaultSyncOptionsTransferMode(rName, "CHANGED"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSDataSyncTaskExists(resourceName, &task1), + resource.TestCheckResourceAttr(resourceName, "options.#", "1"), + resource.TestCheckResourceAttr(resourceName, "options.0.transfer_mode", "CHANGED"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccAWSDataSyncTaskConfigDefaultSyncOptionsTransferMode(rName, "ALL"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSDataSyncTaskExists(resourceName, &task2), + testAccCheckAWSDataSyncTaskNotRecreated(&task1, &task2), + resource.TestCheckResourceAttr(resourceName, "options.#", "1"), + resource.TestCheckResourceAttr(resourceName, "options.0.transfer_mode", "ALL"), + ), + }, + }, + }) +} + func TestAccAWSDataSyncTask_DefaultSyncOptions_Uid(t *testing.T) { var task1, task2 datasync.DescribeTaskOutput rName := acctest.RandomWithPrefix("tf-acc-test") @@ -925,6 +1038,21 @@ resource "aws_datasync_task" "test" { `, rName)) } +func testAccAWSDataSyncTaskExcludesConfig(rName, cron string) string { + return testAccAWSDataSyncTaskConfigDestinationLocationS3Base(rName) + testAccAWSDataSyncTaskConfigSourceLocationNfsBase(rName) + fmt.Sprintf(` +resource "aws_datasync_task" "test" { + destination_location_arn = aws_datasync_location_s3.destination.arn + name = %q + source_location_arn = aws_datasync_location_nfs.source.arn + + excludes { + filter_type = "SIMPLE_PATTERN" + value = %q + } +} +`, rName, cron) +} + func testAccAWSDataSyncTaskConfigDefaultSyncOptionsAtimeMtime(rName, atime, mtime string) string { return composeConfig( testAccAWSDataSyncTaskConfigDestinationLocationS3Base(rName), @@ -999,6 +1127,20 @@ resource "aws_datasync_task" "test" { `, rName, logLevel)) } +func testAccAWSDataSyncTaskConfigDefaultSyncOptionsOverwriteMode(rName, overwriteMode string) string { + return testAccAWSDataSyncTaskConfigDestinationLocationS3Base(rName) + testAccAWSDataSyncTaskConfigSourceLocationNfsBase(rName) + fmt.Sprintf(` +resource "aws_datasync_task" "test" { + destination_location_arn = aws_datasync_location_s3.destination.arn + name = %q + source_location_arn = aws_datasync_location_nfs.source.arn + + options { + overwrite_mode = %q + } +} +`, rName, overwriteMode) +} + func testAccAWSDataSyncTaskConfigDefaultSyncOptionsPosixPermissions(rName, posixPermissions string) string { return composeConfig( testAccAWSDataSyncTaskConfigDestinationLocationS3Base(rName), @@ -1050,6 +1192,34 @@ resource "aws_datasync_task" "test" { `, rName, preserveDevices)) } +func testAccAWSDataSyncTaskConfigDefaultSyncOptionsTaskQueueing(rName, taskQueueing string) string { + return testAccAWSDataSyncTaskConfigDestinationLocationS3Base(rName) + testAccAWSDataSyncTaskConfigSourceLocationNfsBase(rName) + fmt.Sprintf(` +resource "aws_datasync_task" "test" { + destination_location_arn = aws_datasync_location_s3.destination.arn + name = %q + source_location_arn = aws_datasync_location_nfs.source.arn + + options { + task_queueing = %q + } +} +`, rName, taskQueueing) +} + +func testAccAWSDataSyncTaskConfigDefaultSyncOptionsTransferMode(rName, transferMode string) string { + return testAccAWSDataSyncTaskConfigDestinationLocationS3Base(rName) + testAccAWSDataSyncTaskConfigSourceLocationNfsBase(rName) + fmt.Sprintf(` +resource "aws_datasync_task" "test" { + destination_location_arn = aws_datasync_location_s3.destination.arn + name = %q + source_location_arn = aws_datasync_location_nfs.source.arn + + options { + transfer_mode = %q + } +} +`, rName, transferMode) +} + func testAccAWSDataSyncTaskConfigDefaultSyncOptionsUid(rName, uid string) string { return composeConfig( testAccAWSDataSyncTaskConfigDestinationLocationS3Base(rName), diff --git a/website/docs/r/datasync_task.html.markdown b/website/docs/r/datasync_task.html.markdown index 8504b4007c8..374e5dfd16c 100644 --- a/website/docs/r/datasync_task.html.markdown +++ b/website/docs/r/datasync_task.html.markdown @@ -38,6 +38,21 @@ resource "aws_datasync_task" "example" { } ``` +## Example Usage with Filtering + +```hcl +resource "aws_datasync_task" "example" { + destination_location_arn = aws_datasync_location_s3.destination.arn + name = "example" + source_location_arn = aws_datasync_location_nfs.source.arn + + excludes { + filter_type = "SIMPLE_PATTERN" + value = "/folder1|/folder2" + } +} +``` + ## Argument Reference The following arguments are supported: @@ -45,6 +60,7 @@ The following arguments are supported: * `destination_location_arn` - (Required) Amazon Resource Name (ARN) of destination DataSync Location. * `source_location_arn` - (Required) Amazon Resource Name (ARN) of source DataSync Location. * `cloudwatch_log_group_arn` - (Optional) Amazon Resource Name (ARN) of the CloudWatch Log Group that is used to monitor and log events in the sync task. +* `excludes` - (Optional) Filter rules that determines which files to exclude from a task. * `name` - (Optional) Name of the DataSync Task. * `options` - (Optional) Configuration block containing option that controls the default behavior when you start an execution of this DataSync Task. For each individual task execution, you can override these options by specifying an overriding configuration in those executions. * `schedule` - (Optional) Specifies a schedule used to periodically transfer files from a source to a destination location. @@ -59,11 +75,14 @@ The following arguments are supported inside the `options` configuration block: * `atime` - (Optional) A file metadata that shows the last time a file was accessed (that is when the file was read or written to). If set to `BEST_EFFORT`, the DataSync Task attempts to preserve the original (that is, the version before sync `PREPARING` phase) `atime` attribute on all source files. Valid values: `BEST_EFFORT`, `NONE`. Default: `BEST_EFFORT`. * `bytes_per_second` - (Optional) Limits the bandwidth utilized. For example, to set a maximum of 1 MB, set this value to `1048576`. Value values: `-1` or greater. Default: `-1` (unlimited). * `gid` - (Optional) Group identifier of the file's owners. Valid values: `BOTH`, `INT_VALUE`, `NAME`, `NONE`. Default: `INT_VALUE` (preserve integer value of the ID). -* `log_level` - (Optional) Type of logs to be published to a log stream. Valid values: `OFF`, `BASIC`, `TRANSFER`. Default: `OFF`. +* `log_level` - (Optional) Determines the type of logs that DataSync publishes to a log stream in the Amazon CloudWatch log group that you provide. Valid values: `OFF`, `BASIC`, `TRANSFER`. Default: `OFF`. * `mtime` - (Optional) A file metadata that indicates the last time a file was modified (written to) before the sync `PREPARING` phase. Value values: `NONE`, `PRESERVE`. Default: `PRESERVE`. +* `overwrite_mode` - (Optional) Determines whether files at the destination should be overwritten or preserved when copying files. Valid values: `ALWAYS`, `NEVER`. Default: `ALWAYS`. * `posix_permissions` - (Optional) Determines which users or groups can access a file for a specific purpose such as reading, writing, or execution of the file. Valid values: `NONE`, `PRESERVE`. Default: `PRESERVE`. * `preserve_deleted_files` - (Optional) Whether files deleted in the source should be removed or preserved in the destination file system. Valid values: `PRESERVE`, `REMOVE`. Default: `PRESERVE`. * `preserve_devices` - (Optional) Whether the DataSync Task should preserve the metadata of block and character devices in the source files system, and recreate the files with that device name and metadata on the destination. The DataSync Task can’t sync the actual contents of such devices, because many of the devices are non-terminal and don’t return an end of file (EOF) marker. Valid values: `NONE`, `PRESERVE`. Default: `NONE` (ignore special devices). +* `task_queueing` - (Optional) Determines whether tasks should be queued before executing the tasks. Valid values: `ENABLED`, `DISABLED`. Default `ENABLED`. +* `transfer_mode` - (Optional) Determines whether DataSync transfers only the data and metadata that differ between the source and the destination location, or whether DataSync transfers all the content from the source, without comparing to the destination location. Valid values: `CHANGED`, `ALL`. Default: `CHANGED` * `uid` - (Optional) User identifier of the file's owners. Valid values: `BOTH`, `INT_VALUE`, `NAME`, `NONE`. Default: `INT_VALUE` (preserve integer value of the ID). * `verify_mode` - (Optional) Whether a data integrity verification should be performed at the end of a task execution after all data and metadata have been transferred. Valid values: `NONE`, `POINT_IN_TIME_CONSISTENT`, `ONLY_FILES_TRANSFERRED`. Default: `POINT_IN_TIME_CONSISTENT`. @@ -71,6 +90,11 @@ The following arguments are supported inside the `options` configuration block: * `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). +### excludes Argument Reference + +* `filter_type` - (Optional) The type of filter rule to apply. Valid values: `SIMPLE_PATTERN`. +* `value` - (Optional) A single filter string that consists of the patterns to include or exclude. The patterns are delimited by "|" (that is, a pipe), for example: `/folder1|/folder2` + ## Attributes Reference In addition to all arguments above, the following attributes are exported: From 2e9f6841adf78b6763aa307828bf837fe9c67aa7 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Thu, 13 May 2021 11:49:46 -0400 Subject: [PATCH 3/4] Add CHANGELOG entry. --- .changelog/16204.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/16204.txt diff --git a/.changelog/16204.txt b/.changelog/16204.txt new file mode 100644 index 00000000000..dbb30234d48 --- /dev/null +++ b/.changelog/16204.txt @@ -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 +``` \ No newline at end of file From a5921fa8200aa1db61254c772b2decfa342b309e Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Thu, 13 May 2021 12:07:34 -0400 Subject: [PATCH 4/4] Fix linter errors. --- aws/resource_aws_datasync_task_test.go | 86 +++++++++++++++++++++----- 1 file changed, 69 insertions(+), 17 deletions(-) diff --git a/aws/resource_aws_datasync_task_test.go b/aws/resource_aws_datasync_task_test.go index 9a889a75fb5..0c47730fe53 100644 --- a/aws/resource_aws_datasync_task_test.go +++ b/aws/resource_aws_datasync_task_test.go @@ -226,6 +226,7 @@ func TestAccAWSDataSyncTask_Excludes(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSDataSync(t) }, + ErrorCheck: testAccErrorCheck(t, datasync.EndpointsID), Providers: testAccProviders, CheckDestroy: testAccCheckAWSDataSyncTaskDestroy, Steps: []resource.TestStep{ @@ -406,6 +407,43 @@ func TestAccAWSDataSyncTask_DefaultSyncOptions_LogLevel(t *testing.T) { }) } +func TestAccAWSDataSyncTask_DefaultSyncOptions_OverwriteMode(t *testing.T) { + var task1, task2 datasync.DescribeTaskOutput + rName := acctest.RandomWithPrefix("tf-acc-test") + resourceName := "aws_datasync_task.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSDataSync(t) }, + ErrorCheck: testAccErrorCheck(t, datasync.EndpointsID), + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSDataSyncTaskDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSDataSyncTaskConfigDefaultSyncOptionsOverwriteMode(rName, "NEVER"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSDataSyncTaskExists(resourceName, &task1), + resource.TestCheckResourceAttr(resourceName, "options.#", "1"), + resource.TestCheckResourceAttr(resourceName, "options.0.overwrite_mode", "NEVER"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccAWSDataSyncTaskConfigDefaultSyncOptionsOverwriteMode(rName, "ALWAYS"), + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSDataSyncTaskExists(resourceName, &task2), + testAccCheckAWSDataSyncTaskNotRecreated(&task1, &task2), + resource.TestCheckResourceAttr(resourceName, "options.#", "1"), + resource.TestCheckResourceAttr(resourceName, "options.0.overwrite_mode", "ALWAYS"), + ), + }, + }, + }) +} + func TestAccAWSDataSyncTask_DefaultSyncOptions_PosixPermissions(t *testing.T) { var task1, task2 datasync.DescribeTaskOutput rName := acctest.RandomWithPrefix("tf-acc-test") @@ -524,6 +562,7 @@ func TestAccAWSDataSyncTask_DefaultSyncOptions_TaskQueueing(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSDataSync(t) }, + ErrorCheck: testAccErrorCheck(t, datasync.EndpointsID), Providers: testAccProviders, CheckDestroy: testAccCheckAWSDataSyncTaskDestroy, Steps: []resource.TestStep{ @@ -560,6 +599,7 @@ func TestAccAWSDataSyncTask_DefaultSyncOptions_TransferMode(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSDataSync(t) }, + ErrorCheck: testAccErrorCheck(t, datasync.EndpointsID), Providers: testAccProviders, CheckDestroy: testAccCheckAWSDataSyncTaskDestroy, Steps: []resource.TestStep{ @@ -1038,19 +1078,22 @@ resource "aws_datasync_task" "test" { `, rName)) } -func testAccAWSDataSyncTaskExcludesConfig(rName, cron string) string { - return testAccAWSDataSyncTaskConfigDestinationLocationS3Base(rName) + testAccAWSDataSyncTaskConfigSourceLocationNfsBase(rName) + fmt.Sprintf(` +func testAccAWSDataSyncTaskExcludesConfig(rName, value string) string { + return composeConfig( + testAccAWSDataSyncTaskConfigDestinationLocationS3Base(rName), + testAccAWSDataSyncTaskConfigSourceLocationNfsBase(rName), + fmt.Sprintf(` resource "aws_datasync_task" "test" { destination_location_arn = aws_datasync_location_s3.destination.arn - name = %q + name = %[1]q source_location_arn = aws_datasync_location_nfs.source.arn excludes { filter_type = "SIMPLE_PATTERN" - value = %q + value = %[2]q } } -`, rName, cron) +`, rName, value)) } func testAccAWSDataSyncTaskConfigDefaultSyncOptionsAtimeMtime(rName, atime, mtime string) string { @@ -1128,17 +1171,20 @@ resource "aws_datasync_task" "test" { } func testAccAWSDataSyncTaskConfigDefaultSyncOptionsOverwriteMode(rName, overwriteMode string) string { - return testAccAWSDataSyncTaskConfigDestinationLocationS3Base(rName) + testAccAWSDataSyncTaskConfigSourceLocationNfsBase(rName) + fmt.Sprintf(` + return composeConfig( + testAccAWSDataSyncTaskConfigDestinationLocationS3Base(rName), + testAccAWSDataSyncTaskConfigSourceLocationNfsBase(rName), + fmt.Sprintf(` resource "aws_datasync_task" "test" { destination_location_arn = aws_datasync_location_s3.destination.arn - name = %q + name = %[1]q source_location_arn = aws_datasync_location_nfs.source.arn options { - overwrite_mode = %q + overwrite_mode = %[2]q } } -`, rName, overwriteMode) +`, rName, overwriteMode)) } func testAccAWSDataSyncTaskConfigDefaultSyncOptionsPosixPermissions(rName, posixPermissions string) string { @@ -1193,31 +1239,37 @@ resource "aws_datasync_task" "test" { } func testAccAWSDataSyncTaskConfigDefaultSyncOptionsTaskQueueing(rName, taskQueueing string) string { - return testAccAWSDataSyncTaskConfigDestinationLocationS3Base(rName) + testAccAWSDataSyncTaskConfigSourceLocationNfsBase(rName) + fmt.Sprintf(` + return composeConfig( + testAccAWSDataSyncTaskConfigDestinationLocationS3Base(rName), + testAccAWSDataSyncTaskConfigSourceLocationNfsBase(rName), + fmt.Sprintf(` resource "aws_datasync_task" "test" { destination_location_arn = aws_datasync_location_s3.destination.arn - name = %q + name = %[1]q source_location_arn = aws_datasync_location_nfs.source.arn options { - task_queueing = %q + task_queueing = %[2]q } } -`, rName, taskQueueing) +`, rName, taskQueueing)) } func testAccAWSDataSyncTaskConfigDefaultSyncOptionsTransferMode(rName, transferMode string) string { - return testAccAWSDataSyncTaskConfigDestinationLocationS3Base(rName) + testAccAWSDataSyncTaskConfigSourceLocationNfsBase(rName) + fmt.Sprintf(` + return composeConfig( + testAccAWSDataSyncTaskConfigDestinationLocationS3Base(rName), + testAccAWSDataSyncTaskConfigSourceLocationNfsBase(rName), + fmt.Sprintf(` resource "aws_datasync_task" "test" { destination_location_arn = aws_datasync_location_s3.destination.arn - name = %q + name = %[1]q source_location_arn = aws_datasync_location_nfs.source.arn options { - transfer_mode = %q + transfer_mode = %[2]q } } -`, rName, transferMode) +`, rName, transferMode)) } func testAccAWSDataSyncTaskConfigDefaultSyncOptionsUid(rName, uid string) string {