Skip to content
This repository has been archived by the owner on Feb 19, 2021. It is now read-only.

Commit

Permalink
Merge branch 'pr-5010' into v1.36.0_patched
Browse files Browse the repository at this point in the history
  • Loading branch information
mdlavin committed Sep 13, 2018
2 parents a638c0a + 3a14da7 commit 64fb517
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 4 deletions.
15 changes: 13 additions & 2 deletions aws/resource_aws_rds_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func resourceAwsRDSCluster() *schema.Resource {
"engine_version": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ForceNew: false,
Computed: true,
},

Expand Down Expand Up @@ -225,7 +225,7 @@ func resourceAwsRDSCluster() *schema.Resource {
"source_engine_version": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ForceNew: false,
},
},
},
Expand Down Expand Up @@ -981,6 +981,11 @@ func resourceAwsRDSClusterUpdate(d *schema.ResourceData, meta interface{}) error
requestUpdate = true
}

if d.HasChange("engine_version") {
req.EngineVersion = aws.String(d.Get("engine_version").(string))
requestUpdate = true
}

if d.HasChange("vpc_security_group_ids") {
if attr := d.Get("vpc_security_group_ids").(*schema.Set); attr.Len() > 0 {
req.VpcSecurityGroupIds = expandStringList(attr.List())
Expand Down Expand Up @@ -1035,6 +1040,11 @@ func resourceAwsRDSClusterUpdate(d *schema.ResourceData, meta interface{}) error
if isAWSErr(err, "InvalidParameterValue", "IAM role ARN value is invalid or does not include the required permissions") {
return resource.RetryableError(err)
}

if isAWSErr(err, rds.ErrCodeInvalidDBClusterStateFault, "Cannot modify engine version without a primary instance in DB cluster") {
return resource.NonRetryableError(err)
}

if isAWSErr(err, rds.ErrCodeInvalidDBClusterStateFault, "") {
return resource.RetryableError(err)
}
Expand Down Expand Up @@ -1244,4 +1254,5 @@ var resourceAwsRdsClusterUpdatePendingStates = []string{
"backing-up",
"modifying",
"resetting-master-credentials",
"upgrading",
}
2 changes: 1 addition & 1 deletion aws/resource_aws_rds_cluster_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func resourceAwsRDSClusterInstance() *schema.Resource {
"engine_version": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ForceNew: false,
Computed: true,
},

Expand Down
76 changes: 75 additions & 1 deletion aws/resource_aws_rds_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,41 @@ func TestAccAWSRDSCluster_EngineVersion(t *testing.T) {
CheckDestroy: testAccCheckAWSClusterDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSClusterConfig_EngineVersion(rInt, "aurora-postgresql", "9.6.6"),
Config: testAccAWSClusterConfig_EngineVersion(rInt, "aurora-postgresql", "9.6.3"),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSClusterExists(resourceName, &dbCluster),
resource.TestCheckResourceAttr(resourceName, "engine", "aurora-postgresql"),
resource.TestCheckResourceAttr(resourceName, "engine_version", "9.6.3"),
),
},
{
Config: testAccAWSClusterConfig_EngineVersion(rInt, "aurora-postgresql", "9.6.6"),
ExpectError: regexp.MustCompile(`Cannot modify engine version without a primary instance in DB cluster`),
},
},
})
}

func TestAccAWSRDSCluster_EngineVersionWithPrimaryInstance(t *testing.T) {
var dbCluster rds.DBCluster
rInt := acctest.RandInt()
resourceName := "aws_rds_cluster.test"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSClusterDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSClusterConfig_EngineVersionWithPrimaryInstance(rInt, "aurora-postgresql", "9.6.3"),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSClusterExists(resourceName, &dbCluster),
resource.TestCheckResourceAttr(resourceName, "engine", "aurora-postgresql"),
resource.TestCheckResourceAttr(resourceName, "engine_version", "9.6.3"),
),
},
{
Config: testAccAWSClusterConfig_EngineVersionWithPrimaryInstance(rInt, "aurora-postgresql", "9.6.6"),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSClusterExists(resourceName, &dbCluster),
resource.TestCheckResourceAttr(resourceName, "engine", "aurora-postgresql"),
Expand Down Expand Up @@ -1256,8 +1290,48 @@ resource "aws_rds_cluster" "test" {
engine = "%s"
engine_version = "%s"
master_password = "mustbeeightcharaters"
master_username = "foo"
skip_final_snapshot = true
apply_immediately = true
}`, rInt, engine, engineVersion)
}

func testAccAWSClusterConfig_EngineVersionWithPrimaryInstance(rInt int, engine, engineVersion string) string {
return fmt.Sprintf(`
data "aws_availability_zones" "available" {}
variable "cluster_identifier" {
default = "tf-acc-test-%d"
}
variable "engine" {
default = "%s"
}
variable "engine_version" {
default = "%s"
}
resource "aws_rds_cluster" "test" {
availability_zones = ["${data.aws_availability_zones.available.names}"]
cluster_identifier = "${var.cluster_identifier}"
database_name = "mydb"
db_cluster_parameter_group_name = "default.aurora-postgresql9.6"
engine = "${var.engine}"
engine_version = "${var.engine_version}"
master_password = "mustbeeightcharaters"
master_username = "foo"
skip_final_snapshot = true
apply_immediately = true
}
resource "aws_rds_cluster_instance" "test" {
identifier = "${var.cluster_identifier}"
cluster_identifier = "${aws_rds_cluster.test.cluster_identifier}"
engine = "${var.engine}"
engine_version = "${var.engine_version}"
instance_class = "db.r4.large"
}`, rInt, engine, engineVersion)
}

Expand Down

0 comments on commit 64fb517

Please sign in to comment.