Skip to content

Commit

Permalink
rds_global_cluster: Finally
Browse files Browse the repository at this point in the history
  • Loading branch information
YakDriver committed Mar 14, 2022
1 parent 9963e7b commit d888392
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
38 changes: 29 additions & 9 deletions internal/service/rds/global_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
const (
GlobalClusterRemovalTimeout = 30 * time.Minute
globalClusterCreateTimeout = 30 * time.Minute
globalClusterUpdateTimeout = 30 * time.Minute
globalClusterUpdateTimeout = 60 * time.Minute
)

func ResourceGlobalCluster() *schema.Resource {
Expand Down Expand Up @@ -489,7 +489,7 @@ func waitForGlobalClusterUpdate(conn *rds.RDS, globalClusterID string, timeout t

func waitForGlobalClusterVersionUpdate(conn *rds.RDS, globalClusterID, version string, timeout time.Duration) error {
stateConf := &resource.StateChangeConf{
Pending: []string{"modifying", "upgrading"},
Pending: []string{"modifying", "upgrading", "available"},
Target: []string{version},
Refresh: globalClusterVersionRefreshFunc(conn, globalClusterID, version),
Timeout: timeout,
Expand Down Expand Up @@ -559,11 +559,11 @@ func waitForGlobalClusterRemoval(conn *rds.RDS, dbClusterIdentifier string, time
return nil
}

func globalClusterUpgradeMajorEngineVersion(meta interface{}, clusterId string, engineVersion string) error {
func globalClusterUpgradeMajorEngineVersion(meta interface{}, clusterID string, engineVersion string) error {
conn := meta.(*conns.AWSClient).RDSConn

input := &rds.ModifyGlobalClusterInput{
GlobalClusterIdentifier: aws.String(clusterId),
GlobalClusterIdentifier: aws.String(clusterID),
}

input.AllowMajorVersionUpgrade = aws.Bool(true)
Expand Down Expand Up @@ -592,13 +592,13 @@ func globalClusterUpgradeMajorEngineVersion(meta interface{}, clusterId string,
}

if err != nil {
return fmt.Errorf("while upgrading major version of RDS Global Cluster (%s): %w", clusterId, err)
return fmt.Errorf("while upgrading major version of RDS Global Cluster (%s): %w", clusterID, err)
}

globalCluster, err := DescribeGlobalCluster(conn, clusterId)
globalCluster, err := DescribeGlobalCluster(conn, clusterID)

if err != nil {
return fmt.Errorf("while upgrading major version of RDS Global Cluster (%s): %w", clusterId, err)
return fmt.Errorf("while upgrading major version of RDS Global Cluster (%s): %w", clusterID, err)
}

for _, clusterMember := range globalCluster.GlobalClusterMembers {
Expand Down Expand Up @@ -661,6 +661,8 @@ func ClusterIDRegionFromARN(arnID string) (string, string, error) {
func globalClusterUpgradeMinorEngineVersion(meta interface{}, clusterMembers *schema.Set, clusterID, engineVersion string) error {
conn := meta.(*conns.AWSClient).RDSConn

log.Printf("[INFO] Performing RDS Global Cluster (%s) minor version (%s) upgrade", clusterID, engineVersion)

for _, clusterMemberRaw := range clusterMembers.List() {
clusterMember := clusterMemberRaw.(map[string]interface{})

Expand Down Expand Up @@ -694,6 +696,8 @@ func globalClusterUpgradeMinorEngineVersion(meta interface{}, clusterMembers *sc
EngineVersion: aws.String(engineVersion),
}

log.Printf("[INFO] Performing RDS Global Cluster (%s) Cluster (%s) minor version (%s) upgrade", clusterID, dbi, engineVersion)

err = resource.Retry(clusterInitiateUpgradeTimeout, func() *resource.RetryError {
_, err := useConn.ModifyDBCluster(modInput)

Expand Down Expand Up @@ -727,13 +731,29 @@ func globalClusterUpgradeMinorEngineVersion(meta interface{}, clusterMembers *sc
return fmt.Errorf("failed to update engine_version on RDS Global Cluster Cluster (%s): %s", dbi, err)
}

log.Printf("[INFO] Waiting for RDS Global Cluster (%s) Cluster (%s) minor version (%s) upgrade", clusterID, dbi, engineVersion)
if err := waitForClusterUpdate(useConn, dbi, clusterInitiateUpgradeTimeout); err != nil {
return fmt.Errorf("failed to update engine_version, waiting for RDS Global Cluster Cluster (%s) to update: %s", dbi, err)
}
}

if err := waitForGlobalClusterVersionUpdate(conn, clusterID, engineVersion, clusterInitiateUpgradeTimeout); err != nil {
return fmt.Errorf("failed to update engine_version, waiting for RDS Global Cluster (%s) to update: %s", clusterID, err)
globalCluster, err := DescribeGlobalCluster(conn, clusterID)

if tfawserr.ErrCodeEquals(err, rds.ErrCodeGlobalClusterNotFoundFault) {
return fmt.Errorf("after upgrading engine_version, could not find RDS Global Cluster (%s): %s", clusterID, err)
}

if err != nil {
return fmt.Errorf("after minor engine_version upgrade to RDS Global Cluster (%s): %s", clusterID, err)
}

if globalCluster == nil {
return fmt.Errorf("after minor engine_version upgrade to RDS Global Cluster (%s): empty response", clusterID)
}

if aws.StringValue(globalCluster.EngineVersion) != engineVersion {
log.Printf("[DEBUG] RDS Global Cluster (%s) upgrade did not take effect, trying again", clusterID)
return globalClusterUpgradeMinorEngineVersion(meta, clusterMembers, clusterID, engineVersion)
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/rds_global_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ resource "aws_rds_global_cluster" "example" {

### Upgrading Engine Versions

When you upgrade the version of an `aws_rds_global_cluster`, Terraform will attempt to in-place upgrade the engine versions of all associated clusters. Since the `aws_rds_cluster` resource is being updated through the `aws_rds_global_cluster`, you are likely to get an error (`Provider produced inconsistent final plan`). To avoid this, use the `lifecycle` `ignore_changes` meta argument as shown below.
When you upgrade the version of an `aws_rds_global_cluster`, Terraform will attempt to in-place upgrade the engine versions of all associated clusters. Since the `aws_rds_cluster` resource is being updated through the `aws_rds_global_cluster`, you are likely to get an error (`Provider produced inconsistent final plan`). To avoid this, use the `lifecycle` `ignore_changes` meta argument as shown below on the `aws_rds_cluster`.

```terraform
resource "aws_rds_global_cluster" "example" {
Expand Down

0 comments on commit d888392

Please sign in to comment.