Skip to content

Commit b07a09e

Browse files
shuichiro-makigakiMatthew Sherbourne
authored and
Matthew Sherbourne
committed
Add support for include filters in AWS DataSync task
Closes hashicorp#20849
1 parent 0f825e7 commit b07a09e

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed

internal/service/datasync/task.go

+29
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,24 @@ func ResourceTask() *schema.Resource {
6464
},
6565
},
6666
},
67+
"includes": {
68+
Type: schema.TypeList,
69+
Optional: true,
70+
MaxItems: 1,
71+
Elem: &schema.Resource{
72+
Schema: map[string]*schema.Schema{
73+
"filter_type": {
74+
Type: schema.TypeString,
75+
Optional: true,
76+
ValidateFunc: validation.StringInSlice(datasync.FilterType_Values(), false),
77+
},
78+
"value": {
79+
Type: schema.TypeString,
80+
Optional: true,
81+
},
82+
},
83+
},
84+
},
6785
"name": {
6886
Type: schema.TypeString,
6987
Optional: true,
@@ -208,6 +226,10 @@ func resourceTaskCreate(d *schema.ResourceData, meta interface{}) error {
208226
input.Excludes = expandFilterRules(v.([]interface{}))
209227
}
210228

229+
if v, ok := d.GetOk("includes"); ok {
230+
input.Includes = expandFilterRules(v.([]interface{}))
231+
}
232+
211233
if v, ok := d.GetOk("name"); ok {
212234
input.Name = aws.String(v.(string))
213235
}
@@ -255,6 +277,9 @@ func resourceTaskRead(d *schema.ResourceData, meta interface{}) error {
255277
if err := d.Set("excludes", flattenFilterRules(output.Excludes)); err != nil {
256278
return fmt.Errorf("error setting excludes: %w", err)
257279
}
280+
if err := d.Set("includes", flattenFilterRules(output.Includes)); err != nil {
281+
return fmt.Errorf("error setting includes: %w", err)
282+
}
258283
d.Set("name", output.Name)
259284
if err := d.Set("options", flattenOptions(output.Options)); err != nil {
260285
return fmt.Errorf("error setting options: %w", err)
@@ -300,6 +325,10 @@ func resourceTaskUpdate(d *schema.ResourceData, meta interface{}) error {
300325
input.Excludes = expandFilterRules(d.Get("excludes").([]interface{}))
301326
}
302327

328+
if d.HasChanges("includes") {
329+
input.Includes = expandFilterRules(d.Get("includes").([]interface{}))
330+
}
331+
303332
if d.HasChanges("name") {
304333
input.Name = aws.String(d.Get("name").(string))
305334
}

internal/service/datasync/task_test.go

+38
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,44 @@ func TestAccDataSyncTask_excludes(t *testing.T) {
197197
})
198198
}
199199

200+
func TestAccDataSyncTask_includes(t *testing.T) {
201+
var task1 datasync.DescribeTaskOutput
202+
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
203+
resourceName := "aws_datasync_task.test"
204+
205+
resource.ParallelTest(t, resource.TestCase{
206+
PreCheck: func() { acctest.PreCheck(t); testAccPreCheck(t) },
207+
ErrorCheck: acctest.ErrorCheck(t, datasync.EndpointsID),
208+
Providers: acctest.Providers,
209+
CheckDestroy: testAccCheckTaskDestroy,
210+
Steps: []resource.TestStep{
211+
{
212+
Config: testAccTaskIncludesConfig(rName, "/folder1|/folder2"),
213+
Check: resource.ComposeTestCheckFunc(
214+
testAccCheckTaskExists(resourceName, &task1),
215+
resource.TestCheckResourceAttr(resourceName, "includes.#", "1"),
216+
resource.TestCheckResourceAttr(resourceName, "includes.0.filter_type", "SIMPLE_PATTERN"),
217+
resource.TestCheckResourceAttr(resourceName, "includes.0.value", "/folder1|/folder2"),
218+
),
219+
},
220+
{
221+
ResourceName: resourceName,
222+
ImportState: true,
223+
ImportStateVerify: true,
224+
},
225+
{
226+
Config: testAccTaskIncludesConfig(rName, "/test"),
227+
Check: resource.ComposeTestCheckFunc(
228+
testAccCheckTaskExists(resourceName, &task1),
229+
resource.TestCheckResourceAttr(resourceName, "includes.#", "1"),
230+
resource.TestCheckResourceAttr(resourceName, "includes.0.filter_type", "SIMPLE_PATTERN"),
231+
resource.TestCheckResourceAttr(resourceName, "includes.0.value", "/test"),
232+
),
233+
},
234+
},
235+
})
236+
}
237+
200238
func TestAccDataSyncTask_DefaultSyncOptions_atimeMtime(t *testing.T) {
201239
var task1, task2 datasync.DescribeTaskOutput
202240
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)

website/docs/r/datasync_task.html.markdown

+6
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ resource "aws_datasync_task" "example" {
5050
filter_type = "SIMPLE_PATTERN"
5151
value = "/folder1|/folder2"
5252
}
53+
54+
includes {
55+
filter_type = "SIMPLE_PATTERN"
56+
value = "/folder1|/folder2"
57+
}
5358
}
5459
```
5560

@@ -61,6 +66,7 @@ The following arguments are supported:
6166
* `source_location_arn` - (Required) Amazon Resource Name (ARN) of source DataSync Location.
6267
* `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.
6368
* `excludes` - (Optional) Filter rules that determines which files to exclude from a task.
69+
* `includes` - (Optional) Filter rules that determines which files to include in a task.
6470
* `name` - (Optional) Name of the DataSync Task.
6571
* `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.
6672
* `schedule` - (Optional) Specifies a schedule used to periodically transfer files from a source to a destination location.

0 commit comments

Comments
 (0)