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

Feature/datasync task includes filter #25929

Merged
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/25929.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_datasync_task: Add `includes` argument
```
29 changes: 29 additions & 0 deletions internal/service/datasync/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,24 @@ func ResourceTask() *schema.Resource {
},
},
},
"includes": {
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 @@ -208,6 +226,10 @@ func resourceTaskCreate(d *schema.ResourceData, meta interface{}) error {
input.Excludes = expandFilterRules(v.([]interface{}))
}

if v, ok := d.GetOk("includes"); ok {
input.Includes = expandFilterRules(v.([]interface{}))
}

if v, ok := d.GetOk("name"); ok {
input.Name = aws.String(v.(string))
}
Expand Down Expand Up @@ -255,6 +277,9 @@ func resourceTaskRead(d *schema.ResourceData, meta interface{}) error {
if err := d.Set("excludes", flattenFilterRules(output.Excludes)); err != nil {
return fmt.Errorf("error setting excludes: %w", err)
}
if err := d.Set("includes", flattenFilterRules(output.Includes)); err != nil {
return fmt.Errorf("error setting includes: %w", err)
}
d.Set("name", output.Name)
if err := d.Set("options", flattenOptions(output.Options)); err != nil {
return fmt.Errorf("error setting options: %w", err)
Expand Down Expand Up @@ -300,6 +325,10 @@ func resourceTaskUpdate(d *schema.ResourceData, meta interface{}) error {
input.Excludes = expandFilterRules(d.Get("excludes").([]interface{}))
}

if d.HasChanges("includes") {
input.Includes = expandFilterRules(d.Get("includes").([]interface{}))
}

if d.HasChanges("name") {
input.Name = aws.String(d.Get("name").(string))
}
Expand Down
58 changes: 58 additions & 0 deletions internal/service/datasync/task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ func TestAccDataSyncTask_basic(t *testing.T) {
acctest.MatchResourceAttrRegionalARN(resourceName, "arn", "datasync", regexp.MustCompile(`task/task-.+`)),
resource.TestCheckResourceAttr(resourceName, "cloudwatch_log_group_arn", ""),
resource.TestCheckResourceAttrPair(resourceName, "destination_location_arn", dataSyncDestinationLocationResourceName, "arn"),
resource.TestCheckResourceAttr(resourceName, "excludes.#", "0"),
resource.TestCheckResourceAttr(resourceName, "includes.#", "0"),
resource.TestCheckResourceAttr(resourceName, "name", rName),
resource.TestCheckResourceAttr(resourceName, "options.#", "1"),
resource.TestCheckResourceAttr(resourceName, "options.0.atime", "BEST_EFFORT"),
Expand Down Expand Up @@ -197,6 +199,44 @@ func TestAccDataSyncTask_excludes(t *testing.T) {
})
}

func TestAccDataSyncTask_includes(t *testing.T) {
var task1 datasync.DescribeTaskOutput
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_datasync_task.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t); testAccPreCheck(t) },
ErrorCheck: acctest.ErrorCheck(t, datasync.EndpointsID),
ProviderFactories: acctest.ProviderFactories,
CheckDestroy: testAccCheckTaskDestroy,
Steps: []resource.TestStep{
{
Config: testAccTaskConfig_includes(rName, "/folder1|/folder2"),
Check: resource.ComposeTestCheckFunc(
testAccCheckTaskExists(resourceName, &task1),
resource.TestCheckResourceAttr(resourceName, "includes.#", "1"),
resource.TestCheckResourceAttr(resourceName, "includes.0.filter_type", "SIMPLE_PATTERN"),
resource.TestCheckResourceAttr(resourceName, "includes.0.value", "/folder1|/folder2"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccTaskConfig_includes(rName, "/test"),
Check: resource.ComposeTestCheckFunc(
testAccCheckTaskExists(resourceName, &task1),
resource.TestCheckResourceAttr(resourceName, "includes.#", "1"),
resource.TestCheckResourceAttr(resourceName, "includes.0.filter_type", "SIMPLE_PATTERN"),
resource.TestCheckResourceAttr(resourceName, "includes.0.value", "/test"),
),
},
},
})
}

func TestAccDataSyncTask_DefaultSyncOptions_atimeMtime(t *testing.T) {
var task1, task2 datasync.DescribeTaskOutput
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
Expand Down Expand Up @@ -1036,6 +1076,24 @@ resource "aws_datasync_task" "test" {
`, rName, value))
}

func testAccTaskConfig_includes(rName, value string) string {
return acctest.ConfigCompose(
testAccTaskDestinationLocationS3BaseConfig(rName),
testAccTaskSourceLocationNFSBaseConfig(rName),
fmt.Sprintf(`
resource "aws_datasync_task" "test" {
destination_location_arn = aws_datasync_location_s3.destination.arn
name = %[1]q
source_location_arn = aws_datasync_location_nfs.source.arn

includes {
filter_type = "SIMPLE_PATTERN"
value = %[2]q
}
}
`, rName, value))
}

func testAccTaskConfig_defaultSyncOptionsAtimeMtime(rName, atime, mtime string) string {
return acctest.ConfigCompose(
testAccTaskDestinationLocationS3BaseConfig(rName),
Expand Down
13 changes: 12 additions & 1 deletion website/docs/r/datasync_task.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ resource "aws_datasync_task" "example" {
filter_type = "SIMPLE_PATTERN"
value = "/folder1|/folder2"
}

includes {
filter_type = "SIMPLE_PATTERN"
value = "/folder1|/folder2"
}
}
```

Expand All @@ -61,6 +66,7 @@ The following arguments are supported:
* `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.
* `includes` - (Optional) Filter rules that determines which files to include in 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.
Expand Down Expand Up @@ -93,7 +99,12 @@ The following arguments are supported inside the `options` configuration block:
### 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`
* `value` - (Optional) A single filter string that consists of the patterns to exclude. The patterns are delimited by "|" (that is, a pipe), for example: `/folder1|/folder2`

### includes 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. The patterns are delimited by "|" (that is, a pipe), for example: `/folder1|/folder2`

## Attributes Reference

Expand Down