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

r/datasync_task - add scheduling support #14452

Merged
merged 12 commits into from
May 12, 2021
7 changes: 7 additions & 0 deletions .changelog/14452.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:enhancement
resource/aws_datasync_task: Add plan time validation to `cloudwatch_log_group_arn`, `destination_location_arn` and `source_location_arn`
```

```release-note:enhancement
resource/aws_datasync_task: Add `schedule` argument
```
36 changes: 36 additions & 0 deletions aws/internal/service/datasync/finder/finder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package finder

import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/datasync"
"github.com/hashicorp/aws-sdk-go-base/tfawserr"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TaskByARN(conn *datasync.DataSync, arn string) (*datasync.DescribeTaskOutput, error) {
input := &datasync.DescribeTaskInput{
TaskArn: aws.String(arn),
}

output, err := conn.DescribeTask(input)

if tfawserr.ErrMessageContains(err, datasync.ErrCodeInvalidRequestException, "not found") {
return nil, &resource.NotFoundError{
LastError: err,
LastRequest: input,
}
}

if err != nil {
return nil, err
}

if output == nil {
return nil, &resource.NotFoundError{
Message: "Empty result",
LastRequest: input,
}
}

return output, nil
}
22 changes: 5 additions & 17 deletions aws/internal/service/datasync/waiter/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,21 @@ package waiter
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/datasync"
"github.com/hashicorp/aws-sdk-go-base/tfawserr"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/service/datasync/finder"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/tfresource"
)

const (
TaskStatusUnknown = "Unknown"
)

// TaskStatus fetches the Operation and its Status
func TaskStatus(conn *datasync.DataSync, arn string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
input := &datasync.DescribeTaskInput{
TaskArn: aws.String(arn),
}
output, err := finder.TaskByARN(conn, arn)

output, err := conn.DescribeTask(input)

if tfawserr.ErrMessageContains(err, datasync.ErrCodeInvalidRequestException, "not found") {
if tfresource.NotFound(err) {
return nil, "", nil
}

if err != nil {
return output, TaskStatusUnknown, err
}

if output == nil {
return output, TaskStatusUnknown, nil
return nil, "", err
}

return output, aws.StringValue(output.Status), nil
Expand Down
13 changes: 3 additions & 10 deletions aws/internal/service/datasync/waiter/waiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,10 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

// TaskStatusAvailable waits for a Task to return Available
func TaskStatusAvailable(conn *datasync.DataSync, arn string, timeout time.Duration) (*datasync.DescribeTaskOutput, error) {
func TaskAvailable(conn *datasync.DataSync, arn string, timeout time.Duration) (*datasync.DescribeTaskOutput, error) {
stateConf := &resource.StateChangeConf{
Pending: []string{
datasync.TaskStatusCreating,
datasync.TaskStatusUnavailable,
},
Target: []string{
datasync.TaskStatusAvailable,
datasync.TaskStatusRunning,
},
Pending: []string{datasync.TaskStatusCreating, datasync.TaskStatusUnavailable},
Target: []string{datasync.TaskStatusAvailable, datasync.TaskStatusRunning},
Refresh: TaskStatus(conn, arn),
Timeout: timeout,
}
Expand Down
Loading