Skip to content

Commit

Permalink
Merge branch 'taganaka-skip-force-new-on-engine-version'
Browse files Browse the repository at this point in the history
  • Loading branch information
bflad committed Oct 5, 2018
2 parents 511700e + 10024db commit 6ee5d12
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 4 deletions.
12 changes: 11 additions & 1 deletion aws/resource_aws_rds_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ func resourceAwsRDSCluster() *schema.Resource {
"engine_version": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
},

Expand Down Expand Up @@ -996,6 +995,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 @@ -1055,6 +1059,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 @@ -1264,4 +1273,5 @@ var resourceAwsRdsClusterUpdatePendingStates = []string{
"backing-up",
"modifying",
"resetting-master-credentials",
"upgrading",
}
65 changes: 63 additions & 2 deletions aws/resource_aws_rds_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,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 @@ -1513,10 +1547,37 @@ resource "aws_rds_cluster" "test" {
engine_version = "%s"
master_password = "mustbeeightcharaters"
master_username = "foo"
skip_final_snapshot = true
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" {}
resource "aws_rds_cluster" "test" {
availability_zones = ["${data.aws_availability_zones.available.names}"]
cluster_identifier = "tf-acc-test-%d"
database_name = "mydb"
db_cluster_parameter_group_name = "default.aurora-postgresql9.6"
engine = %q
engine_version = %q
master_password = "mustbeeightcharaters"
master_username = "foo"
skip_final_snapshot = true
apply_immediately = true
}
resource "aws_rds_cluster_instance" "test" {
identifier = "tf-acc-test-%d"
cluster_identifier = "${aws_rds_cluster.test.cluster_identifier}"
engine = "${aws_rds_cluster.test.engine}"
instance_class = "db.r4.large"
}`, rInt, engine, engineVersion, rInt)
}

func testAccAWSClusterConfig_Port(rInt, port int) string {
return fmt.Sprintf(`
data "aws_availability_zones" "available" {}
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/rds_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ Default: A 30-minute window selected at random from an 8-hour block of time per
* `iam_database_authentication_enabled` - (Optional) Specifies whether or mappings of AWS Identity and Access Management (IAM) accounts to database accounts is enabled. Please see [AWS Documentation][6] for availability and limitations.
* `engine` - (Optional) The name of the database engine to be used for this DB cluster. Defaults to `aurora`. Valid Values: `aurora`, `aurora-mysql`, `aurora-postgresql`
* `engine_mode` - (Optional) The database engine mode. Valid values: `parallelquery`, `provisioned`, `serverless`. Defaults to: `provisioned`. See the [RDS User Guide](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/aurora-serverless.html) for limitations when using `serverless`.
* `engine_version` - (Optional) The database engine version.
* `engine_version` - (Optional) The database engine version. Updating this argument results in an outage.
* `source_region` - (Optional) The source region for an encrypted replica DB cluster.
* `enabled_cloudwatch_logs_exports` - (Optional) List of log types to export to cloudwatch. If omitted, no logs will be exported.
The following log types are supported: `audit`, `error`, `general`, `slowquery`.
Expand Down

0 comments on commit 6ee5d12

Please sign in to comment.