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

service/rds: Additional error handling for Global Clusters, test fixes for engine versions #15938

Merged
merged 1 commit into from
Nov 4, 2020
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
7 changes: 5 additions & 2 deletions aws/resource_aws_rds_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/rds"
"github.com/hashicorp/aws-sdk-go-base/tfawserr"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
Expand Down Expand Up @@ -1122,7 +1123,9 @@ func resourceAwsRDSClusterUpdate(d *schema.ResourceData, meta interface{}) error
}

log.Printf("[DEBUG] Removing RDS Cluster from RDS Global Cluster: %s", input)
if _, err := conn.RemoveFromGlobalCluster(input); err != nil {
_, err := conn.RemoveFromGlobalCluster(input)

if err != nil && !tfawserr.ErrCodeEquals(err, rds.ErrCodeGlobalClusterNotFoundFault) && !tfawserr.ErrMessageContains(err, "InvalidParameterValue", "is not found in global cluster") {
return fmt.Errorf("error removing RDS Cluster (%s) from RDS Global Cluster: %s", d.Id(), err)
}
}
Expand Down Expand Up @@ -1182,7 +1185,7 @@ func resourceAwsRDSClusterDelete(d *schema.ResourceData, meta interface{}) error
log.Printf("[DEBUG] Removing RDS Cluster from RDS Global Cluster: %s", input)
_, err := conn.RemoveFromGlobalCluster(input)

