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

resource/aws_rds_cluster: Add allow_major_version_upgrade argument #14709

Merged
merged 3 commits into from
Sep 22, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
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
84 changes: 84 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,56 @@ 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.11"
engineVersion2 := "11.7"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSClusterDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSClusterConfig_AllowMajorVersionUpgrade(rName, true, engine, engineVersion1),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSClusterExists(resourceName, &dbCluster1),
resource.TestCheckResourceAttr(resourceName, "allow_major_version_upgrade", "true"),
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, 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 +2301,40 @@ 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
}

data "aws_rds_orderable_db_instance" "test" {
engine = aws_rds_cluster.test.engine
engine_version = aws_rds_cluster.test.engine_version
preferred_instance_classes = ["db.t3.medium", "db.r5.large", "db.r4.large"]
}

# Upgrading requires a healthy primary instance
resource "aws_rds_cluster_instance" "test" {
cluster_identifier = aws_rds_cluster.test.id
engine = data.aws_rds_orderable_db_instance.test.engine
engine_version = data.aws_rds_orderable_db_instance.test.engine_version
identifier = %[1]q
instance_class = data.aws_rds_orderable_db_instance.test.instance_class

lifecycle {
ignore_changes = [engine_version]
}
}
`, 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
2 changes: 1 addition & 1 deletion website/docs/r/rds_cluster_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ The following arguments are supported:
For information on the difference between the available Aurora MySQL engines
see [Comparison between Aurora MySQL 1 and Aurora MySQL 2](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/AuroraMySQL.Updates.20180206.html)
in the Amazon RDS User Guide.
* `engine_version` - (Optional) The database engine version.
* `engine_version` - (Optional) The database engine version. When managing the engine version in the cluster, it is recommended to add the [lifecyle `ignore_changes` configuration](/docs/configuration/resources.html#ignore_changes) for this argument to prevent Terraform from proposing changes to the instance engine version directly.
bflad marked this conversation as resolved.
Show resolved Hide resolved
* `instance_class` - (Required) The instance class to use. For details on CPU
and memory, see [Scaling Aurora DB Instances][4]. Aurora uses `db.*` instance classes/types. Please see [AWS Documentation][7] for currently available instance classes and complete details.
* `publicly_accessible` - (Optional) Bool to control if instance is publicly accessible.
Expand Down