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/aws_redshiftserverless_workgroup: Workgroup may be AVAILABLE when deletion starts #32067

Merged
merged 2 commits into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from all 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/32067.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_redshiftserverless_workgroup: Fix `waiting for completion: unexpected state 'AVAILABLE'` errors when deleting resource
```
25 changes: 0 additions & 25 deletions internal/service/redshiftserverless/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,31 +35,6 @@ func FindNamespaceByName(ctx context.Context, conn *redshiftserverless.RedshiftS
return output.Namespace, nil
}

func FindWorkgroupByName(ctx context.Context, conn *redshiftserverless.RedshiftServerless, name string) (*redshiftserverless.Workgroup, error) {
input := &redshiftserverless.GetWorkgroupInput{
WorkgroupName: aws.String(name),
}

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

if tfawserr.ErrCodeEquals(err, redshiftserverless.ErrCodeResourceNotFoundException) {
return nil, &retry.NotFoundError{
LastError: err,
LastRequest: input,
}
}

if err != nil {
return nil, err
}

if output == nil {
return nil, tfresource.NewEmptyResultError(input)
}

return output.Workgroup, nil
}

func FindEndpointAccessByName(ctx context.Context, conn *redshiftserverless.RedshiftServerless, name string) (*redshiftserverless.EndpointAccess, error) {
input := &redshiftserverless.GetEndpointAccessInput{
EndpointName: aws.String(name),
Expand Down
16 changes: 0 additions & 16 deletions internal/service/redshiftserverless/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,6 @@ func statusNamespace(ctx context.Context, conn *redshiftserverless.RedshiftServe
}
}

func statusWorkgroup(ctx context.Context, conn *redshiftserverless.RedshiftServerless, name string) retry.StateRefreshFunc {
return func() (interface{}, string, error) {
output, err := FindWorkgroupByName(ctx, conn, name)

if tfresource.NotFound(err) {
return nil, "", nil
}

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

return output, aws.StringValue(output.Status), nil
}
}

func statusEndpointAccess(ctx context.Context, conn *redshiftserverless.RedshiftServerless, name string) retry.StateRefreshFunc {
return func() (interface{}, string, error) {
output, err := FindEndpointAccessByName(ctx, conn, name)
Expand Down
42 changes: 0 additions & 42 deletions internal/service/redshiftserverless/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,48 +48,6 @@ func waitNamespaceUpdated(ctx context.Context, conn *redshiftserverless.Redshift
return nil, err
}

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,
redshiftserverless.WorkgroupStatusModifying,
},
Target: []string{
redshiftserverless.WorkgroupStatusAvailable,
},
Refresh: statusWorkgroup(ctx, conn, name),
Timeout: wait,
}

outputRaw, err := stateConf.WaitForStateContext(ctx)

if output, ok := outputRaw.(*redshiftserverless.Workgroup); ok {
return output, err
}

return nil, err
}

func waitWorkgroupDeleted(ctx context.Context, conn *redshiftserverless.RedshiftServerless, name string, wait time.Duration) (*redshiftserverless.Workgroup, error) {
stateConf := &retry.StateChangeConf{
Pending: []string{
redshiftserverless.WorkgroupStatusModifying,
redshiftserverless.WorkgroupStatusDeleting,
},
Target: []string{},
Refresh: statusWorkgroup(ctx, conn, name),
Timeout: wait,
}

outputRaw, err := stateConf.WaitForStateContext(ctx)

if output, ok := outputRaw.(*redshiftserverless.Workgroup); ok {
return output, err
}

return nil, err
}

func waitEndpointAccessActive(ctx context.Context, conn *redshiftserverless.RedshiftServerless, name string) (*redshiftserverless.EndpointAccess, error) { //nolint:unparam
stateConf := &retry.StateChangeConf{
Pending: []string{
Expand Down
76 changes: 76 additions & 0 deletions internal/service/redshiftserverless/workgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/aws/aws-sdk-go/service/redshiftserverless"
"github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
Expand Down Expand Up @@ -393,6 +394,81 @@ func updateWorkgroup(ctx context.Context, conn *redshiftserverless.RedshiftServe
return nil
}

func FindWorkgroupByName(ctx context.Context, conn *redshiftserverless.RedshiftServerless, name string) (*redshiftserverless.Workgroup, error) {
input := &redshiftserverless.GetWorkgroupInput{
WorkgroupName: aws.String(name),
}

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

if tfawserr.ErrCodeEquals(err, redshiftserverless.ErrCodeResourceNotFoundException) {
return nil, &retry.NotFoundError{
LastError: err,
LastRequest: input,
}
}

if err != nil {
return nil, err
}

if output == nil {
return nil, tfresource.NewEmptyResultError(input)
}

return output.Workgroup, nil
}

func statusWorkgroup(ctx context.Context, conn *redshiftserverless.RedshiftServerless, name string) retry.StateRefreshFunc {
return func() (interface{}, string, error) {
output, err := FindWorkgroupByName(ctx, conn, name)

if tfresource.NotFound(err) {
return nil, "", nil
}

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

return output, aws.StringValue(output.Status), nil
}
}

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, redshiftserverless.WorkgroupStatusModifying},
Target: []string{redshiftserverless.WorkgroupStatusAvailable},
Refresh: statusWorkgroup(ctx, conn, name),
Timeout: wait,
}

outputRaw, err := stateConf.WaitForStateContext(ctx)

if output, ok := outputRaw.(*redshiftserverless.Workgroup); ok {
return output, err
}

return nil, err
}

func waitWorkgroupDeleted(ctx context.Context, conn *redshiftserverless.RedshiftServerless, name string, wait time.Duration) (*redshiftserverless.Workgroup, error) {
stateConf := &retry.StateChangeConf{
Pending: []string{redshiftserverless.WorkgroupStatusAvailable, redshiftserverless.WorkgroupStatusModifying, redshiftserverless.WorkgroupStatusDeleting},
Target: []string{},
Refresh: statusWorkgroup(ctx, conn, name),
Timeout: wait,
}

outputRaw, err := stateConf.WaitForStateContext(ctx)

if output, ok := outputRaw.(*redshiftserverless.Workgroup); ok {
return output, err
}

return nil, err
}

func expandConfigParameter(tfMap map[string]interface{}) *redshiftserverless.ConfigParameter {
if tfMap == nil {
return nil
Expand Down