if err != nil && !isAWSErr(err, rds.ErrCodeGlobalClusterNotFoundFault, "") {
if err != nil && !tfawserr.ErrCodeEquals(err, rds.ErrCodeGlobalClusterNotFoundFault) && !tfawserr.ErrMessageContains(err, "InvalidParameterValue", "is not found in global cluster") {
return fmt.Errorf("error removing RDS Cluster (%s) from RDS Global Cluster: %s", d.Id(), err)
}
}
Expand Down
46 changes: 32 additions & 14 deletions aws/resource_aws_rds_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@ func TestAccAWSRDSCluster_EngineMode_Global(t *testing.T) {
CheckDestroy: testAccCheckAWSClusterDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSRDSClusterConfig_EngineMode(rName, "global"),
Config: testAccAWSRDSClusterConfig_EngineMode_Global(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSClusterExists(resourceName, &dbCluster1),
resource.TestCheckResourceAttr(resourceName, "engine_mode", "global"),
Expand Down Expand Up @@ -1119,11 +1119,11 @@ func TestAccAWSRDSCluster_EngineVersionWithPrimaryInstance(t *testing.T) {
CheckDestroy: testAccCheckAWSClusterDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSClusterConfig_EngineVersionWithPrimaryInstance(rInt, "aurora-postgresql", "9.6.3"),
Config: testAccAWSClusterConfig_EngineVersionWithPrimaryInstance(rInt, "aurora-postgresql", "9.6.17"),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSClusterExists(resourceName, &dbCluster),
resource.TestCheckResourceAttr(resourceName, "engine", "aurora-postgresql"),
resource.TestCheckResourceAttr(resourceName, "engine_version", "9.6.3"),
resource.TestCheckResourceAttr(resourceName, "engine_version", "9.6.17"),
),
},
{
Expand All @@ -1139,11 +1139,11 @@ func TestAccAWSRDSCluster_EngineVersionWithPrimaryInstance(t *testing.T) {
},
},
{
Config: testAccAWSClusterConfig_EngineVersionWithPrimaryInstance(rInt, "aurora-postgresql", "9.6.6"),
Config: testAccAWSClusterConfig_EngineVersionWithPrimaryInstance(rInt, "aurora-postgresql", "9.6.18"),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSClusterExists(resourceName, &dbCluster),
resource.TestCheckResourceAttr(resourceName, "engine", "aurora-postgresql"),
resource.TestCheckResourceAttr(resourceName, "engine_version", "9.6.6"),
resource.TestCheckResourceAttr(resourceName, "engine_version", "9.6.18"),
),
},
},
Expand Down Expand Up @@ -1197,7 +1197,7 @@ func TestAccAWSRDSCluster_GlobalClusterIdentifier_EngineMode_Global_Add(t *testi
CheckDestroy: testAccCheckAWSClusterDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSRDSClusterConfig_EngineMode(rName, "global"),
Config: testAccAWSRDSClusterConfig_EngineMode_Global(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSClusterExists(resourceName, &dbCluster1),
resource.TestCheckResourceAttr(resourceName, "global_cluster_identifier", ""),
Expand Down Expand Up @@ -1255,7 +1255,7 @@ func TestAccAWSRDSCluster_GlobalClusterIdentifier_EngineMode_Global_Remove(t *te
},
},
{
Config: testAccAWSRDSClusterConfig_EngineMode(rName, "global"),
Config: testAccAWSRDSClusterConfig_EngineMode_Global(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSClusterExists(resourceName, &dbCluster1),
resource.TestCheckResourceAttr(resourceName, "global_cluster_identifier", ""),
Expand Down Expand Up @@ -3195,6 +3195,19 @@ resource "aws_rds_cluster" "test" {
`, rName, engineMode)
}

func testAccAWSRDSClusterConfig_EngineMode_Global(rName string) string {
return fmt.Sprintf(`
resource "aws_rds_cluster" "test" {
cluster_identifier = %[1]q
engine_mode = "global"
engine_version = "5.6.10a" # version compatible with engine_mode = "global"
master_password = "barbarbarbar"
master_username = "foo"
skip_final_snapshot = true
}
`, rName)
}

func testAccAWSRDSClusterConfig_EngineMode_Multimaster(rName string) string {
return fmt.Sprintf(`
data "aws_availability_zones" "available" {
Expand Down Expand Up @@ -3254,37 +3267,42 @@ resource "aws_rds_cluster" "test" {
func testAccAWSRDSClusterConfig_GlobalClusterIdentifier_EngineMode_Global(rName string) string {
return fmt.Sprintf(`
resource "aws_rds_global_cluster" "test" {
global_cluster_identifier = %q
engine_version = "5.6.10a" # version compatible with engine_mode = "global"
force_destroy = true # Partial configuration removal ordering fix for after Terraform 0.12
global_cluster_identifier = %[1]q
}

resource "aws_rds_cluster" "test" {
cluster_identifier = %q
cluster_identifier = %[1]q
global_cluster_identifier = aws_rds_global_cluster.test.id
engine_mode = "global"
engine_version = aws_rds_global_cluster.test.engine_version
master_password = "barbarbarbar"
master_username = "foo"
skip_final_snapshot = true
}
`, rName, rName)
`, rName)
}

func testAccAWSRDSClusterConfig_GlobalClusterIdentifier_EngineMode_Global_Update(rName, globalClusterIdentifierResourceName string) string {
return fmt.Sprintf(`
resource "aws_rds_global_cluster" "test" {
count = 2

global_cluster_identifier = "%s-${count.index}"
engine_version = "5.6.10a" # version compatible with engine_mode = "global"
global_cluster_identifier = "%[1]s-${count.index}"
}

resource "aws_rds_cluster" "test" {
cluster_identifier = %q
global_cluster_identifier = %s.id
cluster_identifier = %[1]q
global_cluster_identifier = %[2]s.id
engine_mode = "global"
engine_version = %[2]s.engine_version
master_password = "barbarbarbar"
master_username = "foo"
skip_final_snapshot = true
}
`, rName, rName, globalClusterIdentifierResourceName)
`, rName, globalClusterIdentifierResourceName)
}

func testAccAWSRDSClusterConfig_GlobalClusterIdentifier_EngineMode_Provisioned(rName string) string {
Expand Down
9 changes: 8 additions & 1 deletion aws/resource_aws_rds_global_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/rds"
"github.com/hashicorp/aws-sdk-go-base/tfawserr"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
Expand Down Expand Up @@ -250,7 +251,13 @@ func resourceAwsRDSGlobalClusterDelete(d *schema.ResourceData, meta interface{})
GlobalClusterIdentifier: aws.String(d.Id()),
}

if _, err := conn.RemoveFromGlobalCluster(input); err != nil {
_, err := conn.RemoveFromGlobalCluster(input)

if tfawserr.ErrMessageContains(err, "InvalidParameterValue", "is not found in global cluster") {
continue
}

if err != nil {
return fmt.Errorf("error removing RDS DB Cluster (%s) from Global Cluster (%s): %w", dbClusterArn, d.Id(), err)
}

Expand Down