diff --git a/internal/service/redshift/cluster_test.go b/internal/service/redshift/cluster_test.go index 1586e975246..4f061156829 100644 --- a/internal/service/redshift/cluster_test.go +++ b/internal/service/redshift/cluster_test.go @@ -547,7 +547,7 @@ func TestAccRedshiftCluster_changeAvailabilityZone_availabilityZoneRelocationNot }, { Config: testAccClusterConfig_updateAvailabilityZone_availabilityZoneRelocationNotSet(rName, 1), - ExpectError: regexp.MustCompile(`cannot change availability_zone if availability_zone_relocation_enabled is not true`), + ExpectError: regexp.MustCompile("cannot change `availability_zone` if `availability_zone_relocation_enabled` is not true"), }, }, }) @@ -663,7 +663,7 @@ func TestAccRedshiftCluster_availabilityZoneRelocation_publiclyAccessible(t *tes Steps: []resource.TestStep{ { Config: testAccClusterConfig_availabilityZoneRelocation_publiclyAccessible(rName), - ExpectError: regexp.MustCompile(`availability_zone_relocation_enabled can not be true when publicly_accessible is true`), + ExpectError: regexp.MustCompile("`availability_zone_relocation_enabled` cannot be true when `publicly_accessible` is true"), }, }, }) diff --git a/internal/service/redshift/enum.go b/internal/service/redshift/enum.go index 1dc10a665b1..2acaa786891 100644 --- a/internal/service/redshift/enum.go +++ b/internal/service/redshift/enum.go @@ -1,5 +1,13 @@ package redshift +const ( + clusterAvailabilityStatusAvailable = "Available" + clusterAvailabilityStatusFailed = "Failed" + clusterAvailabilityStatusMaintenance = "Maintenance" + clusterAvailabilityStatusModifying = "Modifying" + clusterAvailabilityStatusUnavailable = "Unavailable" +) + // https://docs.aws.amazon.com/redshift/latest/mgmt/working-with-clusters.html#rs-mgmt-cluster-status. //nolint:deadcode,varcheck // These constants are missing from the AWS SDK const ( diff --git a/internal/service/redshift/status.go b/internal/service/redshift/status.go index 63898f2afa6..6678b020fb5 100644 --- a/internal/service/redshift/status.go +++ b/internal/service/redshift/status.go @@ -23,6 +23,22 @@ func statusCluster(conn *redshift.Redshift, id string) resource.StateRefreshFunc } } +func statusClusterAvailability(conn *redshift.Redshift, id string) resource.StateRefreshFunc { + return func() (interface{}, string, error) { + output, err := FindClusterByID(conn, id) + + if tfresource.NotFound(err) { + return nil, "", nil + } + + if err != nil { + return nil, "", err + } + + return output, aws.StringValue(output.ClusterAvailabilityStatus), nil + } +} + func statusClusterAvailabilityZoneRelocation(conn *redshift.Redshift, id string) resource.StateRefreshFunc { return func() (interface{}, string, error) { output, err := FindClusterByID(conn, id) diff --git a/internal/service/redshift/wait.go b/internal/service/redshift/wait.go index b9fc5c96a5d..7132ef732c5 100644 --- a/internal/service/redshift/wait.go +++ b/internal/service/redshift/wait.go @@ -1,10 +1,13 @@ package redshift import ( + "errors" "time" + "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/redshift" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-provider-aws/internal/tfresource" ) const ( @@ -15,15 +18,9 @@ const ( func waitClusterCreated(conn *redshift.Redshift, id string, timeout time.Duration) (*redshift.Cluster, error) { stateConf := &resource.StateChangeConf{ - Pending: []string{ - clusterStatusAvailablePrepForResize, - clusterStatusBackingUp, - clusterStatusCreating, - clusterStatusModifying, - clusterStatusRestoring, - }, - Target: []string{clusterStatusAvailable}, - Refresh: statusCluster(conn, id), + Pending: []string{clusterAvailabilityStatusModifying}, + Target: []string{clusterAvailabilityStatusAvailable}, + Refresh: statusClusterAvailability(conn, id), Timeout: timeout, MinTimeout: 10 * time.Second, } @@ -31,6 +28,8 @@ func waitClusterCreated(conn *redshift.Redshift, id string, timeout time.Duratio outputRaw, err := stateConf.WaitForState() if output, ok := outputRaw.(*redshift.Cluster); ok { + tfresource.SetLastError(err, errors.New(aws.StringValue(output.ClusterStatus))) + return output, err } @@ -39,23 +38,17 @@ func waitClusterCreated(conn *redshift.Redshift, id string, timeout time.Duratio func waitClusterDeleted(conn *redshift.Redshift, id string, timeout time.Duration) (*redshift.Cluster, error) { stateConf := &resource.StateChangeConf{ - Pending: []string{ - clusterStatusAvailable, - clusterStatusCreating, - clusterStatusDeleting, - clusterStatusFinalSnapshot, - clusterStatusRebooting, - clusterStatusRenaming, - clusterStatusResizing, - }, + Pending: []string{clusterAvailabilityStatusModifying}, Target: []string{}, - Refresh: statusCluster(conn, id), + Refresh: statusClusterAvailability(conn, id), Timeout: timeout, } outputRaw, err := stateConf.WaitForState() if output, ok := outputRaw.(*redshift.Cluster); ok { + tfresource.SetLastError(err, errors.New(aws.StringValue(output.ClusterStatus))) + return output, err } @@ -64,24 +57,17 @@ func waitClusterDeleted(conn *redshift.Redshift, id string, timeout time.Duratio func waitClusterUpdated(conn *redshift.Redshift, id string, timeout time.Duration) (*redshift.Cluster, error) { stateConf := &resource.StateChangeConf{ - Pending: []string{ - clusterStatusAvailablePrepForResize, - clusterStatusCreating, - clusterStatusDeleting, - clusterStatusModifying, - clusterStatusRebooting, - clusterStatusRecovering, - clusterStatusRenaming, - clusterStatusResizing, - }, - Target: []string{clusterStatusAvailable}, - Refresh: statusCluster(conn, id), + Pending: []string{clusterAvailabilityStatusMaintenance, clusterAvailabilityStatusModifying, clusterAvailabilityStatusUnavailable}, + Target: []string{clusterAvailabilityStatusAvailable}, + Refresh: statusClusterAvailability(conn, id), Timeout: timeout, } outputRaw, err := stateConf.WaitForState() if output, ok := outputRaw.(*redshift.Cluster); ok { + tfresource.SetLastError(err, errors.New(aws.StringValue(output.ClusterStatus))) + return output, err }