Skip to content

Commit

Permalink
resource/aws_rds_cluster: Add allow_major_version_upgrade argument
Browse files Browse the repository at this point in the history
Reference: #13874

Currently needs some additional work (e.g. better waiters in RDS DB Cluster or RDS DB Cluster Instance handling) so testing can pass.

Output from acceptance testing:

```
    TestAccAWSRDSCluster_AllowMajorVersionUpgrade: resource_aws_rds_cluster_test.go:160: Step 4/4 error: terraform failed: exit status 1

        stderr:

        Error: Failed to modify RDS Cluster (tf-acc-test-340394054292885352): InvalidDBClusterStateFault: Cannot modify engine version without a healthy primary instance in DB cluster: tf-acc-test-340394054292885352
        	status code: 400, request id: 2607bd75-12b6-40b5-a47b-e601680d4091

--- FAIL: TestAccAWSRDSCluster_AllowMajorVersionUpgrade (1015.90s)
```
  • Loading branch information
bflad committed Aug 17, 2020
1 parent c161027 commit be7f4fb
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
9 changes: 9 additions & 0 deletions aws/resource_aws_rds_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ func resourceAwsRDSCluster() *schema.Resource {
Computed: true,
},

"allow_major_version_upgrade": {
Type: schema.TypeBool,
Optional: true,
},

"availability_zones": {
Type: schema.TypeSet,
Elem: &schema.Schema{Type: schema.TypeString},
Expand Down Expand Up @@ -982,6 +987,10 @@ func resourceAwsRDSClusterUpdate(d *schema.ResourceData, meta interface{}) error
DBClusterIdentifier: aws.String(d.Id()),
}

if v, ok := d.GetOk("allow_major_version_upgrade"); ok {
req.AllowMajorVersionUpgrade = aws.Bool(v.(bool))
}

if d.HasChange("backtrack_window") {
req.BacktrackWindow = aws.Int64(int64(d.Get("backtrack_window").(int)))
requestUpdate = true
Expand Down
78 changes: 78 additions & 0 deletions aws/resource_aws_rds_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,60 @@ func TestAccAWSRDSCluster_basic(t *testing.T) {
})
}

func TestAccAWSRDSCluster_AllowMajorVersionUpgrade(t *testing.T) {
var dbCluster1, dbCluster2 rds.DBCluster
rName := acctest.RandomWithPrefix("tf-acc-test")
resourceName := "aws_rds_cluster.test"
// If these hardcoded versions become a maintenance burden, use DescribeDBEngineVersions
// either by having a new data source created or implementing the testing similar
// to TestAccAWSDmsReplicationInstance_EngineVersion
engine := "aurora-postgresql"
engineVersion1 := "10.12"
engineVersion2 := "11.7"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSClusterDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSClusterConfig_AllowMajorVersionUpgrade(rName, false, engine, engineVersion1),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSClusterExists(resourceName, &dbCluster1),
resource.TestCheckResourceAttr(resourceName, "allow_major_version_upgrade", "false"),
resource.TestCheckResourceAttr(resourceName, "engine", engine),
resource.TestCheckResourceAttr(resourceName, "engine_version", engineVersion1),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
"allow_major_version_upgrade",
"apply_immediately",
"cluster_identifier_prefix",
"master_password",
"skip_final_snapshot",
},
},
{
Config: testAccAWSClusterConfig_AllowMajorVersionUpgrade(rName, false, engine, engineVersion2),
ExpectError: regexp.MustCompile(`InvalidParameterCombination: The AllowMajorVersionUpgrade flag must be present when upgrading to a new major version`),
},
{
Config: testAccAWSClusterConfig_AllowMajorVersionUpgrade(rName, true, engine, engineVersion2),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSClusterExists(resourceName, &dbCluster2),
resource.TestCheckResourceAttr(resourceName, "allow_major_version_upgrade", "true"),
resource.TestCheckResourceAttr(resourceName, "engine", engine),
resource.TestCheckResourceAttr(resourceName, "engine_version", engineVersion2),
),
},
},
})
}

func TestAccAWSRDSCluster_AvailabilityZones(t *testing.T) {
var dbCluster rds.DBCluster
rName := acctest.RandomWithPrefix("tf-acc-test")
Expand Down Expand Up @@ -2251,6 +2305,30 @@ resource "aws_rds_cluster" "test" {
`, rName)
}

func testAccAWSClusterConfig_AllowMajorVersionUpgrade(rName string, allowMajorVersionUpgrade bool, engine string, engineVersion string) string {
return fmt.Sprintf(`
resource "aws_rds_cluster" "test" {
allow_major_version_upgrade = %[2]t
apply_immediately = true
cluster_identifier = %[1]q
engine = %[3]q
engine_version = %[4]q
master_password = "mustbeeightcharaters"
master_username = "test"
skip_final_snapshot = true
}
# Upgrading requires a healthy primary instance
resource "aws_rds_cluster_instance" "test" {
cluster_identifier = aws_rds_cluster.test.id
engine = aws_rds_cluster.test.engine
engine_version = aws_rds_cluster.test.engine_version
identifier = %[1]q
instance_class = "db.r4.large"
}
`, rName, allowMajorVersionUpgrade, engine, engineVersion)
}

func testAccAWSClusterConfig_AvailabilityZones(rName string) string {
return fmt.Sprintf(`
data "aws_availability_zones" "available" {
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/rds_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ the [AWS official documentation](https://docs.aws.amazon.com/cli/latest/referenc

The following arguments are supported:

* `allow_major_version_upgrade` - (Optional) Enable to allow major engine version upgrades when changing engine versions. Defaults to `false`.
* `apply_immediately` - (Optional) Specifies whether any cluster modifications are applied immediately, or during the next maintenance window. Default is `false`. See [Amazon RDS Documentation for more information.](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Overview.DBInstance.Modifying.html)
* `availability_zones` - (Optional) A list of EC2 Availability Zones for the DB cluster storage where DB cluster instances can be created. RDS automatically assigns 3 AZs if less than 3 AZs are configured, which will show as a difference requiring resource recreation next Terraform apply. It is recommended to specify 3 AZs or use [the `lifecycle` configuration block `ignore_changes` argument](/docs/configuration/resources.html#ignore_changes) if necessary.
* `backtrack_window` - (Optional) The target backtrack window, in seconds. Only available for `aurora` engine currently. To disable backtracking, set this value to `0`. Defaults to `0`. Must be between `0` and `259200` (72 hours)
Expand Down

0 comments on commit be7f4fb

Please sign in to comment.