diff --git a/aws/resource_aws_rds_cluster.go b/aws/resource_aws_rds_cluster.go index 0c0edf202b49..7fb2db4b8af6 100644 --- a/aws/resource_aws_rds_cluster.go +++ b/aws/resource_aws_rds_cluster.go @@ -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}, @@ -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 diff --git a/aws/resource_aws_rds_cluster_test.go b/aws/resource_aws_rds_cluster_test.go index 33e42e3721f1..8e2ca72e1667 100644 --- a/aws/resource_aws_rds_cluster_test.go +++ b/aws/resource_aws_rds_cluster_test.go @@ -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") @@ -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" { diff --git a/website/docs/r/rds_cluster.html.markdown b/website/docs/r/rds_cluster.html.markdown index c94dd43fe34c..674e1b17d983 100644 --- a/website/docs/r/rds_cluster.html.markdown +++ b/website/docs/r/rds_cluster.html.markdown @@ -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) diff --git a/website/docs/r/rds_cluster_instance.html.markdown b/website/docs/r/rds_cluster_instance.html.markdown index 99efe976cb2d..2de3a6c99aa6 100644 --- a/website/docs/r/rds_cluster_instance.html.markdown +++ b/website/docs/r/rds_cluster_instance.html.markdown @@ -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 [lifecycle `ignore_changes` configuration](/docs/configuration/resources.html#ignore_changes) for this argument to prevent Terraform from proposing changes to the instance engine version directly. * `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.