-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21093 from hashicorp/f_quicksight_data_source_res…
…ource add quicksight data source resource
- Loading branch information
Showing
7 changed files
with
2,733 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:new-resource | ||
aws_quicksight_data_source | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.