Skip to content

Commit

Permalink
r/aws_redshift_cluster: 'cluster_node_ips' -> 'cluster_nodes'.
Browse files Browse the repository at this point in the history
  • Loading branch information
ewbankkit committed Aug 31, 2021
1 parent ff74097 commit 96ba48e
Show file tree
Hide file tree
Showing 7 changed files with 456 additions and 396 deletions.
37 changes: 37 additions & 0 deletions aws/internal/service/redshift/enum.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package redshift

// https://docs.aws.amazon.com/redshift/latest/mgmt/working-with-clusters.html#rs-mgmt-cluster-status.
const (
ClusterStatusAvailable = "available"
ClusterStatusAvailablePrepForResize = "available, prep-for-resize"
ClusterStatusAvailableResizeCleanup = "available, resize-cleanup"
ClusterStatusCancellingResize = "cancelling-resize"
ClusterStatusCreating = "creating"
ClusterStatusDeleting = "deleting"
ClusterStatusFinalSnapshot = "final-snapshot"
ClusterStatusHardwareFailure = "hardware-failure"
ClusterStatusIncompatibleHsm = "incompatible-hsm"
ClusterStatusIncompatibleNetwork = "incompatible-network"
ClusterStatusIncompatibleParameters = "incompatible-parameters"
ClusterStatusIncompatibleRestore = "incompatible-restore"
ClusterStatusModifying = "modifying"
ClusterStatusPaused = "paused"
ClusterStatusRebooting = "rebooting"
ClusterStatusRenaming = "renaming"
ClusterStatusResizing = "resizing"
ClusterStatusRotatingKeys = "rotating-keys"
ClusterStatusStorageFull = "storage-full"
ClusterStatusUpdatingHsm = "updating-hsm"
)

const (
ClusterTypeMultiNode = "multi-node"
ClusterTypeSingleNode = "single-node"
)

func ClusterType_Values() []string {
return []string{
ClusterTypeMultiNode,
ClusterTypeSingleNode,
}
}
38 changes: 38 additions & 0 deletions aws/internal/service/redshift/finder/finder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package finder

import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/redshift"
"github.com/hashicorp/aws-sdk-go-base/tfawserr"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/tfresource"
)

func ClusterByID(conn *redshift.Redshift, id string) (*redshift.Cluster, error) {
input := &redshift.DescribeClustersInput{
ClusterIdentifier: aws.String(id),
}

output, err := conn.DescribeClusters(input)

if tfawserr.ErrCodeEquals(err, redshift.ErrCodeClusterNotFoundFault) {
return nil, &resource.NotFoundError{
LastError: err,
LastRequest: input,
}
}

if err != nil {
return nil, err
}

if output == nil || len(output.Clusters) == 0 || output.Clusters[0] == nil {
return nil, tfresource.NewEmptyResultError(input)
}

if count := len(output.Clusters); count > 1 {
return nil, tfresource.NewTooManyResultsError(count, input)
}

return output.Clusters[0], nil
}
25 changes: 25 additions & 0 deletions aws/internal/service/redshift/waiter/status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package waiter

import (
"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/terraform-providers/terraform-provider-aws/aws/internal/service/redshift/finder"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/tfresource"
)

func ClusterStatus(conn *redshift.Redshift, id string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
output, err := finder.ClusterByID(conn, id)

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

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

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

import (
"time"

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

const (
ClusterInvalidClusterStateFaultTimeout = 15 * time.Minute
)

func ClusterDeleted(conn *redshift.Redshift, id string, timeout time.Duration) (*redshift.Cluster, error) {
stateConf := &resource.StateChangeConf{
Pending: []string{
tfredshift.ClusterStatusAvailable,
tfredshift.ClusterStatusCreating,
tfredshift.ClusterStatusDeleting,
tfredshift.ClusterStatusFinalSnapshot,
tfredshift.ClusterStatusRebooting,
tfredshift.ClusterStatusRenaming,
tfredshift.ClusterStatusResizing,
},
Target: []string{},
Refresh: ClusterStatus(conn, id),
Timeout: timeout,
}

outputRaw, err := stateConf.WaitForState()

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

return nil, err
}
Loading

0 comments on commit 96ba48e

Please sign in to comment.