Skip to content

Commit

Permalink
Merge pull request #21093 from hashicorp/f_quicksight_data_source_res…
Browse files Browse the repository at this point in the history
…ource

add quicksight data source resource
  • Loading branch information
anGie44 authored Sep 30, 2021
2 parents 00625e6 + e2672ff commit 7a9c313
Show file tree
Hide file tree
Showing 7 changed files with 2,733 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/20710.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-resource
aws_quicksight_data_source
```
31 changes: 31 additions & 0 deletions aws/internal/service/quicksight/waiter/status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package waiter

import (
"context"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/quicksight"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

// DataSourceStatus fetches the DataSource and its Status
func DataSourceStatus(ctx context.Context, conn *quicksight.QuickSight, accountId, datasourceId string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
input := &quicksight.DescribeDataSourceInput{
AwsAccountId: aws.String(accountId),
DataSourceId: aws.String(datasourceId),
}

output, err := conn.DescribeDataSourceWithContext(ctx, input)

if err != nil {
return nil, "", err
}

if output == nil || output.DataSource == nil {
return nil, "", nil
}

return output.DataSource, aws.StringValue(output.DataSource.Status), nil
}
}
61 changes: 61 additions & 0 deletions aws/internal/service/quicksight/waiter/waiter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package waiter

import (
"context"
"fmt"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/quicksight"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/tfresource"
)

const (
DataSourceCreateTimeout = 5 * time.Minute
DataSourceUpdateTimeout = 5 * time.Minute
)

// DataSourceCreated waits for a DataSource to return CREATION_SUCCESSFUL
func DataSourceCreated(ctx context.Context, conn *quicksight.QuickSight, accountId, dataSourceId string) (*quicksight.DataSource, error) {
stateConf := &resource.StateChangeConf{
Pending: []string{quicksight.ResourceStatusCreationInProgress},
Target: []string{quicksight.ResourceStatusCreationSuccessful},
Refresh: DataSourceStatus(ctx, conn, accountId, dataSourceId),
Timeout: DataSourceCreateTimeout,
}

outputRaw, err := stateConf.WaitForState()

if output, ok := outputRaw.(*quicksight.DataSource); ok {
if status, errorInfo := aws.StringValue(output.Status), output.ErrorInfo; status == quicksight.ResourceStatusCreationFailed && errorInfo != nil {
tfresource.SetLastError(err, fmt.Errorf("%s: %s", aws.StringValue(errorInfo.Type), aws.StringValue(errorInfo.Message)))
}

return output, err
}

return nil, err
}

// DataSourceUpdated waits for a DataSource to return UPDATE_SUCCESSFUL
func DataSourceUpdated(ctx context.Context, conn *quicksight.QuickSight, accountId, dataSourceId string) (*quicksight.DataSource, error) {
stateConf := &resource.StateChangeConf{
Pending: []string{quicksight.ResourceStatusUpdateInProgress},
Target: []string{quicksight.ResourceStatusUpdateSuccessful},
Refresh: DataSourceStatus(ctx, conn, accountId, dataSourceId),
Timeout: DataSourceUpdateTimeout,
}

outputRaw, err := stateConf.WaitForState()

if output, ok := outputRaw.(*quicksight.DataSource); ok {
if status, errorInfo := aws.StringValue(output.Status), output.ErrorInfo; status == quicksight.ResourceStatusUpdateFailed && errorInfo != nil {
tfresource.SetLastError(err, fmt.Errorf("%s: %s", aws.StringValue(errorInfo.Type), aws.StringValue(errorInfo.Message)))
}

return output, err
}

return nil, err
}
1 change: 1 addition & 0 deletions aws/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,7 @@ func Provider() *schema.Provider {
"aws_prometheus_workspace": resourceAwsPrometheusWorkspace(),
"aws_proxy_protocol_policy": resourceAwsProxyProtocolPolicy(),
"aws_qldb_ledger": resourceAwsQLDBLedger(),
"aws_quicksight_data_source": resourceAwsQuickSightDataSource(),
"aws_quicksight_group": resourceAwsQuickSightGroup(),
"aws_quicksight_group_membership": resourceAwsQuickSightGroupMembership(),
"aws_quicksight_user": resourceAwsQuickSightUser(),
Expand Down
Loading

0 comments on commit 7a9c313

Please sign in to comment.