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

Add timeout to aws_redshiftserverless_workgroup #31054

Merged
merged 7 commits into from
May 4, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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/31054.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_redshiftserverless_workgroup: Add support for defining custom timeouts
```
4 changes: 2 additions & 2 deletions internal/service/redshiftserverless/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func waitNamespaceUpdated(ctx context.Context, conn *redshiftserverless.Redshift
return nil, err
}

func waitWorkgroupAvailable(ctx context.Context, conn *redshiftserverless.RedshiftServerless, name string) (*redshiftserverless.Workgroup, error) { //nolint:unparam
func waitWorkgroupAvailable(ctx context.Context, conn *redshiftserverless.RedshiftServerless, name string, wait time.Duration) (*redshiftserverless.Workgroup, error) { //nolint:unparam
stateConf := &retry.StateChangeConf{
Pending: []string{
redshiftserverless.WorkgroupStatusCreating,
Expand All @@ -70,7 +70,7 @@ func waitWorkgroupAvailable(ctx context.Context, conn *redshiftserverless.Redshi
return nil, err
}

func waitWorkgroupDeleted(ctx context.Context, conn *redshiftserverless.RedshiftServerless, name string) (*redshiftserverless.Workgroup, error) {
func waitWorkgroupDeleted(ctx context.Context, conn *redshiftserverless.RedshiftServerless, name string, wait time.Duration) (*redshiftserverless.Workgroup, error) {
stateConf := &retry.StateChangeConf{
Pending: []string{
redshiftserverless.WorkgroupStatusModifying,
Expand Down
12 changes: 9 additions & 3 deletions internal/service/redshiftserverless/workgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ func ResourceWorkgroup() *schema.Resource {
UpdateWithoutTimeout: resourceWorkgroupUpdate,
DeleteWithoutTimeout: resourceWorkgroupDelete,

Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(20 * time.Minute),
Update: schema.DefaultTimeout(20 * time.Minute),
Delete: schema.DefaultTimeout(20 * time.Minute),
},

Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},
Expand Down Expand Up @@ -205,7 +211,7 @@ func resourceWorkgroupCreate(ctx context.Context, d *schema.ResourceData, meta i

d.SetId(aws.StringValue(out.Workgroup.WorkgroupName))

if _, err := waitWorkgroupAvailable(ctx, conn, d.Id()); err != nil {
if _, err := waitWorkgroupAvailable(ctx, conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil {
return sdkdiag.AppendErrorf(diags, "waiting for Redshift Serverless Workgroup (%s) to be created: %s", d.Id(), err)
}

Expand Down Expand Up @@ -286,7 +292,7 @@ func resourceWorkgroupUpdate(ctx context.Context, d *schema.ResourceData, meta i
return sdkdiag.AppendErrorf(diags, "updating Redshift Serverless Workgroup (%s): %s", d.Id(), err)
}

if _, err := waitWorkgroupAvailable(ctx, conn, d.Id()); err != nil {
if _, err := waitWorkgroupAvailable(ctx, conn, d.Id(), d.Timeout(schema.TimeoutUpdate)); err != nil {
return sdkdiag.AppendErrorf(diags, "waiting for Redshift Serverless Workgroup (%s) to be updated: %s", d.Id(), err)
}
}
Expand Down Expand Up @@ -314,7 +320,7 @@ func resourceWorkgroupDelete(ctx context.Context, d *schema.ResourceData, meta i
return sdkdiag.AppendErrorf(diags, "deleting Redshift Serverless Workgroup (%s): %s", d.Id(), err)
}

if _, err := waitWorkgroupDeleted(ctx, conn, d.Id()); err != nil {
if _, err := waitWorkgroupDeleted(ctx, conn, d.Id(), d.Timeout(schema.TimeoutDelete)); err != nil {
return sdkdiag.AppendErrorf(diags, "deleting Redshift Serverless Workgroup (%s): waiting for completion: %s", d.Id(), err)
}

Expand Down
5 changes: 5 additions & 0 deletions internal/service/redshiftserverless/workgroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ resource "aws_redshiftserverless_namespace" "test" {
resource "aws_redshiftserverless_workgroup" "test" {
namespace_name = aws_redshiftserverless_namespace.test.namespace_name
workgroup_name = %[1]q

# Specify a timeout to ensure the schema is defined properly
timeouts {
create = "60m"
}
}
`, rName)
}
Expand Down