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 validation to the global_cluster_identifier property on a global cluster #30996

Merged
merged 17 commits into from
Aug 14, 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/30996.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_rds_global_cluster: Add plan-time validation of `global_cluster_identifier`
```
6 changes: 3 additions & 3 deletions internal/service/rds/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -1601,7 +1601,7 @@ func FindDBClusterByID(ctx context.Context, conn *rds.RDS, id string) (*rds.DBCl
input := &rds.DescribeDBClustersInput{
DBClusterIdentifier: aws.String(id),
}
output, err := findDBCluster(ctx, conn, input)
output, err := findDBCluster(ctx, conn, input, tfslices.PredicateTrue[*rds.DBCluster]())

if err != nil {
return nil, err
Expand All @@ -1623,8 +1623,8 @@ func FindDBClusterByID(ctx context.Context, conn *rds.RDS, id string) (*rds.DBCl
return output, nil
}

func findDBCluster(ctx context.Context, conn *rds.RDS, input *rds.DescribeDBClustersInput) (*rds.DBCluster, error) {
output, err := findDBClusters(ctx, conn, input, tfslices.PredicateTrue[*rds.DBCluster]())
func findDBCluster(ctx context.Context, conn *rds.RDS, input *rds.DescribeDBClustersInput, filter tfslices.Predicate[*rds.DBCluster]) (*rds.DBCluster, error) {
output, err := findDBClusters(ctx, conn, input, filter)

if err != nil {
return nil, err
Expand Down
6 changes: 3 additions & 3 deletions internal/service/rds/cluster_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func FindDBClusterSnapshotByID(ctx context.Context, conn *rds.RDS, id string) (*
input := &rds.DescribeDBClusterSnapshotsInput{
DBClusterSnapshotIdentifier: aws.String(id),
}
output, err := findDBClusterSnapshot(ctx, conn, input)
output, err := findDBClusterSnapshot(ctx, conn, input, tfslices.PredicateTrue[*rds.DBClusterSnapshot]())

if err != nil {
return nil, err
Expand All @@ -236,8 +236,8 @@ func FindDBClusterSnapshotByID(ctx context.Context, conn *rds.RDS, id string) (*
return output, nil
}

func findDBClusterSnapshot(ctx context.Context, conn *rds.RDS, input *rds.DescribeDBClusterSnapshotsInput) (*rds.DBClusterSnapshot, error) {
output, err := findDBClusterSnapshots(ctx, conn, input, tfslices.PredicateTrue[*rds.DBClusterSnapshot]())
func findDBClusterSnapshot(ctx context.Context, conn *rds.RDS, input *rds.DescribeDBClusterSnapshotsInput, filter tfslices.Predicate[*rds.DBClusterSnapshot]) (*rds.DBClusterSnapshot, error) {
output, err := findDBClusterSnapshots(ctx, conn, input, filter)

if err != nil {
return nil, err
Expand Down
22 changes: 22 additions & 0 deletions internal/service/rds/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ const (
InstanceStatusUpgrading = "upgrading"
)

const (
GlobalClusterStatusAvailable = "available"
GlobalClusterStatusCreating = "creating"
GlobalClusterStatusDeleting = "deleting"
GlobalClusterStatusModifying = "modifying"
GlobalClusterStatusUpgrading = "upgrading"
)

const (
EventSubscriptionStatusActive = "active"
EventSubscriptionStatusCreating = "creating"
Expand Down Expand Up @@ -131,6 +139,20 @@ func ClusterEngine_Values() []string {
}
}

const (
GlobalClusterEngineAurora = "aurora"
GlobalClusterEngineAuroraMySQL = "aurora-mysql"
GlobalClusterEngineAuroraPostgreSQL = "aurora-postgresql"
)

func GlobalClusterEngine_Values() []string {
return []string{
GlobalClusterEngineAurora,
GlobalClusterEngineAuroraMySQL,
GlobalClusterEngineAuroraPostgreSQL,
}
}

const (
EngineModeGlobal = "global"
EngineModeMultiMaster = "multimaster"
Expand Down
2 changes: 1 addition & 1 deletion internal/service/rds/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
package rds

const (
errCodeInvalidParameterCombination = "InvalidParameterCombination"
errCodeInvalidParameterValue = "InvalidParameterValue"
errCodeValidationError = "ValidationError"
errCodeInvalidParameterCombination = "InvalidParameterCombination"
)
86 changes: 0 additions & 86 deletions internal/service/rds/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,92 +195,6 @@ func FindEventSubscriptionByID(ctx context.Context, conn *rds.RDS, id string) (*
return output.EventSubscriptionsList[0], nil
}

func FindGlobalClusterByDBClusterARN(ctx context.Context, conn *rds.RDS, dbClusterARN string) (*rds.GlobalCluster, error) {
input := &rds.DescribeGlobalClustersInput{}
globalClusters, err := findGlobalClusters(ctx, conn, input)
if err != nil {
return nil, err
}

for _, globalCluster := range globalClusters {
for _, v := range globalCluster.GlobalClusterMembers {
if aws.StringValue(v.DBClusterArn) == dbClusterARN {
return globalCluster, nil
}
}
}

return nil, &retry.NotFoundError{LastRequest: dbClusterARN}
}

func FindGlobalClusterByID(ctx context.Context, conn *rds.RDS, id string) (*rds.GlobalCluster, error) {
input := &rds.DescribeGlobalClustersInput{
GlobalClusterIdentifier: aws.String(id),
}

output, err := findGlobalCluster(ctx, conn, input)
if err != nil {
return nil, err
}

// Eventual consistency check.
if aws.StringValue(output.GlobalClusterIdentifier) != id {
return nil, &retry.NotFoundError{
LastRequest: input,
}
}

return output, nil
}

func findGlobalCluster(ctx context.Context, conn *rds.RDS, input *rds.DescribeGlobalClustersInput) (*rds.GlobalCluster, error) {
output, err := findGlobalClusters(ctx, conn, input)
if err != nil {
return nil, err
}

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

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

return output[0], nil
}

func findGlobalClusters(ctx context.Context, conn *rds.RDS, input *rds.DescribeGlobalClustersInput) ([]*rds.GlobalCluster, error) {
var output []*rds.GlobalCluster

err := conn.DescribeGlobalClustersPagesWithContext(ctx, input, func(page *rds.DescribeGlobalClustersOutput, lastPage bool) bool {
if page == nil {
return !lastPage
}

for _, v := range page.GlobalClusters {
if v != nil {
output = append(output, v)
}
}

return !lastPage
})

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

if err != nil {
return nil, err
}

return output, nil
}

func FindReservedDBInstanceByID(ctx context.Context, conn *rds.RDS, id string) (*rds.ReservedDBInstance, error) {
input := &rds.DescribeReservedDBInstancesInput{
ReservedDBInstanceId: aws.String(id),
Expand Down
Loading
Loading