From 6e0d54e01f8812b2f9f31359311df5f47a4069de Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Mon, 7 Mar 2022 12:49:28 -0500 Subject: [PATCH 01/32] rds: Fix some acceptance tests --- internal/service/rds/cluster.go | 7 + internal/service/rds/cluster_endpoint_test.go | 22 +- internal/service/rds/cluster_test.go | 2 +- internal/service/rds/global_cluster.go | 5 +- internal/service/rds/global_cluster_test.go | 41 +-- .../service/rds/instance_data_source_test.go | 27 +- internal/service/rds/instance_test.go | 6 +- internal/service/rds/option_group_test.go | 284 +++++++++--------- 8 files changed, 210 insertions(+), 184 deletions(-) diff --git a/internal/service/rds/cluster.go b/internal/service/rds/cluster.go index 16cfd9d0736..d7d9e5874f2 100644 --- a/internal/service/rds/cluster.go +++ b/internal/service/rds/cluster.go @@ -559,6 +559,7 @@ func resourceClusterCreate(d *schema.ResourceData, meta interface{}) error { } if attr, ok := d.GetOk("engine_version"); ok { + fmt.Printf("[CREATE/cluster/snapshot_identifier] engine_version: %s\n", attr.(string)) opts.EngineVersion = aws.String(attr.(string)) } @@ -654,6 +655,7 @@ func resourceClusterCreate(d *schema.ResourceData, meta interface{}) error { } if attr, ok := d.GetOk("engine_version"); ok { + fmt.Printf("[CREATE/cluster/s3_import] engine_version: %s\n", attr.(string)) createOpts.EngineVersion = aws.String(attr.(string)) } @@ -871,6 +873,7 @@ func resourceClusterCreate(d *schema.ResourceData, meta interface{}) error { } if attr, ok := d.GetOk("engine_version"); ok { + fmt.Printf("[CREATE/cluster/else] engine_version: %s\n", attr.(string)) createOpts.EngineVersion = aws.String(attr.(string)) } @@ -1183,6 +1186,7 @@ func resourceClusterUpdate(d *schema.ResourceData, meta interface{}) error { } if d.HasChange("engine_version") { + fmt.Printf("[UPDATE/cluster] engine_version: %s\n", d.Get("engine_version").(string)) req.EngineVersion = aws.String(d.Get("engine_version").(string)) requestUpdate = true } @@ -1549,7 +1553,10 @@ func compareActualEngineVersion(d *schema.ResourceData, oldVersion string, newVe if oldVersion != newVersion && string(append([]byte(oldVersion), []byte(".")...)) != newVersionSubstr { d.Set("engine_version", newVersion) + fmt.Printf("[READ/cluster] engine_version: %s\n", newVersion) } d.Set("engine_version_actual", newVersion) + fmt.Printf("[READ/cluster] engine_version_actual: %s\n", newVersion) + } diff --git a/internal/service/rds/cluster_endpoint_test.go b/internal/service/rds/cluster_endpoint_test.go index 02e74881f79..c463959741a 100644 --- a/internal/service/rds/cluster_endpoint_test.go +++ b/internal/service/rds/cluster_endpoint_test.go @@ -211,7 +211,9 @@ func testAccCheckClusterEndpointExistsWithProvider(resourceName string, endpoint } func testAccClusterEndpointBaseConfig(n int) string { - return acctest.ConfigCompose(acctest.ConfigAvailableAZsNoOptIn(), fmt.Sprintf(` + return acctest.ConfigCompose( + acctest.ConfigAvailableAZsNoOptIn(), + fmt.Sprintf(` data "aws_rds_orderable_db_instance" "test" { engine = aws_rds_cluster.default.engine engine_version = aws_rds_cluster.default.engine_version @@ -249,7 +251,9 @@ resource "aws_rds_cluster_instance" "test2" { } func testAccClusterEndpointConfig(n int) string { - return testAccClusterEndpointBaseConfig(n) + fmt.Sprintf(` + return acctest.ConfigCompose( + testAccClusterEndpointBaseConfig(n), + fmt.Sprintf(` resource "aws_rds_cluster_endpoint" "reader" { cluster_identifier = aws_rds_cluster.default.id cluster_endpoint_identifier = "reader-%[1]d" @@ -265,11 +269,13 @@ resource "aws_rds_cluster_endpoint" "default" { excluded_members = [aws_rds_cluster_instance.test2.id] } -`, n) +`, n)) } func testAccClusterEndpointTags1Config(n int, tagKey1, tagValue1 string) string { - return testAccClusterEndpointBaseConfig(n) + fmt.Sprintf(` + return acctest.ConfigCompose( + testAccClusterEndpointBaseConfig(n), + fmt.Sprintf(` resource "aws_rds_cluster_endpoint" "reader" { cluster_identifier = aws_rds_cluster.default.id cluster_endpoint_identifier = "reader-%[1]d" @@ -281,11 +287,13 @@ resource "aws_rds_cluster_endpoint" "reader" { %[2]q = %[3]q } } -`, n, tagKey1, tagValue1) +`, n, tagKey1, tagValue1)) } func testAccClusterEndpointTags2Config(n int, tagKey1, tagValue1, tagKey2, tagValue2 string) string { - return testAccClusterEndpointBaseConfig(n) + fmt.Sprintf(` + return acctest.ConfigCompose( + testAccClusterEndpointBaseConfig(n), + fmt.Sprintf(` resource "aws_rds_cluster_endpoint" "reader" { cluster_identifier = aws_rds_cluster.default.id cluster_endpoint_identifier = "reader-%[1]d" @@ -298,5 +306,5 @@ resource "aws_rds_cluster_endpoint" "reader" { %[4]q = %[5]q } } -`, n, tagKey1, tagValue1, tagKey2, tagValue2) +`, n, tagKey1, tagValue1, tagKey2, tagValue2)) } diff --git a/internal/service/rds/cluster_test.go b/internal/service/rds/cluster_test.go index 401660d83e7..0ac9a15bc8a 100644 --- a/internal/service/rds/cluster_test.go +++ b/internal/service/rds/cluster_test.go @@ -3599,7 +3599,7 @@ func testAccClusterConfig_SnapshotIdentifier_EngineVersion(rName string, same bo return fmt.Sprintf(` data "aws_rds_engine_version" "test" { engine = "aurora-postgresql" - preferred_versions = ["11.4", "10.4", "9.6.6"] + preferred_versions = ["13.3", "12.9", "11.14"] } data "aws_rds_engine_version" "upgrade" { diff --git a/internal/service/rds/global_cluster.go b/internal/service/rds/global_cluster.go index 8d5806da3da..674f4e6fa79 100644 --- a/internal/service/rds/global_cluster.go +++ b/internal/service/rds/global_cluster.go @@ -128,6 +128,7 @@ func resourceGlobalClusterCreate(d *schema.ResourceData, meta interface{}) error } if v, ok := d.GetOk("engine_version"); ok { + fmt.Printf("[CREATE/global_cluster] engine_version: %s\n", v.(string)) input.EngineVersion = aws.String(v.(string)) } @@ -192,6 +193,7 @@ func resourceGlobalClusterRead(d *schema.ResourceData, meta interface{}) error { d.Set("deletion_protection", globalCluster.DeletionProtection) d.Set("engine", globalCluster.Engine) d.Set("engine_version", globalCluster.EngineVersion) + fmt.Printf("[READ/global_cluster] engine_verison: %s\n", aws.StringValue(globalCluster.EngineVersion)) d.Set("global_cluster_identifier", globalCluster.GlobalClusterIdentifier) if err := d.Set("global_cluster_members", flattenGlobalClusterMembers(globalCluster.GlobalClusterMembers)); err != nil { @@ -213,6 +215,7 @@ func resourceGlobalClusterUpdate(d *schema.ResourceData, meta interface{}) error } if d.HasChange("engine_version") { + fmt.Printf("[UPDATE/global_cluster] engine_version: %s\n", d.Get("engine_version").(string)) if err := resourceGlobalClusterUpgradeEngineVersion(d, conn); err != nil { return err } @@ -581,7 +584,7 @@ func resourceGlobalClusterUpgradeMinorEngineVersion(clusterMembers *schema.Set, } } if err != nil { - return fmt.Errorf("Failed to update engine_version on global cluster member (%s): %s", clusterMemberArn, err) + return fmt.Errorf("failed to update engine_version on RDS Global Cluster member (%s): %s", clusterMemberArn, err) } } } diff --git a/internal/service/rds/global_cluster_test.go b/internal/service/rds/global_cluster_test.go index 893f88d74bd..586ffe58f26 100644 --- a/internal/service/rds/global_cluster_test.go +++ b/internal/service/rds/global_cluster_test.go @@ -210,17 +210,17 @@ func TestAccRDSGlobalCluster_engineVersionUpdateMinor(t *testing.T) { CheckDestroy: testAccCheckGlobalClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccGlobalClusterWithPrimaryEngineVersionConfig(rName, "aurora", "5.6.mysql_aurora.1.22.2"), + Config: testAccGlobalClusterWithPrimaryEngineVersionConfig(rName, "aurora-mysql", "5.7.mysql_aurora.2.10.1"), Check: resource.ComposeTestCheckFunc( testAccCheckGlobalClusterExists(resourceName, &globalCluster1), ), }, { - Config: testAccGlobalClusterWithPrimaryEngineVersionConfig(rName, "aurora", "5.6.mysql_aurora.1.23.2"), + Config: testAccGlobalClusterWithPrimaryEngineVersionConfig(rName, "aurora-mysql", "5.7.mysql_aurora.2.10.2"), Check: resource.ComposeTestCheckFunc( testAccCheckGlobalClusterExists(resourceName, &globalCluster2), testAccCheckGlobalClusterNotRecreated(&globalCluster1, &globalCluster2), - resource.TestCheckResourceAttr(resourceName, "engine_version", "5.6.mysql_aurora.1.23.2"), + resource.TestCheckResourceAttr(resourceName, "engine_version", "5.7.mysql_aurora.2.10.2"), ), }, { @@ -244,18 +244,18 @@ func TestAccRDSGlobalCluster_engineVersionUpdateMajor(t *testing.T) { CheckDestroy: testAccCheckGlobalClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccGlobalClusterWithPrimaryEngineVersionConfig(rName, "aurora", "5.6.mysql_aurora.1.22.2"), + Config: testAccGlobalClusterWithPrimaryEngineVersionConfig(rName, "aurora", "5.7.mysql_aurora.2.10.2"), Check: resource.ComposeTestCheckFunc( testAccCheckGlobalClusterExists(resourceName, &globalCluster1), ), }, { - Config: testAccGlobalClusterWithPrimaryEngineVersionConfig(rName, "aurora", "5.7.mysql_aurora.2.07.2"), + Config: testAccGlobalClusterWithPrimaryEngineVersionConfig(rName, "aurora", "8.0.mysql_aurora.3.01.0"), ExpectNonEmptyPlan: true, Check: resource.ComposeTestCheckFunc( testAccCheckGlobalClusterExists(resourceName, &globalCluster2), testAccCheckGlobalClusterNotRecreated(&globalCluster1, &globalCluster2), - resource.TestCheckResourceAttr(resourceName, "engine_version", "5.7.mysql_aurora.2.07.2"), + resource.TestCheckResourceAttr(resourceName, "engine_version", "8.0.mysql_aurora.3.01.0"), ), }, { @@ -532,7 +532,7 @@ func testAccPreCheckGlobalCluster(t *testing.T) { func testAccGlobalClusterConfig(rName string) string { return fmt.Sprintf(` resource "aws_rds_global_cluster" "test" { - global_cluster_identifier = %q + global_cluster_identifier = %[1]q } `, rName) } @@ -540,8 +540,8 @@ resource "aws_rds_global_cluster" "test" { func testAccGlobalClusterDatabaseNameConfig(rName, databaseName string) string { return fmt.Sprintf(` resource "aws_rds_global_cluster" "test" { - database_name = %q - global_cluster_identifier = %q + database_name = %[1]q + global_cluster_identifier = %[2]q } `, databaseName, rName) } @@ -549,8 +549,8 @@ resource "aws_rds_global_cluster" "test" { func testAccGlobalClusterDeletionProtectionConfig(rName string, deletionProtection bool) string { return fmt.Sprintf(` resource "aws_rds_global_cluster" "test" { - deletion_protection = %t - global_cluster_identifier = %q + deletion_protection = %[1]t + global_cluster_identifier = %[2]q } `, deletionProtection, rName) } @@ -558,8 +558,8 @@ resource "aws_rds_global_cluster" "test" { func testAccGlobalClusterEngineConfig(rName, engine string) string { return fmt.Sprintf(` resource "aws_rds_global_cluster" "test" { - engine = %q - global_cluster_identifier = %q + engine = %[1]q + global_cluster_identifier = %[2]q } `, engine, rName) } @@ -567,9 +567,9 @@ resource "aws_rds_global_cluster" "test" { func testAccGlobalClusterEngineVersionConfig(rName, engine, engineVersion string) string { return fmt.Sprintf(` resource "aws_rds_global_cluster" "test" { - engine = %q - engine_version = %q - global_cluster_identifier = %q + engine = %[1]q + engine_version = %[2]q + global_cluster_identifier = %[3]q } `, engine, engineVersion, rName) } @@ -586,6 +586,8 @@ resource "aws_rds_cluster" "test" { apply_immediately = true allow_major_version_upgrade = true cluster_identifier = %[3]q + engine = %[1]q + engine_version = %[2]q master_password = "mustbeeightcharacters" master_username = "test" skip_final_snapshot = true @@ -600,6 +602,9 @@ resource "aws_rds_cluster" "test" { resource "aws_rds_cluster_instance" "test" { apply_immediately = true cluster_identifier = aws_rds_cluster.test.id + #cluster_identifier = %[3]q + engine = %[1]q + engine_version = %[2]q identifier = %[3]q instance_class = "db.r3.large" @@ -664,8 +669,8 @@ resource "aws_rds_global_cluster" "test" { func testAccGlobalClusterStorageEncryptedConfig(rName string, storageEncrypted bool) string { return fmt.Sprintf(` resource "aws_rds_global_cluster" "test" { - global_cluster_identifier = %q - storage_encrypted = %t + global_cluster_identifier = %[1]q + storage_encrypted = %[2]t } `, rName, storageEncrypted) } diff --git a/internal/service/rds/instance_data_source_test.go b/internal/service/rds/instance_data_source_test.go index 59164d71ac2..832f18ae86e 100644 --- a/internal/service/rds/instance_data_source_test.go +++ b/internal/service/rds/instance_data_source_test.go @@ -11,14 +11,15 @@ import ( ) func TestAccRDSInstanceDataSource_basic(t *testing.T) { - rInt := sdkacctest.RandInt() + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, ErrorCheck: acctest.ErrorCheck(t, rds.EndpointsID), Providers: acctest.Providers, Steps: []resource.TestStep{ { - Config: testAccInstanceDataSourceConfig(rInt), + Config: testAccInstanceDataSourceConfig(rName), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttrSet("data.aws_db_instance.bar", "address"), resource.TestCheckResourceAttrSet("data.aws_db_instance.bar", "allocated_storage"), @@ -44,7 +45,7 @@ func TestAccRDSInstanceDataSource_basic(t *testing.T) { } func TestAccRDSInstanceDataSource_ec2Classic(t *testing.T) { - rInt := sdkacctest.RandInt() + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t); acctest.PreCheckEC2Classic(t) }, @@ -52,7 +53,7 @@ func TestAccRDSInstanceDataSource_ec2Classic(t *testing.T) { ProviderFactories: acctest.ProviderFactories, Steps: []resource.TestStep{ { - Config: testAccInstanceDataSourceConfig_ec2Classic(rInt), + Config: testAccInstanceDataSourceConfig_ec2Classic(rName), Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.aws_db_instance.bar", "db_subnet_group", ""), ), @@ -61,7 +62,7 @@ func TestAccRDSInstanceDataSource_ec2Classic(t *testing.T) { }) } -func testAccInstanceDataSourceConfig(rInt int) string { +func testAccInstanceDataSourceConfig(rName string) string { return fmt.Sprintf(` data "aws_rds_orderable_db_instance" "test" { engine = "mariadb" @@ -69,7 +70,7 @@ data "aws_rds_orderable_db_instance" "test" { } resource "aws_db_instance" "bar" { - identifier = "datasource-test-terraform-%d" + identifier = %[1]q allocated_storage = 10 engine = data.aws_rds_orderable_db_instance.test.engine @@ -94,21 +95,21 @@ resource "aws_db_instance" "bar" { data "aws_db_instance" "bar" { db_instance_identifier = aws_db_instance.bar.identifier } -`, rInt) +`, rName) } -func testAccInstanceDataSourceConfig_ec2Classic(rInt int) string { +func testAccInstanceDataSourceConfig_ec2Classic(rName string) string { return acctest.ConfigCompose( acctest.ConfigEC2ClassicRegionProvider(), fmt.Sprintf(` data "aws_rds_orderable_db_instance" "test" { engine = "mysql" - engine_version = "5.6.41" - preferred_instance_classes = ["db.m3.medium", "db.m3.large", "db.r3.large"] + engine_version = "8.0.25" + preferred_instance_classes = ["db.t2.micro", "db.m3.medium", "db.m3.large", "db.r3.large"] } resource "aws_db_instance" "bar" { - identifier = "foobarbaz-test-terraform-%[1]d" + identifier = %[1]q allocated_storage = 10 engine = data.aws_rds_orderable_db_instance.test.engine engine_version = data.aws_rds_orderable_db_instance.test.engine_version @@ -118,12 +119,12 @@ resource "aws_db_instance" "bar" { username = "foo" publicly_accessible = true security_group_names = ["default"] - parameter_group_name = "default.mysql5.6" + parameter_group_name = "default.mysql8.0" skip_final_snapshot = true } data "aws_db_instance" "bar" { db_instance_identifier = aws_db_instance.bar.identifier } -`, rInt)) +`, rName)) } diff --git a/internal/service/rds/instance_test.go b/internal/service/rds/instance_test.go index 0b3f177b1d4..63610423e33 100644 --- a/internal/service/rds/instance_test.go +++ b/internal/service/rds/instance_test.go @@ -6319,9 +6319,11 @@ resource "aws_db_instance" "test" { } func testAccInstanceConfig_ReplicateSourceDB_AllocatedStorage(rName string, allocatedStorage int) string { - return acctest.ConfigCompose(testAccInstanceConfig_orderableClassMySQL(), fmt.Sprintf(` + return acctest.ConfigCompose( + testAccInstanceConfig_orderableClassMySQL(), + fmt.Sprintf(` resource "aws_db_instance" "source" { - allocated_storage = 5 + allocated_storage = %[2]d backup_retention_period = 1 engine = data.aws_rds_orderable_db_instance.test.engine identifier = "%[1]s-source" diff --git a/internal/service/rds/option_group_test.go b/internal/service/rds/option_group_test.go index 9b6d461d38d..1789e519b32 100644 --- a/internal/service/rds/option_group_test.go +++ b/internal/service/rds/option_group_test.go @@ -18,7 +18,8 @@ import ( func TestAccRDSOptionGroup_basic(t *testing.T) { var v rds.OptionGroup - rName := fmt.Sprintf("option-group-test-terraform-%s", sdkacctest.RandString(5)) + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_db_option_group.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -29,18 +30,18 @@ func TestAccRDSOptionGroup_basic(t *testing.T) { { Config: testAccOptionGroupBasicConfig(rName), Check: resource.ComposeTestCheckFunc( - testAccCheckOptionGroupExists("aws_db_option_group.bar", &v), - acctest.MatchResourceAttrRegionalARN("aws_db_option_group.bar", "arn", "rds", regexp.MustCompile(`og:.+`)), - resource.TestCheckResourceAttr("aws_db_option_group.bar", "engine_name", "mysql"), - resource.TestCheckResourceAttr("aws_db_option_group.bar", "major_engine_version", "5.6"), - resource.TestCheckResourceAttr("aws_db_option_group.bar", "name", rName), - resource.TestCheckResourceAttr("aws_db_option_group.bar", "option.#", "0"), - resource.TestCheckResourceAttr("aws_db_option_group.bar", "option_group_description", "Managed by Terraform"), - resource.TestCheckResourceAttr("aws_db_option_group.bar", "tags.%", "0"), + testAccCheckOptionGroupExists(resourceName, &v), + acctest.MatchResourceAttrRegionalARN(resourceName, "arn", "rds", regexp.MustCompile(`og:.+`)), + resource.TestCheckResourceAttr(resourceName, "engine_name", "mysql"), + resource.TestCheckResourceAttr(resourceName, "major_engine_version", "8.0"), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "option.#", "0"), + resource.TestCheckResourceAttr(resourceName, "option_group_description", "Managed by Terraform"), + resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), ), }, { - ResourceName: "aws_db_option_group.bar", + ResourceName: resourceName, ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{"name_prefix"}, @@ -51,7 +52,8 @@ func TestAccRDSOptionGroup_basic(t *testing.T) { func TestAccRDSOptionGroup_timeoutBlock(t *testing.T) { var v rds.OptionGroup - rName := fmt.Sprintf("option-group-test-terraform-%s", sdkacctest.RandString(5)) + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_db_option_group.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -62,13 +64,12 @@ func TestAccRDSOptionGroup_timeoutBlock(t *testing.T) { { Config: testAccOptionGroupBasicTimeoutBlockConfig(rName), Check: resource.ComposeTestCheckFunc( - testAccCheckOptionGroupExists("aws_db_option_group.bar", &v), - resource.TestCheckResourceAttr( - "aws_db_option_group.bar", "name", rName), + testAccCheckOptionGroupExists(resourceName, &v), + resource.TestCheckResourceAttr(resourceName, "name", rName), ), }, { - ResourceName: "aws_db_option_group.bar", + ResourceName: resourceName, ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{"name_prefix"}, @@ -90,8 +91,7 @@ func TestAccRDSOptionGroup_namePrefix(t *testing.T) { Config: testAccOptionGroup_namePrefix, Check: resource.ComposeTestCheckFunc( testAccCheckOptionGroupExists("aws_db_option_group.test", &v), - resource.TestMatchResourceAttr( - "aws_db_option_group.test", "name", regexp.MustCompile("^tf-test-")), + resource.TestMatchResourceAttr("aws_db_option_group.test", "name", regexp.MustCompile("^tf-test-")), ), }, { @@ -158,7 +158,8 @@ func TestAccRDSOptionGroup_optionGroupDescription(t *testing.T) { } func TestAccRDSOptionGroup_basicDestroyWithInstance(t *testing.T) { - rName := fmt.Sprintf("option-group-test-terraform-%s", sdkacctest.RandString(5)) + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_db_option_group.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -170,7 +171,7 @@ func TestAccRDSOptionGroup_basicDestroyWithInstance(t *testing.T) { Config: testAccOptionGroupBasicDestroyConfig(rName), }, { - ResourceName: "aws_db_option_group.bar", + ResourceName: resourceName, ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{"name_prefix"}, @@ -181,7 +182,8 @@ func TestAccRDSOptionGroup_basicDestroyWithInstance(t *testing.T) { func TestAccRDSOptionGroup_Option_optionSettings(t *testing.T) { var v rds.OptionGroup - rName := fmt.Sprintf("option-group-test-terraform-%s", sdkacctest.RandString(5)) + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_db_option_group.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -192,18 +194,16 @@ func TestAccRDSOptionGroup_Option_optionSettings(t *testing.T) { { Config: testAccOptionGroupOptionSettings(rName), Check: resource.ComposeTestCheckFunc( - testAccCheckOptionGroupExists("aws_db_option_group.bar", &v), - resource.TestCheckResourceAttr( - "aws_db_option_group.bar", "name", rName), - resource.TestCheckResourceAttr( - "aws_db_option_group.bar", "option.#", "1"), - resource.TestCheckTypeSetElemNestedAttrs("aws_db_option_group.bar", "option.*.option_settings.*", map[string]string{ + testAccCheckOptionGroupExists(resourceName, &v), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "option.#", "1"), + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "option.*.option_settings.*", map[string]string{ "value": "UTC", }), ), }, { - ResourceName: "aws_db_option_group.bar", + ResourceName: resourceName, ImportState: true, ImportStateVerify: true, // Ignore option since our current logic skips "unconfigured" default option settings @@ -213,19 +213,17 @@ func TestAccRDSOptionGroup_Option_optionSettings(t *testing.T) { { Config: testAccOptionGroupOptionSettings_update(rName), Check: resource.ComposeTestCheckFunc( - testAccCheckOptionGroupExists("aws_db_option_group.bar", &v), - resource.TestCheckResourceAttr( - "aws_db_option_group.bar", "name", rName), - resource.TestCheckResourceAttr( - "aws_db_option_group.bar", "option.#", "1"), - resource.TestCheckTypeSetElemNestedAttrs("aws_db_option_group.bar", "option.*.option_settings.*", map[string]string{ + testAccCheckOptionGroupExists(resourceName, &v), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "option.#", "1"), + resource.TestCheckTypeSetElemNestedAttrs(resourceName, "option.*.option_settings.*", map[string]string{ "value": "US/Pacific", }), ), }, // Ensure we can import non-default value option settings { - ResourceName: "aws_db_option_group.bar", + ResourceName: resourceName, ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{"name_prefix"}, @@ -236,7 +234,8 @@ func TestAccRDSOptionGroup_Option_optionSettings(t *testing.T) { func TestAccRDSOptionGroup_OptionOptionSettings_iamRole(t *testing.T) { var v rds.OptionGroup - rName := fmt.Sprintf("option-group-test-terraform-%s", sdkacctest.RandString(5)) + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_db_option_group.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -247,16 +246,14 @@ func TestAccRDSOptionGroup_OptionOptionSettings_iamRole(t *testing.T) { { Config: testAccOptionGroupOptionSettingsIAMRole(rName), Check: resource.ComposeTestCheckFunc( - testAccCheckOptionGroupExists("aws_db_option_group.bar", &v), - resource.TestCheckResourceAttr( - "aws_db_option_group.bar", "name", rName), - resource.TestCheckResourceAttr( - "aws_db_option_group.bar", "option.#", "1"), + testAccCheckOptionGroupExists(resourceName, &v), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "option.#", "1"), testAccCheckOptionGroupOptionSettingsIAMRole(&v), ), }, { - ResourceName: "aws_db_option_group.bar", + ResourceName: resourceName, ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{"name_prefix"}, @@ -267,7 +264,8 @@ func TestAccRDSOptionGroup_OptionOptionSettings_iamRole(t *testing.T) { func TestAccRDSOptionGroup_sqlServerOptionsUpdate(t *testing.T) { var v rds.OptionGroup - rName := fmt.Sprintf("option-group-test-terraform-%s", sdkacctest.RandString(5)) + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_db_option_group.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -278,13 +276,12 @@ func TestAccRDSOptionGroup_sqlServerOptionsUpdate(t *testing.T) { { Config: testAccOptionGroupSQLServerEEOptions(rName), Check: resource.ComposeTestCheckFunc( - testAccCheckOptionGroupExists("aws_db_option_group.bar", &v), - resource.TestCheckResourceAttr( - "aws_db_option_group.bar", "name", rName), + testAccCheckOptionGroupExists(resourceName, &v), + resource.TestCheckResourceAttr(resourceName, "name", rName), ), }, { - ResourceName: "aws_db_option_group.bar", + ResourceName: resourceName, ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{"name_prefix"}, @@ -292,11 +289,9 @@ func TestAccRDSOptionGroup_sqlServerOptionsUpdate(t *testing.T) { { Config: testAccOptionGroupSQLServerEEOptions_update(rName), Check: resource.ComposeTestCheckFunc( - testAccCheckOptionGroupExists("aws_db_option_group.bar", &v), - resource.TestCheckResourceAttr( - "aws_db_option_group.bar", "name", rName), - resource.TestCheckResourceAttr( - "aws_db_option_group.bar", "option.#", "1"), + testAccCheckOptionGroupExists(resourceName, &v), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "option.#", "1"), ), }, }, @@ -305,7 +300,8 @@ func TestAccRDSOptionGroup_sqlServerOptionsUpdate(t *testing.T) { func TestAccRDSOptionGroup_oracleOptionsUpdate(t *testing.T) { var v rds.OptionGroup - rName := fmt.Sprintf("option-group-test-terraform-%s", sdkacctest.RandString(5)) + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_db_option_group.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -316,16 +312,14 @@ func TestAccRDSOptionGroup_oracleOptionsUpdate(t *testing.T) { { Config: testAccOptionGroupOracleEEOptionSettings(rName, "13.2.0.0.v2"), Check: resource.ComposeTestCheckFunc( - testAccCheckOptionGroupExists("aws_db_option_group.bar", &v), - resource.TestCheckResourceAttr( - "aws_db_option_group.bar", "name", rName), - resource.TestCheckResourceAttr( - "aws_db_option_group.bar", "option.#", "1"), + testAccCheckOptionGroupExists(resourceName, &v), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "option.#", "1"), testAccCheckOptionGroupOptionVersionAttribute(&v, "13.2.0.0.v2"), ), }, { - ResourceName: "aws_db_option_group.bar", + ResourceName: resourceName, ImportState: true, ImportStateVerify: true, // Ignore option since API responds with **** instead of password @@ -334,11 +328,9 @@ func TestAccRDSOptionGroup_oracleOptionsUpdate(t *testing.T) { { Config: testAccOptionGroupOracleEEOptionSettings(rName, "13.3.0.0.v2"), Check: resource.ComposeTestCheckFunc( - testAccCheckOptionGroupExists("aws_db_option_group.bar", &v), - resource.TestCheckResourceAttr( - "aws_db_option_group.bar", "name", rName), - resource.TestCheckResourceAttr( - "aws_db_option_group.bar", "option.#", "1"), + testAccCheckOptionGroupExists(resourceName, &v), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "option.#", "1"), testAccCheckOptionGroupOptionVersionAttribute(&v, "13.3.0.0.v2"), ), }, @@ -384,7 +376,8 @@ func TestAccRDSOptionGroup_OptionOptionSettings_multipleNonDefault(t *testing.T) func TestAccRDSOptionGroup_multipleOptions(t *testing.T) { var v rds.OptionGroup - rName := fmt.Sprintf("option-group-test-terraform-%s", sdkacctest.RandString(5)) + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_db_option_group.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -395,15 +388,13 @@ func TestAccRDSOptionGroup_multipleOptions(t *testing.T) { { Config: testAccOptionGroupMultipleOptions(rName), Check: resource.ComposeTestCheckFunc( - testAccCheckOptionGroupExists("aws_db_option_group.bar", &v), - resource.TestCheckResourceAttr( - "aws_db_option_group.bar", "name", rName), - resource.TestCheckResourceAttr( - "aws_db_option_group.bar", "option.#", "2"), + testAccCheckOptionGroupExists(resourceName, &v), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "option.#", "2"), ), }, { - ResourceName: "aws_db_option_group.bar", + ResourceName: resourceName, ImportState: true, ImportStateVerify: true, ImportStateVerifyIgnore: []string{"name_prefix"}, @@ -613,38 +604,38 @@ func testAccCheckOptionGroupDestroy(s *terraform.State) error { return nil } -func testAccOptionGroupBasicTimeoutBlockConfig(r string) string { +func testAccOptionGroupBasicTimeoutBlockConfig(rName string) string { return fmt.Sprintf(` -resource "aws_db_option_group" "bar" { - name = "%s" +resource "aws_db_option_group" "test" { + name = %[1]q option_group_description = "Test option group for terraform" engine_name = "mysql" - major_engine_version = "5.6" + major_engine_version = "8.0" timeouts { delete = "10m" } } -`, r) +`, rName) } -func testAccOptionGroupBasicConfig(r string) string { +func testAccOptionGroupBasicConfig(rName string) string { return fmt.Sprintf(` -resource "aws_db_option_group" "bar" { - name = "%s" +resource "aws_db_option_group" "test" { + name = %[1]q engine_name = "mysql" - major_engine_version = "5.6" + major_engine_version = "8.0" } -`, r) +`, rName) } -func testAccOptionGroupBasicDestroyConfig(r string) string { +func testAccOptionGroupBasicDestroyConfig(rName string) string { return fmt.Sprintf(` -resource "aws_db_instance" "bar" { +resource "aws_db_instance" "test" { allocated_storage = 10 - engine = "mysql" - engine_version = "5.6.35" - instance_class = "db.t2.micro" + engine = data.aws_rds_orderable_db_instance.test.engine + engine_version = data.aws_rds_orderable_db_instance.test.engine_version + instance_class = data.aws_rds_orderable_db_instance.test.instance_class name = "baz" password = "barbarbarbar" username = "foo" @@ -657,22 +648,31 @@ resource "aws_db_instance" "bar" { backup_retention_period = 0 skip_final_snapshot = true - option_group_name = aws_db_option_group.bar.name + option_group_name = aws_db_option_group.test.name } -resource "aws_db_option_group" "bar" { - name = "%s" +data "aws_rds_orderable_db_instance" "test" { + engine = "mysql" + license_model = "general-public-license" + storage_type = "standard" + + preferred_engine_versions = ["8.0.25", "8.0.26", "8.0.27"] + preferred_instance_classes = ["db.t2.micro", "db.t2.small", "db.t3.medium", "db.t3.large"] +} + +resource "aws_db_option_group" "test" { + name = %[1]q option_group_description = "Test option group for terraform" engine_name = "mysql" - major_engine_version = "5.6" + major_engine_version = "8.0" } -`, r) +`, rName) } -func testAccOptionGroupOptionSettings(r string) string { +func testAccOptionGroupOptionSettings(rName string) string { return fmt.Sprintf(` -resource "aws_db_option_group" "bar" { - name = "%s" +resource "aws_db_option_group" "test" { + name = %[1]q option_group_description = "Test option group for terraform" engine_name = "oracle-ee" major_engine_version = "12.2" @@ -686,10 +686,10 @@ resource "aws_db_option_group" "bar" { } } } -`, r) +`, rName) } -func testAccOptionGroupOptionSettingsIAMRole(r string) string { +func testAccOptionGroupOptionSettingsIAMRole(rName string) string { return fmt.Sprintf(` data "aws_partition" "current" {} @@ -709,8 +709,8 @@ resource "aws_iam_role" "sql_server_backup" { assume_role_policy = data.aws_iam_policy_document.rds_assume_role.json } -resource "aws_db_option_group" "bar" { - name = "%[1]s" +resource "aws_db_option_group" "test" { + name = %[1]q option_group_description = "Test option group for terraform" engine_name = "sqlserver-ex" major_engine_version = "14.00" @@ -724,13 +724,13 @@ resource "aws_db_option_group" "bar" { } } } -`, r) +`, rName) } -func testAccOptionGroupOptionSettings_update(r string) string { +func testAccOptionGroupOptionSettings_update(rName string) string { return fmt.Sprintf(` -resource "aws_db_option_group" "bar" { - name = "%s" +resource "aws_db_option_group" "test" { + name = %[1]q option_group_description = "Test option group for terraform" engine_name = "oracle-ee" major_engine_version = "12.2" @@ -744,24 +744,24 @@ resource "aws_db_option_group" "bar" { } } } -`, r) +`, rName) } -func testAccOptionGroupSQLServerEEOptions(r string) string { +func testAccOptionGroupSQLServerEEOptions(rName string) string { return fmt.Sprintf(` -resource "aws_db_option_group" "bar" { - name = "%s" +resource "aws_db_option_group" "test" { + name = %[1]q option_group_description = "Test option group for terraform" engine_name = "sqlserver-ee" major_engine_version = "11.00" } -`, r) +`, rName) } -func testAccOptionGroupSQLServerEEOptions_update(r string) string { +func testAccOptionGroupSQLServerEEOptions_update(rName string) string { return fmt.Sprintf(` -resource "aws_db_option_group" "bar" { - name = "%s" +resource "aws_db_option_group" "test" { + name = %[1]q option_group_description = "Test option group for terraform" engine_name = "sqlserver-ee" major_engine_version = "11.00" @@ -770,17 +770,17 @@ resource "aws_db_option_group" "bar" { option_name = "TDE" } } -`, r) +`, rName) } -func testAccOptionGroupOracleEEOptionSettings(r, optionVersion string) string { +func testAccOptionGroupOracleEEOptionSettings(rName, optionVersion string) string { return fmt.Sprintf(` resource "aws_security_group" "foo" { - name = "%[1]s" + name = %[1]q } -resource "aws_db_option_group" "bar" { - name = "%[1]s" +resource "aws_db_option_group" "test" { + name = %[1]q option_group_description = "Test option group for terraform issue 748" engine_name = "oracle-ee" major_engine_version = "12.2" @@ -788,7 +788,7 @@ resource "aws_db_option_group" "bar" { option { option_name = "OEM_AGENT" port = "3872" - version = "%[2]s" + version = %[2]q vpc_security_group_memberships = [aws_security_group.foo.id] @@ -808,13 +808,13 @@ resource "aws_db_option_group" "bar" { } } } -`, r, optionVersion) +`, rName, optionVersion) } -func testAccOptionGroupMultipleOptions(r string) string { +func testAccOptionGroupMultipleOptions(rName string) string { return fmt.Sprintf(` -resource "aws_db_option_group" "bar" { - name = "%s" +resource "aws_db_option_group" "test" { + name = %[1]q option_group_description = "Test option group for terraform" engine_name = "oracle-ee" major_engine_version = "12.2" @@ -827,7 +827,7 @@ resource "aws_db_option_group" "bar" { option_name = "STATSPACK" } } -`, r) +`, rName) } const testAccOptionGroup_namePrefix = ` @@ -835,7 +835,7 @@ resource "aws_db_option_group" "test" { name_prefix = "tf-test-" option_group_description = "Test option group for terraform" engine_name = "mysql" - major_engine_version = "5.6" + major_engine_version = "8.0" } ` @@ -843,7 +843,7 @@ const testAccOptionGroup_generatedName = ` resource "aws_db_option_group" "test" { option_group_description = "Test option group for terraform" engine_name = "mysql" - major_engine_version = "5.6" + major_engine_version = "8.0" } ` @@ -851,9 +851,9 @@ func testAccOptionGroupOptionGroupDescriptionConfig(rName, optionGroupDescriptio return fmt.Sprintf(` resource "aws_db_option_group" "test" { engine_name = "mysql" - major_engine_version = "5.6" - name = %q - option_group_description = %q + major_engine_version = "8.0" + name = %[1]q + option_group_description = %[2]q } `, rName, optionGroupDescription) } @@ -862,15 +862,15 @@ func testAccOptionGroupOptionOptionSettingsMultipleConfig(rName, value string) s return fmt.Sprintf(` resource "aws_db_option_group" "test" { engine_name = "mysql" - major_engine_version = "5.6" - name = %q + major_engine_version = "8.0" + name = %[1]q option { option_name = "MARIADB_AUDIT_PLUGIN" option_settings { name = "SERVER_AUDIT_EXCL_USERS" - value = %q + value = %[2]q } option_settings { @@ -891,11 +891,11 @@ func testAccOptionGroupTags1Config(rName, tagKey1, tagValue1 string) string { return fmt.Sprintf(` resource "aws_db_option_group" "test" { engine_name = "mysql" - major_engine_version = "5.6" - name = %q + major_engine_version = "8.0" + name = %[1]q tags = { - %q = %q + %[2]q = %[3]q } } `, rName, tagKey1, tagValue1) @@ -905,12 +905,12 @@ func testAccOptionGroupTags2Config(rName, tagKey1, tagValue1, tagKey2, tagValue2 return fmt.Sprintf(` resource "aws_db_option_group" "test" { engine_name = "mysql" - major_engine_version = "5.6" - name = %q + major_engine_version = "8.0" + name = %[1]q tags = { - %q = %q - %q = %q + %[2]q = %[3]q + %[4]q = %[5]q } } `, rName, tagKey1, tagValue1, tagKey2, tagValue2) @@ -920,8 +920,8 @@ func testAccOptionGroupTagsWithOption1Config(rName, tagKey1, tagValue1 string) s return fmt.Sprintf(` resource "aws_db_option_group" "test" { engine_name = "mysql" - major_engine_version = "5.6" - name = %q + major_engine_version = "8.0" + name = %[1]q option { option_name = "MARIADB_AUDIT_PLUGIN" @@ -933,7 +933,7 @@ resource "aws_db_option_group" "test" { } tags = { - %q = %q + %[2]q = %[3]q } } `, rName, tagKey1, tagValue1) @@ -943,8 +943,8 @@ func testAccOptionGroupTagsWithOption2Config(rName, tagKey1, tagValue1, tagKey2, return fmt.Sprintf(` resource "aws_db_option_group" "test" { engine_name = "mysql" - major_engine_version = "5.6" - name = %q + major_engine_version = "8.0" + name = %[1]q option { option_name = "MARIADB_AUDIT_PLUGIN" @@ -956,8 +956,8 @@ resource "aws_db_option_group" "test" { } tags = { - %q = %q - %q = %q + %[2]q = %[3]q + %[4]q = %[5]q } } `, rName, tagKey1, tagValue1, tagKey2, tagValue2) From 8fd58b0b1c57add1b2fc932ea9ba27e67036b413 Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Mon, 7 Mar 2022 20:15:20 -0500 Subject: [PATCH 02/32] Add constants for instance classes --- internal/service/rds/consts.go | 75 +++++++++++++++++++++++++++++ internal/service/rds/consts_test.go | 12 +++++ 2 files changed, 87 insertions(+) create mode 100644 internal/service/rds/consts.go create mode 100644 internal/service/rds/consts_test.go diff --git a/internal/service/rds/consts.go b/internal/service/rds/consts.go new file mode 100644 index 00000000000..c31b4aa776e --- /dev/null +++ b/internal/service/rds/consts.go @@ -0,0 +1,75 @@ +package rds + +const ( + ClusterRoleStatusActive = "ACTIVE" + ClusterRoleStatusDeleted = "DELETED" + ClusterRoleStatusPending = "PENDING" +) + +const ( + StorageTypeStandard = "standard" + StorageTypeGp2 = "gp2" + StorageTypeIo1 = "io1" +) + +func StorageType_Values() []string { + return []string{ + StorageTypeStandard, + StorageTypeGp2, + StorageTypeIo1, + } +} + +// https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/accessing-monitoring.html#Overview.DBInstance.Status. +const ( + InstanceStatusAvailable = "available" + InstanceStatusBackingUp = "backing-up" + InstanceStatusConfiguringEnhancedMonitoring = "configuring-enhanced-monitoring" + InstanceStatusConfiguringLogExports = "configuring-log-exports" + InstanceStatusCreating = "creating" + InstanceStatusDeleting = "deleting" + InstanceStatusIncompatibleParameters = "incompatible-parameters" + InstanceStatusIncompatibleRestore = "incompatible-restore" + InstanceStatusModifying = "modifying" + InstanceStatusStarting = "starting" + InstanceStatusStopping = "stopping" + InstanceStatusStorageFull = "storage-full" + InstanceStatusStorageOptimization = "storage-optimization" +) + +const ( + EventSubscriptionStatusActive = "active" + EventSubscriptionStatusCreating = "creating" + EventSubscriptionStatusDeleting = "deleting" + EventSubscriptionStatusModifying = "modifying" +) + +const ( + ExportableLogTypeAgent = "agent" + ExportableLogTypeAlert = "alert" + ExportableLogTypeAudit = "audit" + ExportableLogTypeError = "error" + ExportableLogTypeGeneral = "general" + ExportableLogTypeListener = "listener" + ExportableLogTypeOEMAgent = "oemagent" + ExportableLogTypePostgreSQL = "postgresql" + ExportableLogTypeSlowQuery = "slowquery" + ExportableLogTypeTrace = "trace" + ExportableLogTypeUpgrade = "upgrade" +) + +func ExportableLogType_Values() []string { + return []string{ + ExportableLogTypeAgent, + ExportableLogTypeAlert, + ExportableLogTypeAudit, + ExportableLogTypeError, + ExportableLogTypeGeneral, + ExportableLogTypeListener, + ExportableLogTypeOEMAgent, + ExportableLogTypePostgreSQL, + ExportableLogTypeSlowQuery, + ExportableLogTypeTrace, + ExportableLogTypeUpgrade, + } +} diff --git a/internal/service/rds/consts_test.go b/internal/service/rds/consts_test.go new file mode 100644 index 00000000000..b2e22376478 --- /dev/null +++ b/internal/service/rds/consts_test.go @@ -0,0 +1,12 @@ +package rds_test + +const ( + // Please make sure GovCloud and commercial support these since they vary + postgresPreferredInstanceClasses = `"db.t3.micro", "db.t3.small", "db.t2.small", "db.t2.medium"` + mySQLPreferredInstanceClasses = `"db.t3.micro", "db.t3.small", "db.t2.small", "db.t2.medium"` + mariaDBPreferredInstanceClasses = `"db.t3.micro", "db.t3.small", "db.t2.small", "db.t2.medium"` + oraclePreferredInstanceClasses = `"db.t3.medium", "db.t2.medium", "db.t3.large", "db.t2.large"` // Oracle requires at least a medium instance as a replica source + sqlServerPreferredInstanceClasses = `"db.t2.small", "db.t3.small"` + sqlServerSEPreferredInstanceClasses = `"db.m5.large", "db.m4.large", "db.r4.large"` + oracleSE2PreferredInstanceClasses = `"db.m5.large", "db.m4.large", "db.r4.large"` +) From 44832e1a350cd0a657d6b9b919a84259f6d307da Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Mon, 7 Mar 2022 20:15:49 -0500 Subject: [PATCH 03/32] rds/cluster: Debugging --- internal/service/rds/cluster.go | 33 ++++++++------------------------- 1 file changed, 8 insertions(+), 25 deletions(-) diff --git a/internal/service/rds/cluster.go b/internal/service/rds/cluster.go index d7d9e5874f2..31391e56678 100644 --- a/internal/service/rds/cluster.go +++ b/internal/service/rds/cluster.go @@ -23,9 +23,9 @@ import ( ) const ( - rdsClusterScalingConfiguration_DefaultMinCapacity = 1 - rdsClusterScalingConfiguration_DefaultMaxCapacity = 16 - rdsClusterTimeoutDelete = 2 * time.Minute + clusterScalingConfiguration_DefaultMinCapacity = 1 + clusterScalingConfiguration_DefaultMaxCapacity = 16 + clusterTimeoutDelete = 2 * time.Minute ) func ResourceCluster() *schema.Resource { @@ -205,12 +205,12 @@ func ResourceCluster() *schema.Resource { "max_capacity": { Type: schema.TypeInt, Optional: true, - Default: rdsClusterScalingConfiguration_DefaultMaxCapacity, + Default: clusterScalingConfiguration_DefaultMaxCapacity, }, "min_capacity": { Type: schema.TypeInt, Optional: true, - Default: rdsClusterScalingConfiguration_DefaultMinCapacity, + Default: clusterScalingConfiguration_DefaultMinCapacity, }, "seconds_until_auto_pause": { Type: schema.TypeInt, @@ -1084,7 +1084,7 @@ func resourceClusterRead(d *schema.ResourceData, meta interface{}) error { d.Set("hosted_zone_id", dbc.HostedZoneId) d.Set("iam_database_authentication_enabled", dbc.IAMDatabaseAuthenticationEnabled) - rdsClusterSetResourceDataEngineVersionFromCluster(d, dbc) + clusterSetResourceDataEngineVersionFromCluster(d, dbc) var roles []string for _, r := range dbc.AssociatedRoles { @@ -1401,7 +1401,7 @@ func resourceClusterDelete(d *schema.ResourceData, meta interface{}) error { log.Printf("[DEBUG] RDS Cluster delete options: %s", deleteOpts) - err := resource.Retry(rdsClusterTimeoutDelete, func() *resource.RetryError { + err := resource.Retry(clusterTimeoutDelete, func() *resource.RetryError { _, err := conn.DeleteDBCluster(&deleteOpts) if err != nil { if tfawserr.ErrMessageContains(err, rds.ErrCodeInvalidDBClusterStateFault, "is not currently in the available state") { @@ -1538,25 +1538,8 @@ func WaitForClusterDeletion(conn *rds.RDS, id string, timeout time.Duration) err return err } -func rdsClusterSetResourceDataEngineVersionFromCluster(d *schema.ResourceData, c *rds.DBCluster) { +func clusterSetResourceDataEngineVersionFromCluster(d *schema.ResourceData, c *rds.DBCluster) { oldVersion := d.Get("engine_version").(string) newVersion := aws.StringValue(c.EngineVersion) compareActualEngineVersion(d, oldVersion, newVersion) } - -func compareActualEngineVersion(d *schema.ResourceData, oldVersion string, newVersion string) { - newVersionSubstr := newVersion - - if len(newVersion) > len(oldVersion) { - newVersionSubstr = string([]byte(newVersion)[0 : len(oldVersion)+1]) - } - - if oldVersion != newVersion && string(append([]byte(oldVersion), []byte(".")...)) != newVersionSubstr { - d.Set("engine_version", newVersion) - fmt.Printf("[READ/cluster] engine_version: %s\n", newVersion) - } - - d.Set("engine_version_actual", newVersion) - fmt.Printf("[READ/cluster] engine_version_actual: %s\n", newVersion) - -} From bbf84038e3793df52f7d44ab65ea40f8cdd0dbdc Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Mon, 7 Mar 2022 20:16:16 -0500 Subject: [PATCH 04/32] rds/instance: Modernize tests --- internal/service/rds/instance_test.go | 696 +++++++++++++------------- 1 file changed, 349 insertions(+), 347 deletions(-) diff --git a/internal/service/rds/instance_test.go b/internal/service/rds/instance_test.go index 63610423e33..7c3ac2a553f 100644 --- a/internal/service/rds/instance_test.go +++ b/internal/service/rds/instance_test.go @@ -173,7 +173,7 @@ func TestAccRDSInstance_onlyMajorVersion(t *testing.T) { CheckDestroy: testAccCheckClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_MajorVersionOnly(engine, engineVersion), + Config: testAccInstanceConfig_MajorVersionOnly(), Check: resource.ComposeTestCheckFunc( testAccCheckInstanceExists(resourceName, &dbInstance1), resource.TestCheckResourceAttr(resourceName, "engine", engine), @@ -260,6 +260,7 @@ func TestAccRDSInstance_kmsKey(t *testing.T) { var v rds.DBInstance kmsKeyResourceName := "aws_kms_key.foo" resourceName := "aws_db_instance.bar" + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -268,7 +269,7 @@ func TestAccRDSInstance_kmsKey(t *testing.T) { CheckDestroy: testAccCheckInstanceDestroy, Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_KMSKeyID(sdkacctest.RandInt()), + Config: testAccInstanceConfig_KMSKeyID(rName), Check: resource.ComposeTestCheckFunc( testAccCheckInstanceExists(resourceName, &v), testAccCheckInstanceAttributes(&v), @@ -293,7 +294,7 @@ func TestAccRDSInstance_kmsKey(t *testing.T) { func TestAccRDSInstance_subnetGroup(t *testing.T) { var v rds.DBInstance - rName := sdkacctest.RandString(10) + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -324,7 +325,7 @@ func TestAccRDSInstance_subnetGroup(t *testing.T) { func TestAccRDSInstance_optionGroup(t *testing.T) { var v rds.DBInstance - rName := fmt.Sprintf("tf-option-test-%d", sdkacctest.RandInt()) + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -347,6 +348,7 @@ func TestAccRDSInstance_optionGroup(t *testing.T) { func TestAccRDSInstance_iamAuth(t *testing.T) { var v rds.DBInstance + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -355,7 +357,7 @@ func TestAccRDSInstance_iamAuth(t *testing.T) { CheckDestroy: testAccCheckInstanceDestroy, Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_IAMAuth(sdkacctest.RandInt()), + Config: testAccInstanceConfig_IAMAuth(rName), Check: resource.ComposeTestCheckFunc( testAccCheckInstanceExists("aws_db_instance.bar", &v), testAccCheckInstanceAttributes(&v), @@ -536,7 +538,7 @@ func TestAccRDSInstance_deletionProtection(t *testing.T) { func TestAccRDSInstance_finalSnapshotIdentifier(t *testing.T) { var snap rds.DBInstance - rInt := sdkacctest.RandInt() + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -547,7 +549,7 @@ func TestAccRDSInstance_finalSnapshotIdentifier(t *testing.T) { CheckDestroy: testAccCheckInstanceSnapshot, Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_FinalSnapshotIdentifier(rInt), + Config: testAccInstanceConfig_FinalSnapshotIdentifier(rName), Check: resource.ComposeTestCheckFunc( testAccCheckInstanceExists("aws_db_instance.snapshot", &snap), ), @@ -558,6 +560,7 @@ func TestAccRDSInstance_finalSnapshotIdentifier(t *testing.T) { func TestAccRDSInstance_FinalSnapshotIdentifier_skipFinalSnapshot(t *testing.T) { var snap rds.DBInstance + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -566,7 +569,7 @@ func TestAccRDSInstance_FinalSnapshotIdentifier_skipFinalSnapshot(t *testing.T) CheckDestroy: testAccCheckInstanceNoSnapshot, Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_FinalSnapshotIdentifier_SkipFinalSnapshot(), + Config: testAccInstanceConfig_FinalSnapshotIdentifier_SkipFinalSnapshot(rName), Check: resource.ComposeTestCheckFunc( testAccCheckInstanceExists("aws_db_instance.snapshot", &snap), ), @@ -1571,8 +1574,7 @@ func TestAccRDSInstance_ReplicateSourceDB_parameterGroupTwoStep(t *testing.T) { func TestAccRDSInstance_s3Import_basic(t *testing.T) { var snap rds.DBInstance - bucket := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) - uniqueId := sdkacctest.RandomWithPrefix("tf-acc-s3-import-test") + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) bucketPrefix := sdkacctest.RandString(5) const resourceName = "aws_db_instance.test" @@ -1584,10 +1586,10 @@ func TestAccRDSInstance_s3Import_basic(t *testing.T) { CheckDestroy: testAccCheckInstanceDestroy, Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_S3Import_basic(bucket, bucketPrefix, uniqueId), + Config: testAccInstanceConfig_S3Import_basic(rName, bucketPrefix), Check: resource.ComposeTestCheckFunc( testAccCheckInstanceExists(resourceName, &snap), - resource.TestCheckResourceAttr(resourceName, "identifier", uniqueId), + resource.TestCheckResourceAttr(resourceName, "identifier", rName), resource.TestCheckResourceAttr(resourceName, "identifier_prefix", ""), ), }, @@ -1605,8 +1607,7 @@ func TestAccRDSInstance_s3Import_basic(t *testing.T) { func TestAccRDSInstance_s3Import_NameDeprecated_basic(t *testing.T) { var snap rds.DBInstance - bucket := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) - uniqueId := sdkacctest.RandomWithPrefix("tf-acc-s3-import-test") + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) bucketPrefix := sdkacctest.RandString(5) const resourceName = "aws_db_instance.test" @@ -1618,10 +1619,10 @@ func TestAccRDSInstance_s3Import_NameDeprecated_basic(t *testing.T) { CheckDestroy: testAccCheckInstanceDestroy, Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_S3Import_NameDeprecated_basic(bucket, bucketPrefix, uniqueId), + Config: testAccInstanceConfig_S3Import_NameDeprecated_basic(rName, bucketPrefix), Check: resource.ComposeTestCheckFunc( testAccCheckInstanceExists(resourceName, &snap), - resource.TestCheckResourceAttr(resourceName, "identifier", uniqueId), + resource.TestCheckResourceAttr(resourceName, "identifier", rName), resource.TestCheckResourceAttr(resourceName, "identifier_prefix", ""), ), }, @@ -1640,7 +1641,7 @@ func TestAccRDSInstance_s3Import_NameDeprecated_basic(t *testing.T) { func TestAccRDSInstance_s3Import_namePrefix(t *testing.T) { var snap rds.DBInstance const identifierPrefix = "tf-acc-test-prefix-" - bucket := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) bucketPrefix := sdkacctest.RandString(5) const resourceName = "aws_db_instance.test" @@ -1652,7 +1653,7 @@ func TestAccRDSInstance_s3Import_namePrefix(t *testing.T) { CheckDestroy: testAccCheckInstanceDestroy, Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_S3Import_namePrefix(bucket, bucketPrefix, identifierPrefix), + Config: testAccInstanceConfig_S3Import_namePrefix(rName, bucketPrefix, identifierPrefix), Check: resource.ComposeTestCheckFunc( testAccCheckInstanceExists(resourceName, &snap), create.TestCheckResourceAttrNameFromPrefix(resourceName, "identifier", identifierPrefix), @@ -1673,7 +1674,7 @@ func TestAccRDSInstance_s3Import_namePrefix(t *testing.T) { func TestAccRDSInstance_s3Import_nameGenerated(t *testing.T) { var snap rds.DBInstance - bucket := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) bucketPrefix := sdkacctest.RandString(5) const resourceName = "aws_db_instance.test" @@ -1685,7 +1686,7 @@ func TestAccRDSInstance_s3Import_nameGenerated(t *testing.T) { CheckDestroy: testAccCheckInstanceDestroy, Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_S3Import_nameGenerated(bucket, bucketPrefix), + Config: testAccInstanceConfig_S3Import_nameGenerated(rName, bucketPrefix), Check: resource.ComposeTestCheckFunc( testAccCheckInstanceExists(resourceName, &snap), create.TestCheckResourceAttrNameGenerated(resourceName, "identifier"), @@ -2729,7 +2730,7 @@ func TestAccRDSInstance_MonitoringRoleARN_removedToEnabled(t *testing.T) { func TestAccRDSInstance_separateIopsUpdate(t *testing.T) { var v rds.DBInstance - rName := sdkacctest.RandString(5) + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -2759,7 +2760,7 @@ func TestAccRDSInstance_separateIopsUpdate(t *testing.T) { func TestAccRDSInstance_portUpdate(t *testing.T) { var v rds.DBInstance - rName := sdkacctest.RandString(5) + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -2768,7 +2769,7 @@ func TestAccRDSInstance_portUpdate(t *testing.T) { CheckDestroy: testAccCheckInstanceDestroy, Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_SnapshotInstanceConfig_mysqlPort(rName), + Config: testAccInstanceConfig_SnapshotInstanceConfig_mySQLPort(rName), Check: resource.ComposeTestCheckFunc( testAccCheckInstanceExists("aws_db_instance.bar", &v), resource.TestCheckResourceAttr( @@ -2790,7 +2791,8 @@ func TestAccRDSInstance_portUpdate(t *testing.T) { func TestAccRDSInstance_MSSQL_tz(t *testing.T) { var v rds.DBInstance - rInt := sdkacctest.RandInt() + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_db_instance.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -2799,26 +2801,22 @@ func TestAccRDSInstance_MSSQL_tz(t *testing.T) { CheckDestroy: testAccCheckInstanceDestroy, Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_MSSQL_timezone(rInt), + Config: testAccInstanceConfig_MSSQL_timezone(rName), Check: resource.ComposeTestCheckFunc( - testAccCheckInstanceExists("aws_db_instance.mssql", &v), + testAccCheckInstanceExists(resourceName, &v), testAccCheckInstanceAttributes_MSSQL(&v, ""), - resource.TestCheckResourceAttr( - "aws_db_instance.mssql", "allocated_storage", "20"), - resource.TestCheckResourceAttr( - "aws_db_instance.mssql", "engine", "sqlserver-ex"), + resource.TestCheckResourceAttr(resourceName, "allocated_storage", "20"), + resource.TestCheckResourceAttr(resourceName, "engine", "sqlserver-ex"), ), }, { - Config: testAccInstanceConfig_MSSQL_timezone_AKST(rInt), + Config: testAccInstanceConfig_MSSQL_timezone_AKST(rName), Check: resource.ComposeTestCheckFunc( - testAccCheckInstanceExists("aws_db_instance.mssql", &v), + testAccCheckInstanceExists(resourceName, &v), testAccCheckInstanceAttributes_MSSQL(&v, "Alaskan Standard Time"), - resource.TestCheckResourceAttr( - "aws_db_instance.mssql", "allocated_storage", "20"), - resource.TestCheckResourceAttr( - "aws_db_instance.mssql", "engine", "sqlserver-ex"), + resource.TestCheckResourceAttr(resourceName, "allocated_storage", "20"), + resource.TestCheckResourceAttr(resourceName, "engine", "sqlserver-ex"), ), }, }, @@ -2892,7 +2890,7 @@ func TestAccRDSInstance_MSSQL_domainSnapshotRestore(t *testing.T) { func TestAccRDSInstance_MySQL_snapshotRestoreWithEngineVersion(t *testing.T) { var v, vRestoredInstance rds.DBInstance - rInt := sdkacctest.RandInt() + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -2901,7 +2899,7 @@ func TestAccRDSInstance_MySQL_snapshotRestoreWithEngineVersion(t *testing.T) { CheckDestroy: testAccCheckInstanceDestroy, Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_MySQLSnapshotRestoreWithEngineVersion(rInt), + Config: testAccInstanceConfig_MySQLSnapshotRestoreWithEngineVersion(rName), Check: resource.ComposeTestCheckFunc( testAccCheckInstanceExists("aws_db_instance.mysql_restore", &vRestoredInstance), testAccCheckInstanceExists("aws_db_instance.mysql", &v), @@ -2915,6 +2913,7 @@ func TestAccRDSInstance_MySQL_snapshotRestoreWithEngineVersion(t *testing.T) { func TestAccRDSInstance_minorVersion(t *testing.T) { var v rds.DBInstance + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -2923,7 +2922,7 @@ func TestAccRDSInstance_minorVersion(t *testing.T) { CheckDestroy: testAccCheckInstanceDestroy, Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_AutoMinorVersion(), + Config: testAccInstanceConfig_AutoMinorVersion(rName), Check: resource.ComposeTestCheckFunc( testAccCheckInstanceExists("aws_db_instance.bar", &v), ), @@ -2934,7 +2933,7 @@ func TestAccRDSInstance_minorVersion(t *testing.T) { func TestAccRDSInstance_ec2Classic(t *testing.T) { var v rds.DBInstance - rInt := sdkacctest.RandInt() + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_db_instance.bar" resource.ParallelTest(t, resource.TestCase{ @@ -2944,7 +2943,7 @@ func TestAccRDSInstance_ec2Classic(t *testing.T) { CheckDestroy: testAccCheckInstanceEC2ClassicDestroy, Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_EC2Classic(rInt), + Config: testAccInstanceConfig_EC2Classic(rName), Check: resource.ComposeTestCheckFunc( testAccCheckInstanceEC2ClassicExists(resourceName, &v), ), @@ -2956,7 +2955,7 @@ func TestAccRDSInstance_ec2Classic(t *testing.T) { func TestAccRDSInstance_cloudWatchLogsExport(t *testing.T) { var v rds.DBInstance - rInt := sdkacctest.RandInt() + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -2965,7 +2964,7 @@ func TestAccRDSInstance_cloudWatchLogsExport(t *testing.T) { CheckDestroy: testAccCheckInstanceDestroy, Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_CloudWatchLogsExportConfiguration(rInt), + Config: testAccInstanceConfig_CloudWatchLogsExportConfiguration(rName), Check: resource.ComposeTestCheckFunc( testAccCheckInstanceExists("aws_db_instance.bar", &v), ), @@ -2989,7 +2988,7 @@ func TestAccRDSInstance_cloudWatchLogsExport(t *testing.T) { func TestAccRDSInstance_EnabledCloudWatchLogsExports_mySQL(t *testing.T) { var v rds.DBInstance resourceName := "aws_db_instance.bar" - rInt := sdkacctest.RandInt() + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -2998,7 +2997,7 @@ func TestAccRDSInstance_EnabledCloudWatchLogsExports_mySQL(t *testing.T) { CheckDestroy: testAccCheckInstanceDestroy, Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_CloudWatchLogsExportConfiguration(rInt), + Config: testAccInstanceConfig_CloudWatchLogsExportConfiguration(rName), Check: resource.ComposeTestCheckFunc( testAccCheckInstanceExists(resourceName, &v), resource.TestCheckResourceAttr(resourceName, "enabled_cloudwatch_logs_exports.#", "2"), @@ -3007,7 +3006,7 @@ func TestAccRDSInstance_EnabledCloudWatchLogsExports_mySQL(t *testing.T) { ), }, { - Config: testAccInstanceConfig_CloudWatchLogsExportConfigurationAdd(rInt), + Config: testAccInstanceConfig_CloudWatchLogsExportConfigurationAdd(rName), Check: resource.ComposeTestCheckFunc( testAccCheckInstanceExists(resourceName, &v), resource.TestCheckResourceAttr(resourceName, "enabled_cloudwatch_logs_exports.#", "3"), @@ -3017,7 +3016,7 @@ func TestAccRDSInstance_EnabledCloudWatchLogsExports_mySQL(t *testing.T) { ), }, { - Config: testAccInstanceConfig_CloudWatchLogsExportConfigurationModify(rInt), + Config: testAccInstanceConfig_CloudWatchLogsExportConfigurationModify(rName), Check: resource.ComposeTestCheckFunc( testAccCheckInstanceExists(resourceName, &v), resource.TestCheckResourceAttr(resourceName, "enabled_cloudwatch_logs_exports.#", "3"), @@ -3027,7 +3026,7 @@ func TestAccRDSInstance_EnabledCloudWatchLogsExports_mySQL(t *testing.T) { ), }, { - Config: testAccInstanceConfig_CloudWatchLogsExportConfigurationDelete(rInt), + Config: testAccInstanceConfig_CloudWatchLogsExportConfigurationDelete(rName), Check: resource.ComposeTestCheckFunc( testAccCheckInstanceExists(resourceName, &v), resource.TestCheckResourceAttr(resourceName, "enabled_cloudwatch_logs_exports.#", "0"), @@ -3144,7 +3143,7 @@ func TestAccRDSInstance_EnabledCloudWatchLogsExports_postgresql(t *testing.T) { func TestAccRDSInstance_noDeleteAutomatedBackups(t *testing.T) { var dbInstance rds.DBInstance - rName := sdkacctest.RandomWithPrefix("tf-testacc-nodelautobak") + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_db_instance.test" resource.ParallelTest(t, resource.TestCase{ @@ -3749,6 +3748,7 @@ func TestAccRDSInstance_RestoreToPointInTime_sourceIdentifier(t *testing.T) { var dbInstance, sourceDbInstance rds.DBInstance sourceName := "aws_db_instance.test" resourceName := "aws_db_instance.restore" + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -3757,7 +3757,7 @@ func TestAccRDSInstance_RestoreToPointInTime_sourceIdentifier(t *testing.T) { CheckDestroy: testAccCheckInstanceDestroy, Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_RestoreToPointInTime_SourceIdentifier(), + Config: testAccInstanceConfig_RestoreToPointInTime_SourceIdentifier(rName), Check: resource.ComposeTestCheckFunc( testAccCheckInstanceExists(sourceName, &sourceDbInstance), testAccCheckInstanceExists(resourceName, &dbInstance), @@ -3785,6 +3785,7 @@ func TestAccRDSInstance_RestoreToPointInTime_sourceResourceID(t *testing.T) { var dbInstance, sourceDbInstance rds.DBInstance sourceName := "aws_db_instance.test" resourceName := "aws_db_instance.restore" + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -3793,7 +3794,7 @@ func TestAccRDSInstance_RestoreToPointInTime_sourceResourceID(t *testing.T) { CheckDestroy: testAccCheckInstanceDestroy, Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_RestoreToPointInTime_SourceResourceID(), + Config: testAccInstanceConfig_RestoreToPointInTime_SourceResourceID(rName), Check: resource.ComposeTestCheckFunc( testAccCheckInstanceExists(sourceName, &sourceDbInstance), testAccCheckInstanceExists(resourceName, &dbInstance), @@ -4096,54 +4097,38 @@ func TestAccRDSInstance_license(t *testing.T) { }) } -func testAccInstanceConfig_orderableClass(engine, version, license string) string { +func testAccInstanceConfig_orderableClass(engine, license, storage, classes string) string { return fmt.Sprintf(` -data "aws_rds_orderable_db_instance" "test" { - engine = %[1]q - engine_version = %[2]q - license_model = %[3]q - storage_type = "standard" - - preferred_instance_classes = ["db.t3.micro", "db.t2.micro", "db.t2.medium"] -} -`, engine, version, license) +data "aws_rds_engine_version" "default" { + engine = %[1]q } -func testAccInstanceConfig_orderableClass_SQLServerEx(engine, version, license string) string { - return fmt.Sprintf(` data "aws_rds_orderable_db_instance" "test" { - engine = %[1]q - engine_version = %[2]q - license_model = %[3]q - storage_type = "standard" + engine = data.aws_rds_engine_version.default.engine + engine_version = data.aws_rds_engine_version.default.version + license_model = %[2]q + storage_type = %[3]q - preferred_instance_classes = ["db.t2.small", "db.t3.small"] + preferred_instance_classes = [%[4]s] } -`, engine, version, license) +`, engine, license, storage, classes) } func testAccInstanceConfig_orderableClassMySQL() string { - return testAccInstanceConfig_orderableClass("mysql", "8.0.23", "general-public-license") + return testAccInstanceConfig_orderableClass("mysql", "general-public-license", "standard", mySQLPreferredInstanceClasses) } func testAccInstanceConfig_orderableClassMariadb() string { - return testAccInstanceConfig_orderableClass("mariadb", "10.5.12", "general-public-license") + return testAccInstanceConfig_orderableClass("mariadb", "general-public-license", "standard", mariaDBPreferredInstanceClasses) } func testAccInstanceConfig_orderableClassSQLServerEx() string { - return testAccInstanceConfig_orderableClass_SQLServerEx("sqlserver-ex", "15.00.4073.23.v1", "license-included") + return testAccInstanceConfig_orderableClass("sqlserver-ex", "license-included", "standard", sqlServerPreferredInstanceClasses) } -const testAccInstanceConfig_orderableClassSQLServerSe = ` -data "aws_rds_orderable_db_instance" "test" { - engine = "sqlserver-se" - engine_version = "15.00.4073.23.v1" - license_model = "license-included" - storage_type = "standard" - - preferred_instance_classes = ["db.m5.large", "db.m4.large", "db.r4.large"] +func testAccInstanceConfig_orderableClassSQLServerSe() string { + return testAccInstanceConfig_orderableClass("sqlserver-se", "license-included", "standard", sqlServerSEPreferredInstanceClasses) } -` func testAccInstanceBasicConfig(rName string) string { return acctest.ConfigCompose( @@ -4156,8 +4141,8 @@ resource "aws_db_instance" "test" { engine = data.aws_rds_orderable_db_instance.test.engine engine_version = data.aws_rds_orderable_db_instance.test.engine_version instance_class = data.aws_rds_orderable_db_instance.test.instance_class - name = "baz" - parameter_group_name = "default.mysql8.0" + db_name = "baz" + parameter_group_name = "default.${data.aws_rds_engine_version.default.parameter_group_family}" password = "barbarbarbar" skip_final_snapshot = true username = "test" @@ -4182,7 +4167,7 @@ resource "aws_db_instance" "test" { engine_version = data.aws_rds_orderable_db_instance.test.engine_version instance_class = data.aws_rds_orderable_db_instance.test.instance_class name = "baz" # deprecated - parameter_group_name = "default.mysql8.0" + parameter_group_name = "default.${data.aws_rds_engine_version.default.parameter_group_family}" password = "barbarbarbar" skip_final_snapshot = true username = "test" @@ -4195,18 +4180,18 @@ resource "aws_db_instance" "test" { `, rName)) } -func testAccInstanceConfig_MajorVersionOnly(engine, engineVersion string) string { +func testAccInstanceConfig_MajorVersionOnly() string { return acctest.ConfigCompose( testAccInstanceConfig_orderableClassMySQL(), fmt.Sprintf(` resource "aws_db_instance" "test" { allocated_storage = 10 backup_retention_period = 0 - engine = data.aws_rds_orderable_db_instance.test.engine - engine_version = %[1]q + engine = data.aws_rds_engine_version.default.engine + engine_version = regex("^\\d+\\.\\d+", data.aws_rds_engine_version.default.version) instance_class = data.aws_rds_orderable_db_instance.test.instance_class - name = "baz" - parameter_group_name = "default.%[2]s%[1]s" + db_name = "baz" + parameter_group_name = "default.${data.aws_rds_engine_version.default.parameter_group_family}" password = "barbarbarbar" skip_final_snapshot = true username = "foo" @@ -4216,7 +4201,7 @@ resource "aws_db_instance" "test" { # validation error). maintenance_window = "Fri:09:00-Fri:09:30" } -`, engineVersion, engine)) +`)) } func testAccInstanceConfig_namePrefix(identifierPrefix string) string { @@ -4251,10 +4236,10 @@ resource "aws_db_instance" "test" { `) } -func testAccInstanceConfig_KMSKeyID(rInt int) string { +func testAccInstanceConfig_KMSKeyID(rName string) string { return fmt.Sprintf(` resource "aws_kms_key" "foo" { - description = "Terraform acc test %d" + description = %[1]q policy = < Date: Mon, 7 Mar 2022 20:16:48 -0500 Subject: [PATCH 05/32] rds/option_group_test: Make version dynamic --- internal/service/rds/option_group_test.go | 163 +++++++++++++++------- 1 file changed, 116 insertions(+), 47 deletions(-) diff --git a/internal/service/rds/option_group_test.go b/internal/service/rds/option_group_test.go index 1789e519b32..658c29d44b3 100644 --- a/internal/service/rds/option_group_test.go +++ b/internal/service/rds/option_group_test.go @@ -606,11 +606,15 @@ func testAccCheckOptionGroupDestroy(s *terraform.State) error { func testAccOptionGroupBasicTimeoutBlockConfig(rName string) string { return fmt.Sprintf(` +data "aws_rds_engine_version" "default" { + engine = "mysql" +} + resource "aws_db_option_group" "test" { name = %[1]q option_group_description = "Test option group for terraform" - engine_name = "mysql" - major_engine_version = "8.0" + engine_name = data.aws_rds_engine_version.default.engine + major_engine_version = regex("^\\d+\\.\\d+", data.aws_rds_engine_version.default.version) timeouts { delete = "10m" @@ -621,16 +625,30 @@ resource "aws_db_option_group" "test" { func testAccOptionGroupBasicConfig(rName string) string { return fmt.Sprintf(` +data "aws_rds_engine_version" "default" { + engine = "mysql" +} + resource "aws_db_option_group" "test" { name = %[1]q - engine_name = "mysql" - major_engine_version = "8.0" + engine_name = data.aws_rds_engine_version.default.engine + major_engine_version = regex("^\\d+\\.\\d+", data.aws_rds_engine_version.default.version) } `, rName) } func testAccOptionGroupBasicDestroyConfig(rName string) string { return fmt.Sprintf(` +data "aws_rds_engine_version" "default" { + engine = "mysql" +} + +data "aws_rds_orderable_db_instance" "test" { + engine = data.aws_rds_engine_version.default.engine + engine_version = data.aws_rds_engine_version.default.version + preferred_instance_classes = [%[1]s] +} + resource "aws_db_instance" "test" { allocated_storage = 10 engine = data.aws_rds_orderable_db_instance.test.engine @@ -651,31 +669,26 @@ resource "aws_db_instance" "test" { option_group_name = aws_db_option_group.test.name } -data "aws_rds_orderable_db_instance" "test" { - engine = "mysql" - license_model = "general-public-license" - storage_type = "standard" - - preferred_engine_versions = ["8.0.25", "8.0.26", "8.0.27"] - preferred_instance_classes = ["db.t2.micro", "db.t2.small", "db.t3.medium", "db.t3.large"] -} - resource "aws_db_option_group" "test" { - name = %[1]q + name = %[2]q option_group_description = "Test option group for terraform" - engine_name = "mysql" - major_engine_version = "8.0" + engine_name = data.aws_rds_engine_version.default.engine + major_engine_version = regex("^\\d+\\.\\d+", data.aws_rds_engine_version.default.version) } -`, rName) +`, mySQLPreferredInstanceClasses, rName) } func testAccOptionGroupOptionSettings(rName string) string { return fmt.Sprintf(` +data "aws_rds_engine_version" "default" { + engine = "oracle-ee" +} + resource "aws_db_option_group" "test" { name = %[1]q option_group_description = "Test option group for terraform" - engine_name = "oracle-ee" - major_engine_version = "12.2" + engine_name = data.aws_rds_engine_version.default.engine + major_engine_version = regex("^\\d+", data.aws_rds_engine_version.default.version) option { option_name = "Timezone" @@ -693,6 +706,10 @@ func testAccOptionGroupOptionSettingsIAMRole(rName string) string { return fmt.Sprintf(` data "aws_partition" "current" {} +data "aws_rds_engine_version" "default" { + engine = "sqlserver-ex" +} + data "aws_iam_policy_document" "rds_assume_role" { statement { actions = ["sts:AssumeRole"] @@ -712,8 +729,8 @@ resource "aws_iam_role" "sql_server_backup" { resource "aws_db_option_group" "test" { name = %[1]q option_group_description = "Test option group for terraform" - engine_name = "sqlserver-ex" - major_engine_version = "14.00" + engine_name = data.aws_rds_engine_version.default.engine + major_engine_version = regex("^\\d+\\.\\d+", data.aws_rds_engine_version.default.version) option { option_name = "SQLSERVER_BACKUP_RESTORE" @@ -729,11 +746,15 @@ resource "aws_db_option_group" "test" { func testAccOptionGroupOptionSettings_update(rName string) string { return fmt.Sprintf(` +data "aws_rds_engine_version" "default" { + engine = "oracle-ee" +} + resource "aws_db_option_group" "test" { name = %[1]q option_group_description = "Test option group for terraform" - engine_name = "oracle-ee" - major_engine_version = "12.2" + engine_name = data.aws_rds_engine_version.default.engine + major_engine_version = regex("^\\d+", data.aws_rds_engine_version.default.version) option { option_name = "Timezone" @@ -749,22 +770,30 @@ resource "aws_db_option_group" "test" { func testAccOptionGroupSQLServerEEOptions(rName string) string { return fmt.Sprintf(` +data "aws_rds_engine_version" "default" { + engine = "sqlserver-ee" +} + resource "aws_db_option_group" "test" { name = %[1]q option_group_description = "Test option group for terraform" - engine_name = "sqlserver-ee" - major_engine_version = "11.00" + engine_name = data.aws_rds_engine_version.default.engine + major_engine_version = regex("^\\d+\\.\\d+", data.aws_rds_engine_version.default.version) } `, rName) } func testAccOptionGroupSQLServerEEOptions_update(rName string) string { return fmt.Sprintf(` +data "aws_rds_engine_version" "default" { + engine = "sqlserver-ee" +} + resource "aws_db_option_group" "test" { name = %[1]q option_group_description = "Test option group for terraform" - engine_name = "sqlserver-ee" - major_engine_version = "11.00" + engine_name = data.aws_rds_engine_version.default.engine + major_engine_version = regex("^\\d+\\.\\d+", data.aws_rds_engine_version.default.version) option { option_name = "TDE" @@ -775,6 +804,10 @@ resource "aws_db_option_group" "test" { func testAccOptionGroupOracleEEOptionSettings(rName, optionVersion string) string { return fmt.Sprintf(` +data "aws_rds_engine_version" "default" { + engine = "oracle-ee" +} + resource "aws_security_group" "foo" { name = %[1]q } @@ -782,8 +815,8 @@ resource "aws_security_group" "foo" { resource "aws_db_option_group" "test" { name = %[1]q option_group_description = "Test option group for terraform issue 748" - engine_name = "oracle-ee" - major_engine_version = "12.2" + engine_name = data.aws_rds_engine_version.default.engine + major_engine_version = regex("^\\d+", data.aws_rds_engine_version.default.version) option { option_name = "OEM_AGENT" @@ -813,11 +846,15 @@ resource "aws_db_option_group" "test" { func testAccOptionGroupMultipleOptions(rName string) string { return fmt.Sprintf(` +data "aws_rds_engine_version" "default" { + engine = "oracle-ee" +} + resource "aws_db_option_group" "test" { name = %[1]q option_group_description = "Test option group for terraform" - engine_name = "oracle-ee" - major_engine_version = "12.2" + engine_name = data.aws_rds_engine_version.default.engine + major_engine_version = regex("^\\d+", data.aws_rds_engine_version.default.version) option { option_name = "SPATIAL" @@ -831,27 +868,39 @@ resource "aws_db_option_group" "test" { } const testAccOptionGroup_namePrefix = ` +data "aws_rds_engine_version" "default" { + engine = "mysql" +} + resource "aws_db_option_group" "test" { name_prefix = "tf-test-" option_group_description = "Test option group for terraform" - engine_name = "mysql" - major_engine_version = "8.0" + engine_name = data.aws_rds_engine_version.default.engine + major_engine_version = regex("^\\d+\\.\\d+", data.aws_rds_engine_version.default.version) } ` const testAccOptionGroup_generatedName = ` +data "aws_rds_engine_version" "default" { + engine = "mysql" +} + resource "aws_db_option_group" "test" { option_group_description = "Test option group for terraform" - engine_name = "mysql" - major_engine_version = "8.0" + engine_name = data.aws_rds_engine_version.default.engine + major_engine_version = regex("^\\d+\\.\\d+", data.aws_rds_engine_version.default.version) } ` func testAccOptionGroupOptionGroupDescriptionConfig(rName, optionGroupDescription string) string { return fmt.Sprintf(` +data "aws_rds_engine_version" "default" { + engine = "mysql" +} + resource "aws_db_option_group" "test" { - engine_name = "mysql" - major_engine_version = "8.0" + engine_name = data.aws_rds_engine_version.default.engine + major_engine_version = regex("^\\d+\\.\\d+", data.aws_rds_engine_version.default.version) name = %[1]q option_group_description = %[2]q } @@ -860,9 +909,13 @@ resource "aws_db_option_group" "test" { func testAccOptionGroupOptionOptionSettingsMultipleConfig(rName, value string) string { return fmt.Sprintf(` +data "aws_rds_engine_version" "default" { + engine = "mysql" +} + resource "aws_db_option_group" "test" { - engine_name = "mysql" - major_engine_version = "8.0" + engine_name = data.aws_rds_engine_version.default.engine + major_engine_version = regex("^\\d+\\.\\d+", data.aws_rds_engine_version.default.version) name = %[1]q option { @@ -889,9 +942,13 @@ resource "aws_db_option_group" "test" { func testAccOptionGroupTags1Config(rName, tagKey1, tagValue1 string) string { return fmt.Sprintf(` +data "aws_rds_engine_version" "default" { + engine = "mysql" +} + resource "aws_db_option_group" "test" { - engine_name = "mysql" - major_engine_version = "8.0" + engine_name = data.aws_rds_engine_version.default.engine + major_engine_version = regex("^\\d+\\.\\d+", data.aws_rds_engine_version.default.version) name = %[1]q tags = { @@ -903,9 +960,13 @@ resource "aws_db_option_group" "test" { func testAccOptionGroupTags2Config(rName, tagKey1, tagValue1, tagKey2, tagValue2 string) string { return fmt.Sprintf(` +data "aws_rds_engine_version" "default" { + engine = "mysql" +} + resource "aws_db_option_group" "test" { - engine_name = "mysql" - major_engine_version = "8.0" + engine_name = data.aws_rds_engine_version.default.engine + major_engine_version = regex("^\\d+\\.\\d+", data.aws_rds_engine_version.default.version) name = %[1]q tags = { @@ -918,9 +979,13 @@ resource "aws_db_option_group" "test" { func testAccOptionGroupTagsWithOption1Config(rName, tagKey1, tagValue1 string) string { return fmt.Sprintf(` +data "aws_rds_engine_version" "default" { + engine = "mysql" +} + resource "aws_db_option_group" "test" { - engine_name = "mysql" - major_engine_version = "8.0" + engine_name = data.aws_rds_engine_version.default.engine + major_engine_version = regex("^\\d+\\.\\d+", data.aws_rds_engine_version.default.version) name = %[1]q option { @@ -941,9 +1006,13 @@ resource "aws_db_option_group" "test" { func testAccOptionGroupTagsWithOption2Config(rName, tagKey1, tagValue1, tagKey2, tagValue2 string) string { return fmt.Sprintf(` +data "aws_rds_engine_version" "default" { + engine = "mysql" +} + resource "aws_db_option_group" "test" { - engine_name = "mysql" - major_engine_version = "8.0" + engine_name = data.aws_rds_engine_version.default.engine + major_engine_version = regex("^\\d+\\.\\d+", data.aws_rds_engine_version.default.version) name = %[1]q option { From cfe8c7f26436b68b27d6ea995214855d8bf1db05 Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Mon, 7 Mar 2022 20:17:20 -0500 Subject: [PATCH 06/32] rds/ds/orderable: Make version dynamic --- .../orderable_instance_data_source_test.go | 189 +++++++++++------- 1 file changed, 120 insertions(+), 69 deletions(-) diff --git a/internal/service/rds/orderable_instance_data_source_test.go b/internal/service/rds/orderable_instance_data_source_test.go index c767a674a51..586dea7dd56 100644 --- a/internal/service/rds/orderable_instance_data_source_test.go +++ b/internal/service/rds/orderable_instance_data_source_test.go @@ -13,9 +13,7 @@ import ( func TestAccRDSOrderableInstanceDataSource_basic(t *testing.T) { dataSourceName := "data.aws_rds_orderable_db_instance.test" - class := "db.t2.small" engine := "mysql" - engineVersion := "5.7.22" licenseModel := "general-public-license" storageType := "standard" @@ -26,13 +24,13 @@ func TestAccRDSOrderableInstanceDataSource_basic(t *testing.T) { CheckDestroy: nil, Steps: []resource.TestStep{ { - Config: testAccOrderableInstanceDataSourceConfig_basic(class, engine, engineVersion, licenseModel, storageType), + Config: testAccOrderableInstanceDataSourceConfig_basic(engine, licenseModel, storageType), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "instance_class", class), resource.TestCheckResourceAttr(dataSourceName, "engine", engine), - resource.TestCheckResourceAttr(dataSourceName, "engine_version", engineVersion), resource.TestCheckResourceAttr(dataSourceName, "license_model", licenseModel), resource.TestCheckResourceAttr(dataSourceName, "storage_type", storageType), + resource.TestCheckResourceAttrPair(dataSourceName, "engine_version", "data.aws_rds_engine_version.default", "version"), + resource.TestCheckResourceAttrPair(dataSourceName, "instance_class", "data.aws_rds_orderable_db_instance.dynamic", "instance_class"), ), }, }, @@ -41,7 +39,7 @@ func TestAccRDSOrderableInstanceDataSource_basic(t *testing.T) { func TestAccRDSOrderableInstanceDataSource_preferredClass(t *testing.T) { dataSourceName := "data.aws_rds_orderable_db_instance.test" - preferredClass := "db.t2.micro" + preferredClass := "db.t3.micro" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t); testAccOrderableInstancePreCheck(t) }, @@ -61,7 +59,6 @@ func TestAccRDSOrderableInstanceDataSource_preferredClass(t *testing.T) { func TestAccRDSOrderableInstanceDataSource_preferredVersion(t *testing.T) { dataSourceName := "data.aws_rds_orderable_db_instance.test" - preferredVersion := "5.7.22" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t); testAccOrderableInstancePreCheck(t) }, @@ -70,9 +67,9 @@ func TestAccRDSOrderableInstanceDataSource_preferredVersion(t *testing.T) { CheckDestroy: nil, Steps: []resource.TestStep{ { - Config: testAccOrderableInstanceDataSourceConfig_preferredVersion(preferredVersion), + Config: testAccOrderableInstanceDataSourceConfig_preferredVersion(), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "engine_version", preferredVersion), + resource.TestCheckResourceAttrPair(dataSourceName, "engine_version", "data.aws_rds_engine_version.default", "version"), ), }, }, @@ -81,8 +78,6 @@ func TestAccRDSOrderableInstanceDataSource_preferredVersion(t *testing.T) { func TestAccRDSOrderableInstanceDataSource_preferredClassAndVersion(t *testing.T) { dataSourceName := "data.aws_rds_orderable_db_instance.test" - preferredClass := "db.m3.medium" - preferredVersion := "5.7.22" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t); testAccOrderableInstancePreCheck(t) }, @@ -91,10 +86,10 @@ func TestAccRDSOrderableInstanceDataSource_preferredClassAndVersion(t *testing.T CheckDestroy: nil, Steps: []resource.TestStep{ { - Config: testAccOrderableInstanceDataSourceConfig_preferredClassAndVersion(preferredClass, preferredVersion), + Config: testAccOrderableInstanceDataSourceConfig_preferredClassAndVersion(), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "instance_class", preferredClass), - resource.TestCheckResourceAttr(dataSourceName, "engine_version", preferredVersion), + resource.TestCheckResourceAttrPair(dataSourceName, "instance_class", "data.aws_rds_orderable_db_instance.dynamic", "instance_class"), + resource.TestCheckResourceAttrPair(dataSourceName, "engine_version", "data.aws_rds_engine_version.default", "version"), ), }, }, @@ -258,161 +253,217 @@ func testAccOrderableInstancePreCheck(t *testing.T) { } } -func testAccOrderableInstanceDataSourceConfig_basic(class, engine, version, license, storage string) string { +func testAccOrderableInstanceDataSourceConfig_basic(engine, license, storage string) string { return fmt.Sprintf(` +data "aws_rds_engine_version" "default" { + engine = %[1]q +} + +data "aws_rds_orderable_db_instance" "dynamic" { + engine = data.aws_rds_engine_version.default.engine + engine_version = data.aws_rds_engine_version.default.version + preferred_instance_classes = [%[2]s] +} + data "aws_rds_orderable_db_instance" "test" { - instance_class = %q - engine = %q - engine_version = %q - license_model = %q - storage_type = %q + instance_class = data.aws_rds_orderable_db_instance.dynamic.instance_class + engine = data.aws_rds_engine_version.default.engine + engine_version = data.aws_rds_engine_version.default.version + license_model = %[3]q + storage_type = %[4]q } -`, class, engine, version, license, storage) +`, engine, mySQLPreferredInstanceClasses, license, storage) } func testAccOrderableInstanceDataSourceConfig_preferredClass(preferredClass string) string { return fmt.Sprintf(` +data "aws_rds_engine_version" "default" { + engine = "mysql" +} + data "aws_rds_orderable_db_instance" "test" { - engine = "mysql" - engine_version = "5.7.22" + engine = data.aws_rds_engine_version.default.engine + engine_version = data.aws_rds_engine_version.default.version license_model = "general-public-license" preferred_instance_classes = [ "db.xyz.xlarge", - %q, + %[1]q, "db.t3.small", ] } `, preferredClass) } -func testAccOrderableInstanceDataSourceConfig_preferredVersion(preferredVersion string) string { - return fmt.Sprintf(` +func testAccOrderableInstanceDataSourceConfig_preferredVersion() string { + return ` +data "aws_rds_engine_version" "default" { + engine = "mysql" +} + data "aws_rds_orderable_db_instance" "test" { - engine = "mysql" + engine = data.aws_rds_engine_version.default.engine license_model = "general-public-license" storage_type = "standard" preferred_engine_versions = [ "18.42.32", - %q, + data.aws_rds_engine_version.default.version, "not.a.version", ] } -`, preferredVersion) +` } -func testAccOrderableInstanceDataSourceConfig_preferredClassAndVersion(preferredClass, preferredVersion string) string { +func testAccOrderableInstanceDataSourceConfig_preferredClassAndVersion() string { return fmt.Sprintf(` +data "aws_rds_engine_version" "default" { + engine = "mysql" +} + +data "aws_rds_orderable_db_instance" "dynamic" { + engine = data.aws_rds_engine_version.default.engine + engine_version = data.aws_rds_engine_version.default.version + preferred_instance_classes = [%[1]s] +} + data "aws_rds_orderable_db_instance" "test" { - engine = "mysql" + engine = data.aws_rds_engine_version.default.engine license_model = "general-public-license" preferred_instance_classes = [ "db.xyz.xlarge", - %q, + data.aws_rds_orderable_db_instance.dynamic.instance_class, "db.t3.small", ] preferred_engine_versions = [ "18.42.32", - %q, + data.aws_rds_engine_version.default.version, "not.a.version", ] } -`, preferredClass, preferredVersion) +`, mySQLPreferredInstanceClasses) } func testAccOrderableInstanceDataSourceConfig_supportsEnhancedMonitoring() string { - return ` + return fmt.Sprintf(` +data "aws_rds_engine_version" "default" { + engine = "mysql" +} + data "aws_rds_orderable_db_instance" "test" { - engine = "mysql" + engine = data.aws_rds_engine_version.default.engine license_model = "general-public-license" storage_type = "standard" supports_enhanced_monitoring = true - preferred_engine_versions = ["8.0.25", "8.0.26", "8.0.27"] - preferred_instance_classes = ["db.t2.small", "db.t3.medium", "db.t3.large"] + preferred_engine_versions = ["8.0.25", "8.0.26", data.aws_rds_engine_version.default.version] + preferred_instance_classes = [%[1]s] } -` +`, mySQLPreferredInstanceClasses) } func testAccOrderableInstanceDataSourceConfig_supportsIAMDatabaseAuthentication() string { - return ` + return fmt.Sprintf(` +data "aws_rds_engine_version" "default" { + engine = "mysql" +} + data "aws_rds_orderable_db_instance" "test" { - engine = "mysql" + engine = data.aws_rds_engine_version.default.engine license_model = "general-public-license" storage_type = "standard" supports_iam_database_authentication = true - preferred_engine_versions = ["8.0.25", "8.0.26", "8.0.27"] - preferred_instance_classes = ["db.t2.small", "db.t3.medium", "db.t3.large"] + preferred_engine_versions = ["8.0.25", "8.0.26", data.aws_rds_engine_version.default.version] + preferred_instance_classes = [%[1]s] } -` +`, mySQLPreferredInstanceClasses) } func testAccOrderableInstanceDataSourceConfig_supportsIops() string { - return ` + return fmt.Sprintf(` +data "aws_rds_engine_version" "default" { + engine = "mysql" +} + data "aws_rds_orderable_db_instance" "test" { - engine = "mysql" + engine = data.aws_rds_engine_version.default.engine license_model = "general-public-license" supports_iops = true - preferred_engine_versions = ["8.0.20", "8.0.19", "8.0.17"] - preferred_instance_classes = ["db.t3.small", "db.t2.xlarge", "db.t2.small"] + preferred_engine_versions = ["8.0.20", "8.0.19", data.aws_rds_engine_version.default.version] + preferred_instance_classes = [%[1]s] } -` +`, mySQLPreferredInstanceClasses) } func testAccOrderableInstanceDataSourceConfig_supportsKerberosAuthentication() string { - return ` + return fmt.Sprintf(` +data "aws_rds_engine_version" "default" { + engine = "postgres" +} + data "aws_rds_orderable_db_instance" "test" { - engine = "postgres" + engine = data.aws_rds_engine_version.default.engine license_model = "postgresql-license" storage_type = "standard" supports_kerberos_authentication = true - preferred_engine_versions = ["12.3", "11.1", "10.13"] - preferred_instance_classes = ["db.m5.xlarge", "db.r5.large", "db.t3.large"] + preferred_engine_versions = ["14.1", "13.5", data.aws_rds_engine_version.default.version] + preferred_instance_classes = [%[1]s] } -` +`, postgresPreferredInstanceClasses) } func testAccOrderableInstanceDataSourceConfig_supportsPerformanceInsights() string { - return ` + return fmt.Sprintf(` +data "aws_rds_engine_version" "default" { + engine = "mysql" +} + data "aws_rds_orderable_db_instance" "test" { - engine = "mysql" + engine = data.aws_rds_engine_version.default.engine license_model = "general-public-license" supports_performance_insights = true - preferred_engine_versions = ["8.0.25", "8.0.26", "8.0.27"] - preferred_instance_classes = ["db.t2.small", "db.t3.medium", "db.t3.large"] + preferred_engine_versions = ["8.0.25", "8.0.26", data.aws_rds_engine_version.default.version] + preferred_instance_classes = [%[1]s] } -` +`, mySQLPreferredInstanceClasses) } func testAccOrderableInstanceDataSourceConfig_supportsStorageAutoScaling() string { - return ` + return fmt.Sprintf(` +data "aws_rds_engine_version" "default" { + engine = "mysql" +} + data "aws_rds_orderable_db_instance" "test" { - engine = "mysql" + engine = data.aws_rds_engine_version.default.engine license_model = "general-public-license" supports_storage_autoscaling = true - preferred_engine_versions = ["8.0.20", "8.0.19", "5.7.30"] - preferred_instance_classes = ["db.t3.medium", "db.t2.large", "db.t3.xlarge"] + preferred_engine_versions = ["8.0.20", "8.0.19", data.aws_rds_engine_version.default.version] + preferred_instance_classes = [%[1]s] } -` +`, mySQLPreferredInstanceClasses) } func testAccOrderableInstanceDataSourceConfig_supportsStorageEncryption() string { - return ` + return fmt.Sprintf(` +data "aws_rds_engine_version" "default" { + engine = "mysql" +} + data "aws_rds_orderable_db_instance" "test" { - engine = "mysql" + engine = data.aws_rds_engine_version.default.engine license_model = "general-public-license" storage_type = "standard" supports_storage_encryption = true - preferred_engine_versions = ["8.0.25", "8.0.26", "8.0.27"] - preferred_instance_classes = ["db.t2.small", "db.t3.medium", "db.t3.large"] + preferred_engine_versions = ["8.0.25", "8.0.26", data.aws_rds_engine_version.default.version] + preferred_instance_classes = [%[1]s] } -` +`, mySQLPreferredInstanceClasses) } From f164bfcf857d8de7da9853a96de67bbb2f2cce32 Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Mon, 7 Mar 2022 20:18:04 -0500 Subject: [PATCH 07/32] rds/snapshot: Make version dynamic --- .../service/rds/snapshot_data_source_test.go | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/internal/service/rds/snapshot_data_source_test.go b/internal/service/rds/snapshot_data_source_test.go index 98d27324e19..b7f386d9f4d 100644 --- a/internal/service/rds/snapshot_data_source_test.go +++ b/internal/service/rds/snapshot_data_source_test.go @@ -44,11 +44,21 @@ func testAccCheckSnapshotIDDataSource(n string) resource.TestCheckFunc { func testAccCheckSnapshotDataSourceConfig(rInt int) string { return fmt.Sprintf(` +data "aws_rds_engine_version" "default" { + engine = "mysql" +} + +data "aws_rds_orderable_db_instance" "test" { + engine = data.aws_rds_engine_version.default.engine + engine_version = data.aws_rds_engine_version.default.version + preferred_instance_classes = [%[1]s] +} + resource "aws_db_instance" "bar" { allocated_storage = 10 - engine = "mysql" - engine_version = "5.6.35" - instance_class = "db.t2.micro" + engine = data.aws_rds_engine_version.default.engine + engine_version = data.aws_rds_engine_version.default.version + instance_class = data.aws_rds_orderable_db_instance.test.instance_class name = "baz" password = "barbarbarbar" username = "foo" @@ -61,7 +71,7 @@ resource "aws_db_instance" "bar" { backup_retention_period = 0 - parameter_group_name = "default.mysql5.6" + parameter_group_name = "default.${data.aws_rds_engine_version.default.parameter_group_family}" } data "aws_db_snapshot" "snapshot" { @@ -71,7 +81,7 @@ data "aws_db_snapshot" "snapshot" { resource "aws_db_snapshot" "test" { db_instance_identifier = aws_db_instance.bar.id - db_snapshot_identifier = "testsnapshot%d" + db_snapshot_identifier = "testsnapshot%[2]d" } -`, rInt) +`, mySQLPreferredInstanceClasses, rInt) } From be025e23191ba28f5be13b458e1fe1a21637363c Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Mon, 7 Mar 2022 20:18:35 -0500 Subject: [PATCH 08/32] snapshot/tests: Dynamic version --- internal/service/rds/enum.go | 75 --------------------------- internal/service/rds/snapshot_test.go | 36 +++++++++---- internal/service/rds/verify.go | 24 +++++++++ 3 files changed, 50 insertions(+), 85 deletions(-) delete mode 100644 internal/service/rds/enum.go create mode 100644 internal/service/rds/verify.go diff --git a/internal/service/rds/enum.go b/internal/service/rds/enum.go deleted file mode 100644 index c31b4aa776e..00000000000 --- a/internal/service/rds/enum.go +++ /dev/null @@ -1,75 +0,0 @@ -package rds - -const ( - ClusterRoleStatusActive = "ACTIVE" - ClusterRoleStatusDeleted = "DELETED" - ClusterRoleStatusPending = "PENDING" -) - -const ( - StorageTypeStandard = "standard" - StorageTypeGp2 = "gp2" - StorageTypeIo1 = "io1" -) - -func StorageType_Values() []string { - return []string{ - StorageTypeStandard, - StorageTypeGp2, - StorageTypeIo1, - } -} - -// https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/accessing-monitoring.html#Overview.DBInstance.Status. -const ( - InstanceStatusAvailable = "available" - InstanceStatusBackingUp = "backing-up" - InstanceStatusConfiguringEnhancedMonitoring = "configuring-enhanced-monitoring" - InstanceStatusConfiguringLogExports = "configuring-log-exports" - InstanceStatusCreating = "creating" - InstanceStatusDeleting = "deleting" - InstanceStatusIncompatibleParameters = "incompatible-parameters" - InstanceStatusIncompatibleRestore = "incompatible-restore" - InstanceStatusModifying = "modifying" - InstanceStatusStarting = "starting" - InstanceStatusStopping = "stopping" - InstanceStatusStorageFull = "storage-full" - InstanceStatusStorageOptimization = "storage-optimization" -) - -const ( - EventSubscriptionStatusActive = "active" - EventSubscriptionStatusCreating = "creating" - EventSubscriptionStatusDeleting = "deleting" - EventSubscriptionStatusModifying = "modifying" -) - -const ( - ExportableLogTypeAgent = "agent" - ExportableLogTypeAlert = "alert" - ExportableLogTypeAudit = "audit" - ExportableLogTypeError = "error" - ExportableLogTypeGeneral = "general" - ExportableLogTypeListener = "listener" - ExportableLogTypeOEMAgent = "oemagent" - ExportableLogTypePostgreSQL = "postgresql" - ExportableLogTypeSlowQuery = "slowquery" - ExportableLogTypeTrace = "trace" - ExportableLogTypeUpgrade = "upgrade" -) - -func ExportableLogType_Values() []string { - return []string{ - ExportableLogTypeAgent, - ExportableLogTypeAlert, - ExportableLogTypeAudit, - ExportableLogTypeError, - ExportableLogTypeGeneral, - ExportableLogTypeListener, - ExportableLogTypeOEMAgent, - ExportableLogTypePostgreSQL, - ExportableLogTypeSlowQuery, - ExportableLogTypeTrace, - ExportableLogTypeUpgrade, - } -} diff --git a/internal/service/rds/snapshot_test.go b/internal/service/rds/snapshot_test.go index 57bcd85a457..7e88039110f 100644 --- a/internal/service/rds/snapshot_test.go +++ b/internal/service/rds/snapshot_test.go @@ -187,33 +187,47 @@ func testAccCheckDbSnapshotDisappears(snapshot *rds.DBSnapshot) resource.TestChe func testAccSnapshotBaseConfig(rName string) string { return fmt.Sprintf(` +data "aws_rds_engine_version" "default" { + engine = "mysql" +} + +data "aws_rds_orderable_db_instance" "test" { + engine = data.aws_rds_engine_version.default.engine + engine_version = data.aws_rds_engine_version.default.version + preferred_instance_classes = ["db.t3.small", "db.t2.small", "db.t2.medium"] +} + resource "aws_db_instance" "test" { allocated_storage = 10 - engine = "mysql" - engine_version = "5.6.35" - instance_class = "db.t2.micro" + engine = data.aws_rds_engine_version.default.engine + engine_version = data.aws_rds_engine_version.default.version + instance_class = data.aws_rds_orderable_db_instance.test.instance_class name = "baz" identifier = %[1]q password = "barbarbarbar" username = "foo" maintenance_window = "Fri:09:00-Fri:09:30" backup_retention_period = 0 - parameter_group_name = "default.mysql5.6" + parameter_group_name = "default.${data.aws_rds_engine_version.default.parameter_group_family}" skip_final_snapshot = true }`, rName) } func testAccSnapshotConfig(rName string) string { - return testAccSnapshotBaseConfig(rName) + fmt.Sprintf(` + return acctest.ConfigCompose( + testAccSnapshotBaseConfig(rName), + fmt.Sprintf(` resource "aws_db_snapshot" "test" { db_instance_identifier = aws_db_instance.test.id db_snapshot_identifier = %[1]q } -`, rName) +`, rName)) } func testAccSnapshotTags1Config(rName, tag1Key, tag1Value string) string { - return testAccSnapshotBaseConfig(rName) + fmt.Sprintf(` + return acctest.ConfigCompose( + testAccSnapshotBaseConfig(rName), + fmt.Sprintf(` resource "aws_db_snapshot" "test" { db_instance_identifier = aws_db_instance.test.id db_snapshot_identifier = %[1]q @@ -222,11 +236,13 @@ resource "aws_db_snapshot" "test" { %[2]q = %[3]q } } -`, rName, tag1Key, tag1Value) +`, rName, tag1Key, tag1Value)) } func testAccSnapshotTags2Config(rName, tag1Key, tag1Value, tag2Key, tag2Value string) string { - return testAccSnapshotBaseConfig(rName) + fmt.Sprintf(` + return acctest.ConfigCompose( + testAccSnapshotBaseConfig(rName), + fmt.Sprintf(` resource "aws_db_snapshot" "test" { db_instance_identifier = aws_db_instance.test.id db_snapshot_identifier = %[1]q @@ -236,5 +252,5 @@ resource "aws_db_snapshot" "test" { %[4]q = %[5]q } } -`, rName, tag1Key, tag1Value, tag2Key, tag2Value) +`, rName, tag1Key, tag1Value, tag2Key, tag2Value)) } diff --git a/internal/service/rds/verify.go b/internal/service/rds/verify.go new file mode 100644 index 00000000000..11ec581641e --- /dev/null +++ b/internal/service/rds/verify.go @@ -0,0 +1,24 @@ +package rds + +import ( + "fmt" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +func compareActualEngineVersion(d *schema.ResourceData, oldVersion string, newVersion string) { + newVersionSubstr := newVersion + + if len(newVersion) > len(oldVersion) { + newVersionSubstr = string([]byte(newVersion)[0 : len(oldVersion)+1]) + } + + if oldVersion != newVersion && string(append([]byte(oldVersion), []byte(".")...)) != newVersionSubstr { + d.Set("engine_version", newVersion) + fmt.Printf("[READ/cluster] engine_version: %s\n", newVersion) + } + + d.Set("engine_version_actual", newVersion) + fmt.Printf("[READ/cluster] engine_version_actual: %s\n", newVersion) + +} From ef15f7b92a16a884b150e6b42ec3d9d8a02abf0f Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Tue, 8 Mar 2022 15:36:26 -0500 Subject: [PATCH 09/32] Additional test fixes --- internal/service/rds/instance_test.go | 309 ++++++++++++++------------ internal/service/rds/subnet_group.go | 7 +- internal/service/rds/wait.go | 11 +- 3 files changed, 177 insertions(+), 150 deletions(-) diff --git a/internal/service/rds/instance_test.go b/internal/service/rds/instance_test.go index 7c3ac2a553f..1238ddde5d0 100644 --- a/internal/service/rds/instance_test.go +++ b/internal/service/rds/instance_test.go @@ -5,6 +5,7 @@ import ( "log" "os" "regexp" + "strings" "testing" "github.com/aws/aws-sdk-go/aws" @@ -62,8 +63,8 @@ func TestAccRDSInstance_basic(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "license_model", "general-public-license"), resource.TestCheckResourceAttrSet(resourceName, "maintenance_window"), resource.TestCheckResourceAttr(resourceName, "max_allocated_storage", "0"), - resource.TestCheckResourceAttr(resourceName, "option_group_name", "default:mysql-8-0"), - resource.TestCheckResourceAttr(resourceName, "parameter_group_name", "default.mysql8.0"), + resource.TestMatchResourceAttr(resourceName, "option_group_name", regexp.MustCompile(`^default:mysql-\d`)), + resource.TestMatchResourceAttr(resourceName, "parameter_group_name", regexp.MustCompile(`^default\.mysql\d`)), resource.TestCheckResourceAttr(resourceName, "port", "3306"), resource.TestCheckResourceAttr(resourceName, "publicly_accessible", "false"), resource.TestCheckResourceAttrSet(resourceName, "resource_id"), @@ -295,6 +296,7 @@ func TestAccRDSInstance_kmsKey(t *testing.T) { func TestAccRDSInstance_subnetGroup(t *testing.T) { var v rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_db_instance.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -305,17 +307,15 @@ func TestAccRDSInstance_subnetGroup(t *testing.T) { { Config: testAccInstanceConfig_WithSubnetGroup(rName), Check: resource.ComposeTestCheckFunc( - testAccCheckInstanceExists("aws_db_instance.bar", &v), - resource.TestCheckResourceAttr( - "aws_db_instance.bar", "db_subnet_group_name", "foo-"+rName), + testAccCheckInstanceExists(resourceName, &v), + resource.TestCheckResourceAttr(resourceName, "db_subnet_group_name", rName), ), }, { Config: testAccInstanceConfig_WithSubnetGroupUpdated(rName), Check: resource.ComposeTestCheckFunc( - testAccCheckInstanceExists("aws_db_instance.bar", &v), - resource.TestCheckResourceAttr( - "aws_db_instance.bar", "db_subnet_group_name", "bar-"+rName), + testAccCheckInstanceExists(resourceName, &v), + resource.TestCheckResourceAttr(resourceName, "db_subnet_group_name", fmt.Sprintf("%s-2", rName)), ), }, }, @@ -326,6 +326,7 @@ func TestAccRDSInstance_optionGroup(t *testing.T) { var v rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_db_instance.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -336,10 +337,9 @@ func TestAccRDSInstance_optionGroup(t *testing.T) { { Config: testAccInstanceConfig_WithOptionGroup(rName), Check: resource.ComposeTestCheckFunc( - testAccCheckInstanceExists("aws_db_instance.bar", &v), + testAccCheckInstanceExists(resourceName, &v), testAccCheckInstanceAttributes(&v), - resource.TestCheckResourceAttr( - "aws_db_instance.bar", "option_group_name", rName), + resource.TestCheckResourceAttr(resourceName, "option_group_name", rName), ), }, }, @@ -699,7 +699,7 @@ func TestAccRDSInstance_password(t *testing.T) { }) } -func TestAccRDSInstance_replicateSourceDB_basic(t *testing.T) { +func TestAccRDSInstance_ReplicateSourceDB_basic(t *testing.T) { var dbInstance, sourceDbInstance rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -736,7 +736,7 @@ func TestAccRDSInstance_replicateSourceDB_basic(t *testing.T) { }) } -func TestAccRDSInstance_replicateSourceDB_namePrefix(t *testing.T) { +func TestAccRDSInstance_ReplicateSourceDB_namePrefix(t *testing.T) { var v rds.DBInstance sourceName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -769,7 +769,7 @@ func TestAccRDSInstance_replicateSourceDB_namePrefix(t *testing.T) { }) } -func TestAccRDSInstance_replicateSourceDB_nameGenerated(t *testing.T) { +func TestAccRDSInstance_ReplicateSourceDB_nameGenerated(t *testing.T) { var v rds.DBInstance sourceName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -801,7 +801,7 @@ func TestAccRDSInstance_replicateSourceDB_nameGenerated(t *testing.T) { }) } -func TestAccRDSInstance_replicateSourceDB_addLater(t *testing.T) { +func TestAccRDSInstance_ReplicateSourceDB_addLater(t *testing.T) { var dbInstance, sourceDbInstance rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -1310,7 +1310,7 @@ func TestAccRDSInstance_ReplicateSourceDB_multiAZ(t *testing.T) { }) } -func TestAccRDSInstance_ReplicateSourceDB_parameterGroupName_sameSetOnBoth(t *testing.T) { +func TestAccRDSInstance_ReplicateSourceDB_parameterGroupNameSameSetOnBoth(t *testing.T) { var dbInstance, sourceDbInstance rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -1339,7 +1339,7 @@ func TestAccRDSInstance_ReplicateSourceDB_parameterGroupName_sameSetOnBoth(t *te }) } -func TestAccRDSInstance_ReplicateSourceDB_parameterGroupName_differentSetOnBoth(t *testing.T) { +func TestAccRDSInstance_ReplicateSourceDB_parameterGroupNameDifferentSetOnBoth(t *testing.T) { var dbInstance, sourceDbInstance rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -1368,7 +1368,7 @@ func TestAccRDSInstance_ReplicateSourceDB_parameterGroupName_differentSetOnBoth( }) } -func TestAccRDSInstance_ReplicateSourceDB_parameterGroupName_replicaCopiesValue(t *testing.T) { +func TestAccRDSInstance_ReplicateSourceDB_parameterGroupNameReplicaCopiesValue(t *testing.T) { var dbInstance, sourceDbInstance rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -1396,7 +1396,7 @@ func TestAccRDSInstance_ReplicateSourceDB_parameterGroupName_replicaCopiesValue( }) } -func TestAccRDSInstance_ReplicateSourceDB_parameterGroupName_setOnReplica(t *testing.T) { +func TestAccRDSInstance_ReplicateSourceDB_parameterGroupNameSetOnReplica(t *testing.T) { var dbInstance, sourceDbInstance rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -1572,7 +1572,7 @@ func TestAccRDSInstance_ReplicateSourceDB_parameterGroupTwoStep(t *testing.T) { }) } -func TestAccRDSInstance_s3Import_basic(t *testing.T) { +func TestAccRDSInstance_S3Import_basic(t *testing.T) { var snap rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) bucketPrefix := sdkacctest.RandString(5) @@ -1605,7 +1605,7 @@ func TestAccRDSInstance_s3Import_basic(t *testing.T) { }) } -func TestAccRDSInstance_s3Import_NameDeprecated_basic(t *testing.T) { +func TestAccRDSInstance_S3Import_nameDeprecated(t *testing.T) { var snap rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) bucketPrefix := sdkacctest.RandString(5) @@ -1638,7 +1638,7 @@ func TestAccRDSInstance_s3Import_NameDeprecated_basic(t *testing.T) { }) } -func TestAccRDSInstance_s3Import_namePrefix(t *testing.T) { +func TestAccRDSInstance_S3Import_namePrefix(t *testing.T) { var snap rds.DBInstance const identifierPrefix = "tf-acc-test-prefix-" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -1672,7 +1672,7 @@ func TestAccRDSInstance_s3Import_namePrefix(t *testing.T) { }) } -func TestAccRDSInstance_s3Import_nameGenerated(t *testing.T) { +func TestAccRDSInstance_S3Import_nameGenerated(t *testing.T) { var snap rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) bucketPrefix := sdkacctest.RandString(5) @@ -1983,7 +1983,7 @@ func TestAccRDSInstance_SnapshotIdentifier_availabilityZone(t *testing.T) { }) } -func TestAccRDSInstance_SnapshotIdentifier_backupRetentionPeriod_override(t *testing.T) { +func TestAccRDSInstance_SnapshotIdentifier_backupRetentionPeriodOverride(t *testing.T) { var dbInstance, sourceDbInstance rds.DBInstance var dbSnapshot rds.DBSnapshot @@ -2011,7 +2011,7 @@ func TestAccRDSInstance_SnapshotIdentifier_backupRetentionPeriod_override(t *tes }) } -func TestAccRDSInstance_SnapshotIdentifier_backupRetentionPeriod_unset(t *testing.T) { +func TestAccRDSInstance_SnapshotIdentifier_backupRetentionPeriodUnset(t *testing.T) { var dbInstance, sourceDbInstance rds.DBInstance var dbSnapshot rds.DBSnapshot @@ -2098,7 +2098,7 @@ func TestAccRDSInstance_SnapshotIdentifier_dbSubnetGroupName(t *testing.T) { }) } -func TestAccRDSInstance_SnapshotIdentifier_DBSubnetGroupName_ramShared(t *testing.T) { +func TestAccRDSInstance_SnapshotIdentifier_dbSubnetGroupNameRAMShared(t *testing.T) { var dbInstance, sourceDbInstance rds.DBInstance var dbSnapshot rds.DBSnapshot var dbSubnetGroup rds.DBSubnetGroup @@ -2134,7 +2134,7 @@ func TestAccRDSInstance_SnapshotIdentifier_DBSubnetGroupName_ramShared(t *testin }) } -func TestAccRDSInstance_SnapshotIdentifier_DBSubnetGroupName_vpcSecurityGroupIDs(t *testing.T) { +func TestAccRDSInstance_SnapshotIdentifier_dbSubnetGroupNameVPCSecurityGroupIDs(t *testing.T) { var dbInstance, sourceDbInstance rds.DBInstance var dbSnapshot rds.DBSnapshot var dbSubnetGroup rds.DBSubnetGroup @@ -2343,7 +2343,7 @@ func TestAccRDSInstance_SnapshotIdentifier_multiAZ(t *testing.T) { }) } -func TestAccRDSInstance_SnapshotIdentifier_multiAZ_sqlServer(t *testing.T) { +func TestAccRDSInstance_SnapshotIdentifier_multiAZSQLServer(t *testing.T) { var dbInstance, sourceDbInstance rds.DBInstance var dbSnapshot rds.DBSnapshot @@ -2457,8 +2457,8 @@ func TestAccRDSInstance_SnapshotIdentifier_tags(t *testing.T) { }) } -func TestAccRDSInstance_SnapshotIdentifier_Tags_Clear(t *testing.T) { - acctest.Skip(t, "To be fixed: https://github.com/hashicorp/terraform-provider-aws/issues/5959") +func TestAccRDSInstance_SnapshotIdentifier_tagsRemove(t *testing.T) { + //acctest.Skip(t, "To be fixed: https://github.com/hashicorp/terraform-provider-aws/issues/5959") // --- FAIL: TestAccRDSInstance_SnapshotIdentifierTags_unset (1086.15s) // testing.go:527: Step 0 error: Check failed: Check 4/4 error: aws_db_instance.test: Attribute 'tags.%' expected "0", got "1" @@ -2520,7 +2520,7 @@ func TestAccRDSInstance_SnapshotIdentifier_vpcSecurityGroupIDs(t *testing.T) { // This acceptance test explicitly tests when snapshot_identifier is set, // vpc_security_group_ids is set (which triggered the resource update function), // and tags is set which was missing its ARN used for tagging -func TestAccRDSInstance_SnapshotIdentifier_vpcSecurityGroupIDs_tags(t *testing.T) { +func TestAccRDSInstance_SnapshotIdentifier_vpcSecurityGroupIDsTags(t *testing.T) { var dbInstance, sourceDbInstance rds.DBInstance var dbSnapshot rds.DBSnapshot @@ -2761,6 +2761,7 @@ func TestAccRDSInstance_portUpdate(t *testing.T) { var v rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_db_instance.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -2771,18 +2772,16 @@ func TestAccRDSInstance_portUpdate(t *testing.T) { { Config: testAccInstanceConfig_SnapshotInstanceConfig_mySQLPort(rName), Check: resource.ComposeTestCheckFunc( - testAccCheckInstanceExists("aws_db_instance.bar", &v), - resource.TestCheckResourceAttr( - "aws_db_instance.bar", "port", "3306"), + testAccCheckInstanceExists(resourceName, &v), + resource.TestCheckResourceAttr(resourceName, "port", "3306"), ), }, { Config: testAccInstanceConfig_SnapshotInstanceConfig_updateMySQLPort(rName), Check: resource.ComposeTestCheckFunc( - testAccCheckInstanceExists("aws_db_instance.bar", &v), - resource.TestCheckResourceAttr( - "aws_db_instance.bar", "port", "3305"), + testAccCheckInstanceExists(resourceName, &v), + resource.TestCheckResourceAttr(resourceName, "port", "3305"), ), }, }, @@ -2891,6 +2890,8 @@ func TestAccRDSInstance_MSSQL_domainSnapshotRestore(t *testing.T) { func TestAccRDSInstance_MySQL_snapshotRestoreWithEngineVersion(t *testing.T) { var v, vRestoredInstance rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_db_instance.test" + restoreResourceName := "aws_db_instance.restore" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -2901,10 +2902,11 @@ func TestAccRDSInstance_MySQL_snapshotRestoreWithEngineVersion(t *testing.T) { { Config: testAccInstanceConfig_MySQLSnapshotRestoreWithEngineVersion(rName), Check: resource.ComposeTestCheckFunc( - testAccCheckInstanceExists("aws_db_instance.mysql_restore", &vRestoredInstance), - testAccCheckInstanceExists("aws_db_instance.mysql", &v), - resource.TestCheckResourceAttr("aws_db_instance.mysql", "engine_version", "8.0.23"), - resource.TestCheckResourceAttr("aws_db_instance.mysql_restore", "engine_version", "8.0.25"), + testAccCheckInstanceExists(restoreResourceName, &vRestoredInstance), + testAccCheckInstanceExists(resourceName, &v), + // Hardcoded older version. Will to update when no longer compatible to upgrade from this to the default version. + resource.TestCheckResourceAttr(resourceName, "engine_version", "8.0.25"), + resource.TestCheckResourceAttrPair(restoreResourceName, "engine_version", "data.aws_rds_engine_version.default", "version"), ), }, }, @@ -3334,12 +3336,12 @@ func testAccCheckInstanceSnapshot(s *terraform.State) error { var found bool for _, t := range listTagsOutput.TagList { - if *t.Key == "Name" && *t.Value == "tf-tags-db" { + if aws.StringValue(t.Key) == "Name" && strings.HasPrefix(aws.StringValue(t.Value), acctest.ResourcePrefix) { found = true } } if !found { - return fmt.Errorf("Expected to find tag Name (%s), but wasn't found. Tags: %s", "tf-tags-db", listTagsOutput.TagList) + return fmt.Errorf("Expected to find tag Name with prefix \"%s\", but wasn't found. Tags: %s", acctest.ResourcePrefix, listTagsOutput.TagList) } // end tag search @@ -4327,7 +4329,7 @@ resource "aws_db_option_group" "test" { option_group_description = "Test option group for terraform" } -resource "aws_db_instance" "bar" { +resource "aws_db_instance" "test" { allocated_storage = 10 engine = aws_db_option_group.test.engine_name engine_version = aws_db_option_group.test.major_engine_version @@ -4904,8 +4906,10 @@ resource "aws_db_instance" "bar" { } func testAccInstanceConfig_SnapshotInstanceConfig_mySQLPort(rName string) string { - return acctest.ConfigCompose(testAccInstanceConfig_orderableClassMySQL(), fmt.Sprintf(` -resource "aws_db_instance" "bar" { + return acctest.ConfigCompose( + testAccInstanceConfig_orderableClassMySQL(), + fmt.Sprintf(` +resource "aws_db_instance" "test" { identifier = %[1]q engine = data.aws_rds_orderable_db_instance.test.engine engine_version = data.aws_rds_orderable_db_instance.test.engine_version @@ -4924,8 +4928,10 @@ resource "aws_db_instance" "bar" { } func testAccInstanceConfig_SnapshotInstanceConfig_updateMySQLPort(rName string) string { - return acctest.ConfigCompose(testAccInstanceConfig_orderableClassMySQL(), fmt.Sprintf(` -resource "aws_db_instance" "bar" { + return acctest.ConfigCompose( + testAccInstanceConfig_orderableClassMySQL(), + fmt.Sprintf(` +resource "aws_db_instance" "test" { identifier = %[1]q engine = data.aws_rds_orderable_db_instance.test.engine engine_version = data.aws_rds_orderable_db_instance.test.engine_version @@ -4948,7 +4954,7 @@ func testAccInstanceConfig_WithSubnetGroup(rName string) string { testAccInstanceConfig_orderableClassMySQL(), acctest.ConfigAvailableAZsNoOptIn(), fmt.Sprintf(` -resource "aws_vpc" "foo" { +resource "aws_vpc" "test" { cidr_block = "10.1.0.0/16" tags = { @@ -4956,36 +4962,36 @@ resource "aws_vpc" "foo" { } } -resource "aws_subnet" "foo" { +resource "aws_subnet" "test" { cidr_block = "10.1.1.0/24" availability_zone = data.aws_availability_zones.available.names[0] - vpc_id = aws_vpc.foo.id + vpc_id = aws_vpc.test.id tags = { Name = %[1]q } } -resource "aws_subnet" "bar" { +resource "aws_subnet" "test2" { cidr_block = "10.1.2.0/24" availability_zone = data.aws_availability_zones.available.names[1] - vpc_id = aws_vpc.foo.id + vpc_id = aws_vpc.test.id tags = { Name = "%[1]s-2" } } -resource "aws_db_subnet_group" "foo" { +resource "aws_db_subnet_group" "test" { name = %[1]q - subnet_ids = [aws_subnet.foo.id, aws_subnet.bar.id] + subnet_ids = [aws_subnet.test.id, aws_subnet.test2.id] tags = { Name = %[1]q } } -resource "aws_db_instance" "bar" { +resource "aws_db_instance" "test" { identifier = %[1]q engine = data.aws_rds_orderable_db_instance.test.engine engine_version = data.aws_rds_orderable_db_instance.test.engine_version @@ -4994,7 +5000,7 @@ resource "aws_db_instance" "bar" { username = "foo" password = "barbarbar" parameter_group_name = "default.${data.aws_rds_engine_version.default.parameter_group_family}" - db_subnet_group_name = aws_db_subnet_group.foo.name + db_subnet_group_name = aws_db_subnet_group.test.name port = 3305 allocated_storage = 10 skip_final_snapshot = true @@ -5010,7 +5016,7 @@ func testAccInstanceConfig_WithSubnetGroupUpdated(rName string) string { testAccInstanceConfig_orderableClassMySQL(), acctest.ConfigAvailableAZsNoOptIn(), fmt.Sprintf(` -resource "aws_vpc" "foo" { +resource "aws_vpc" "test" { cidr_block = "10.1.0.0/16" tags = { @@ -5018,73 +5024,73 @@ resource "aws_vpc" "foo" { } } -resource "aws_vpc" "bar" { - cidr_block = "10.10.0.0/16" +resource "aws_subnet" "test" { + cidr_block = "10.1.1.0/24" + availability_zone = data.aws_availability_zones.available.names[0] + vpc_id = aws_vpc.test.id tags = { Name = %[1]q } } -resource "aws_subnet" "foo" { - cidr_block = "10.1.1.0/24" - availability_zone = data.aws_availability_zones.available.names[0] - vpc_id = aws_vpc.foo.id +resource "aws_subnet" "test2" { + cidr_block = "10.1.2.0/24" + availability_zone = data.aws_availability_zones.available.names[1] + vpc_id = aws_vpc.test.id + + tags = { + Name = "%[1]s-2" + } +} + +resource "aws_db_subnet_group" "test" { + name = %[1]q + subnet_ids = [aws_subnet.test.id, aws_subnet.test2.id] tags = { Name = %[1]q } } -resource "aws_subnet" "bar" { - cidr_block = "10.1.2.0/24" - availability_zone = data.aws_availability_zones.available.names[1] - vpc_id = aws_vpc.foo.id +resource "aws_vpc" "test2" { + cidr_block = "10.10.0.0/16" tags = { Name = "%[1]s-2" } } -resource "aws_subnet" "test" { +resource "aws_subnet" "test3" { cidr_block = "10.10.3.0/24" availability_zone = data.aws_availability_zones.available.names[1] - vpc_id = aws_vpc.bar.id + vpc_id = aws_vpc.test2.id tags = { Name = "%[1]s-3" } } -resource "aws_subnet" "another_test" { +resource "aws_subnet" "test4" { cidr_block = "10.10.4.0/24" availability_zone = data.aws_availability_zones.available.names[0] - vpc_id = aws_vpc.bar.id + vpc_id = aws_vpc.test2.id tags = { Name = "%[1]s-4" } } -resource "aws_db_subnet_group" "foo" { - name = "%[1]s-1" - subnet_ids = [aws_subnet.foo.id, aws_subnet.bar.id] - - tags = { - Name = %[1]q - } -} - -resource "aws_db_subnet_group" "bar" { +resource "aws_db_subnet_group" "test2" { name = "%[1]s-2" - subnet_ids = [aws_subnet.test.id, aws_subnet.another_test.id] + subnet_ids = [aws_subnet.test3.id, aws_subnet.test4.id] tags = { Name = "%[1]s-2" } } -resource "aws_db_instance" "bar" { +resource "aws_db_instance" "test" { identifier = %[1]q engine = data.aws_rds_orderable_db_instance.test.engine engine_version = data.aws_rds_orderable_db_instance.test.engine_version @@ -5093,14 +5099,15 @@ resource "aws_db_instance" "bar" { username = "foo" password = "barbarbar" parameter_group_name = "default.${data.aws_rds_engine_version.default.parameter_group_family}" - db_subnet_group_name = aws_db_subnet_group.bar.name + db_subnet_group_name = aws_db_subnet_group.test2.name port = 3305 allocated_storage = 10 skip_final_snapshot = true backup_retention_period = 0 + apply_immediately = true - apply_immediately = true + depends_on = [aws_db_subnet_group.test] } `, rName)) } @@ -5461,7 +5468,7 @@ func testAccInstanceConfig_MySQLSnapshotRestoreWithEngineVersion(rName string) s testAccInstanceConfig_orderableClassMySQL(), acctest.ConfigAvailableAZsNoOptIn(), fmt.Sprintf(` -resource "aws_vpc" "foo" { +resource "aws_vpc" "test" { cidr_block = "10.1.0.0/16" enable_dns_hostnames = true @@ -5470,15 +5477,14 @@ resource "aws_vpc" "foo" { } } -resource "aws_db_subnet_group" "rds_one" { +resource "aws_db_subnet_group" "test" { name = %[1]q - description = "db subnets for rds_one" - - subnet_ids = [aws_subnet.main.id, aws_subnet.other.id] + description = "db subnets" + subnet_ids = [aws_subnet.test.id, aws_subnet.test2.id] } -resource "aws_subnet" "main" { - vpc_id = aws_vpc.foo.id +resource "aws_subnet" "test" { + vpc_id = aws_vpc.test.id availability_zone = data.aws_availability_zones.available.names[0] cidr_block = "10.1.1.0/24" @@ -5487,8 +5493,8 @@ resource "aws_subnet" "main" { } } -resource "aws_subnet" "other" { - vpc_id = aws_vpc.foo.id +resource "aws_subnet" "test2" { + vpc_id = aws_vpc.test.id availability_zone = data.aws_availability_zones.available.names[1] cidr_block = "10.1.2.0/24" @@ -5497,10 +5503,10 @@ resource "aws_subnet" "other" { } } -resource "aws_db_instance" "mysql" { +resource "aws_db_instance" "test" { allocated_storage = 20 - engine = data.aws_rds_orderable_db_instance.test.engine - engine_version = data.aws_rds_orderable_db_instance.test.engine_version + engine = data.aws_rds_engine_version.default.engine + engine_version = "8.0.25" # test is from older to newer version, update when restore from this to current default version is incompatible identifier = %[1]q instance_class = data.aws_rds_orderable_db_instance.test.instance_class password = "password" @@ -5508,45 +5514,42 @@ resource "aws_db_instance" "mysql" { username = "root" } -resource "aws_db_snapshot" "mysql-snap" { - db_instance_identifier = aws_db_instance.mysql.id +resource "aws_db_snapshot" "test" { + db_instance_identifier = aws_db_instance.test.id db_snapshot_identifier = %[1]q } -resource "aws_db_instance" "mysql_restore" { - identifier = "%[1]s-restore" - - db_subnet_group_name = aws_db_subnet_group.rds_one.name - - instance_class = data.aws_rds_orderable_db_instance.test.instance_class +resource "aws_db_instance" "restore" { allocated_storage = 20 - username = "root" - password = "password" - engine = data.aws_rds_orderable_db_instance.test.engine - engine_version = "8.0.25" + apply_immediately = true backup_retention_period = 0 + db_subnet_group_name = aws_db_subnet_group.test.name + engine = data.aws_rds_engine_version.default.engine + engine_version = data.aws_rds_engine_version.default.version + identifier = "%[1]s-restore" + instance_class = data.aws_rds_orderable_db_instance.test.instance_class + password = "password" skip_final_snapshot = true - snapshot_identifier = aws_db_snapshot.mysql-snap.id - - apply_immediately = true - vpc_security_group_ids = [aws_security_group.rds-mysql.id] + snapshot_identifier = aws_db_snapshot.test.id + username = "root" + vpc_security_group_ids = [aws_security_group.test.id] } -resource "aws_security_group" "rds-mysql" { +resource "aws_security_group" "test" { name = %[1]q description = "TF Testing" - vpc_id = aws_vpc.foo.id + vpc_id = aws_vpc.test.id } -resource "aws_security_group_rule" "rds-mysql-1" { +resource "aws_security_group_rule" "test" { type = "egress" from_port = 0 to_port = 0 protocol = "-1" cidr_blocks = ["0.0.0.0/0"] - security_group_id = aws_security_group.rds-mysql.id + security_group_id = aws_security_group.test.id } `, rName)) } @@ -5569,12 +5572,14 @@ resource "aws_db_instance" "test" { } func testAccInstanceConfig_AutoMinorVersion(rName string) string { - return acctest.ConfigCompose(testAccInstanceConfig_orderableClassMySQL(), fmt.Sprintf(` + return acctest.ConfigCompose( + testAccInstanceConfig_orderableClassMySQL(), + fmt.Sprintf(` resource "aws_db_instance" "bar" { identifier = %[1]q allocated_storage = 10 - engine = data.aws_rds_orderable_db_instance.test.engine - engine_version = "8.0" + engine = data.aws_rds_engine_version.default.engine + engine_version = regex("^\\d+\\.\\d+", data.aws_rds_engine_version.default.version) instance_class = data.aws_rds_orderable_db_instance.test.instance_class db_name = "baz" password = "barbarbarbar" @@ -6591,15 +6596,20 @@ resource "aws_db_subnet_group" "test" { subnet_ids = aws_subnet.test[*].id } +data "aws_rds_engine_version" "default" { + provider = "awsalternate" + engine = "mysql" +} + data "aws_rds_orderable_db_instance" "test" { provider = "awsalternate" - engine = "mysql" - engine_version = "8.0.23" + engine = data.aws_rds_engine_version.default.engine + engine_version = data.aws_rds_engine_version.default.version license_model = "general-public-license" storage_type = "standard" - preferred_instance_classes = ["db.t3.micro", "db.t2.micro", "db.t2.medium"] + preferred_instance_classes = [%[2]s] } resource "aws_db_instance" "source" { @@ -6608,7 +6618,7 @@ resource "aws_db_instance" "source" { allocated_storage = 5 backup_retention_period = 1 db_subnet_group_name = aws_db_subnet_group.alternate.name - engine = data.aws_rds_orderable_db_instance.test.engine + engine = data.aws_rds_engine_version.default.engine identifier = "%[1]s-source" instance_class = data.aws_rds_orderable_db_instance.test.instance_class password = "avoid-plaintext-passwords" @@ -6623,7 +6633,7 @@ resource "aws_db_instance" "test" { replicate_source_db = aws_db_instance.source.arn skip_final_snapshot = true } -`, rName)) +`, rName, mySQLPreferredInstanceClasses)) } // When testing needs to distinguish a second region and second account in the same region @@ -6764,15 +6774,20 @@ resource "aws_security_group" "test" { vpc_id = aws_vpc.alternateaccountsameregion.id } +data "aws_rds_engine_version" "default" { + provider = "awssameaccountalternateregion" + engine = "mysql" +} + data "aws_rds_orderable_db_instance" "test" { provider = "awssameaccountalternateregion" - engine = "mysql" - engine_version = "8.0.23" + engine = data.aws_rds_engine_version.default.engine + engine_version = data.aws_rds_engine_version.default.version license_model = "general-public-license" storage_type = "standard" - preferred_instance_classes = ["db.t3.micro", "db.t2.micro", "db.t2.medium"] + preferred_instance_classes = [%[2]s] } resource "aws_db_instance" "source" { @@ -6781,7 +6796,8 @@ resource "aws_db_instance" "source" { allocated_storage = 5 backup_retention_period = 1 db_subnet_group_name = aws_db_subnet_group.sameaccountalternateregion.name - engine = data.aws_rds_orderable_db_instance.test.engine + engine = data.aws_rds_engine_version.default.engine + engine_version = data.aws_rds_engine_version.default.version identifier = "%[1]s-source" instance_class = data.aws_rds_orderable_db_instance.test.instance_class password = "avoid-plaintext-passwords" @@ -6797,7 +6813,7 @@ resource "aws_db_instance" "test" { skip_final_snapshot = true vpc_security_group_ids = [aws_security_group.test.id] } -`, rName)) +`, rName, mySQLPreferredInstanceClasses)) } func testAccInstanceConfig_ReplicateSourceDB_DbSubnetGroupName_VPCSecurityGroupIDs(rName string) string { @@ -6876,15 +6892,20 @@ resource "aws_db_subnet_group" "test" { subnet_ids = aws_subnet.test[*].id } +data "aws_rds_engine_version" "default" { + provider = "awsalternate" + engine = "mysql" +} + data "aws_rds_orderable_db_instance" "test" { provider = "awsalternate" - engine = "mysql" - engine_version = "8.0.23" + engine = data.aws_rds_engine_version.default.engine + engine_version = data.aws_rds_engine_version.default.version license_model = "general-public-license" storage_type = "standard" - preferred_instance_classes = ["db.t3.micro", "db.t2.micro", "db.t2.medium"] + preferred_instance_classes = [%[2]s] } resource "aws_db_instance" "source" { @@ -6909,7 +6930,7 @@ resource "aws_db_instance" "test" { skip_final_snapshot = true vpc_security_group_ids = [aws_security_group.test.id] } -`, rName)) +`, rName, mySQLPreferredInstanceClasses)) } func testAccInstanceConfig_ReplicateSourceDB_DeletionProtection(rName string, deletionProtection bool) string { @@ -7611,9 +7632,9 @@ resource "aws_db_instance" "test" { func testAccInstanceConfig_SnapshotIdentifier_AllowMajorVersionUpgrade(rName string, allowMajorVersionUpgrade bool) string { return fmt.Sprintf(` -data "aws_rds_orderable_db_instance" "postgres10" { +data "aws_rds_orderable_db_instance" "postgres13" { engine = "postgres" - engine_version = "10.1" + engine_version = "13.5" license_model = "postgresql-license" storage_type = "standard" @@ -7622,10 +7643,10 @@ data "aws_rds_orderable_db_instance" "postgres10" { resource "aws_db_instance" "source" { allocated_storage = 5 - engine = data.aws_rds_orderable_db_instance.postgres10.engine - engine_version = data.aws_rds_orderable_db_instance.postgres10.engine_version + engine = data.aws_rds_orderable_db_instance.postgres13.engine + engine_version = data.aws_rds_orderable_db_instance.postgres13.engine_version identifier = "%[1]s-source" - instance_class = data.aws_rds_orderable_db_instance.postgres10.instance_class + instance_class = data.aws_rds_orderable_db_instance.postgres13.instance_class password = "avoid-plaintext-passwords" username = "tfacctest" skip_final_snapshot = true @@ -7636,9 +7657,9 @@ resource "aws_db_snapshot" "test" { db_snapshot_identifier = %[1]q } -data "aws_rds_orderable_db_instance" "postgres11" { +data "aws_rds_orderable_db_instance" "postgres14" { engine = "postgres" - engine_version = "11.1" + engine_version = "14.1" license_model = "postgresql-license" storage_type = "standard" @@ -7647,8 +7668,8 @@ data "aws_rds_orderable_db_instance" "postgres11" { resource "aws_db_instance" "test" { allow_major_version_upgrade = %[2]t - engine = data.aws_rds_orderable_db_instance.postgres11.engine - engine_version = data.aws_rds_orderable_db_instance.postgres11.engine_version + engine = data.aws_rds_orderable_db_instance.postgres14.engine + engine_version = data.aws_rds_orderable_db_instance.postgres14.engine_version identifier = %[1]q instance_class = aws_db_instance.source.instance_class snapshot_identifier = aws_db_snapshot.test.id diff --git a/internal/service/rds/subnet_group.go b/internal/service/rds/subnet_group.go index 47a29fe7fe6..a3c0ba1894e 100644 --- a/internal/service/rds/subnet_group.go +++ b/internal/service/rds/subnet_group.go @@ -222,7 +222,12 @@ func resourceSubnetGroupDelete(d *schema.ResourceData, meta interface{}) error { MinTimeout: 1 * time.Second, } _, err := stateConf.WaitForState() - return err + + if err != nil { + return fmt.Errorf("deleting RDS Subnet Group (%s): %w", d.Id(), err) + } + + return nil } func resourceSubnetGroupDeleteRefreshFunc( diff --git a/internal/service/rds/wait.go b/internal/service/rds/wait.go index a3917df1d14..2edd2eb0326 100644 --- a/internal/service/rds/wait.go +++ b/internal/service/rds/wait.go @@ -161,11 +161,12 @@ func waitDBInstanceDeleted(conn *rds.RDS, id string, timeout time.Duration) (*rd InstanceStatusStorageFull, InstanceStatusStorageOptimization, }, - Target: []string{}, - Refresh: statusDBInstance(conn, id), - Timeout: timeout, - MinTimeout: 10 * time.Second, - Delay: 30 * time.Second, + Target: []string{}, + Refresh: statusDBInstance(conn, id), + Timeout: timeout, + MinTimeout: 10 * time.Second, + Delay: 30 * time.Second, + ContinuousTargetOccurence: 3, } outputRaw, err := stateConf.WaitForState() From 7a6db9d363ec6903b750db7a067d228f801cf65b Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Tue, 8 Mar 2022 15:37:13 -0500 Subject: [PATCH 10/32] Continue skipping unfixed test --- internal/service/rds/instance_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/rds/instance_test.go b/internal/service/rds/instance_test.go index 1238ddde5d0..ecbed815231 100644 --- a/internal/service/rds/instance_test.go +++ b/internal/service/rds/instance_test.go @@ -2458,7 +2458,7 @@ func TestAccRDSInstance_SnapshotIdentifier_tags(t *testing.T) { } func TestAccRDSInstance_SnapshotIdentifier_tagsRemove(t *testing.T) { - //acctest.Skip(t, "To be fixed: https://github.com/hashicorp/terraform-provider-aws/issues/5959") + acctest.Skip(t, "To be fixed: https://github.com/hashicorp/terraform-provider-aws/issues/5959") // --- FAIL: TestAccRDSInstance_SnapshotIdentifierTags_unset (1086.15s) // testing.go:527: Step 0 error: Check failed: Check 4/4 error: aws_db_instance.test: Attribute 'tags.%' expected "0", got "1" From bd79e33f57d2c3ab382c2a8a241200bf058a010f Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Tue, 8 Mar 2022 16:27:47 -0500 Subject: [PATCH 11/32] Flint and steel --- internal/service/rds/global_cluster_test.go | 1 - internal/service/rds/instance.go | 9 +++++++-- internal/service/rds/instance_test.go | 16 ++++++---------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/internal/service/rds/global_cluster_test.go b/internal/service/rds/global_cluster_test.go index 586ffe58f26..ffb72cf43ec 100644 --- a/internal/service/rds/global_cluster_test.go +++ b/internal/service/rds/global_cluster_test.go @@ -602,7 +602,6 @@ resource "aws_rds_cluster" "test" { resource "aws_rds_cluster_instance" "test" { apply_immediately = true cluster_identifier = aws_rds_cluster.test.id - #cluster_identifier = %[3]q engine = %[1]q engine_version = %[2]q identifier = %[3]q diff --git a/internal/service/rds/instance.go b/internal/service/rds/instance.go index c8cfbe783df..a4b4c4c20ed 100644 --- a/internal/service/rds/instance.go +++ b/internal/service/rds/instance.go @@ -1808,7 +1808,7 @@ func resourceInstanceUpdate(d *schema.ResourceData, meta interface{}) error { if requestUpdate { log.Printf("[DEBUG] DB Instance Modification request: %s", req) - err := resource.Retry(tfiam.PropagationTimeout, func() *resource.RetryError { + err := resource.Retry(d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError { _, err := conn.ModifyDBInstance(req) // Retry for IAM eventual consistency @@ -1816,6 +1816,11 @@ func resourceInstanceUpdate(d *schema.ResourceData, meta interface{}) error { return resource.RetryableError(err) } + // InvalidDBInstanceState: RDS is configuring Enhanced Monitoring or Performance Insights for this DB instance. Try your request later. + if tfawserr.ErrMessageContains(err, rds.ErrCodeInvalidDBInstanceStateFault, "your request later") { + return resource.RetryableError(err) + } + if err != nil { return resource.NonRetryableError(err) } @@ -1828,7 +1833,7 @@ func resourceInstanceUpdate(d *schema.ResourceData, meta interface{}) error { } if err != nil { - return fmt.Errorf("Error modifying DB Instance %s: %w", d.Id(), err) + return fmt.Errorf("modifying DB Instance %s: %w", d.Id(), err) } log.Printf("[DEBUG] Waiting for DB Instance (%s) to be available", d.Id()) diff --git a/internal/service/rds/instance_test.go b/internal/service/rds/instance_test.go index ecbed815231..4a37d60c133 100644 --- a/internal/service/rds/instance_test.go +++ b/internal/service/rds/instance_test.go @@ -5480,7 +5480,7 @@ resource "aws_vpc" "test" { resource "aws_db_subnet_group" "test" { name = %[1]q description = "db subnets" - subnet_ids = [aws_subnet.test.id, aws_subnet.test2.id] + subnet_ids = [aws_subnet.test.id, aws_subnet.test2.id] } resource "aws_subnet" "test" { @@ -5606,8 +5606,7 @@ resource "aws_vpc" "foo" { resource "aws_db_subnet_group" "rds_one" { name = %[1]q description = "db subnets for rds_one" - - subnet_ids = [aws_subnet.main.id, aws_subnet.other.id] + subnet_ids = [aws_subnet.main.id, aws_subnet.other.id] } resource "aws_subnet" "main" { @@ -5668,8 +5667,7 @@ resource "aws_vpc" "foo" { resource "aws_db_subnet_group" "rds_one" { name = %[1]q description = "db subnets for rds_one" - - subnet_ids = [aws_subnet.main.id, aws_subnet.other.id] + subnet_ids = [aws_subnet.main.id, aws_subnet.other.id] } resource "aws_subnet" "main" { @@ -5733,8 +5731,7 @@ resource "aws_vpc" "foo" { resource "aws_db_subnet_group" "rds_one" { name = %[1]q description = "db subnets for rds_one" - - subnet_ids = [aws_subnet.main.id, aws_subnet.other.id] + subnet_ids = [aws_subnet.main.id, aws_subnet.other.id] } resource "aws_subnet" "main" { @@ -5798,8 +5795,7 @@ resource "aws_vpc" "foo" { resource "aws_db_subnet_group" "rds_one" { name = %[1]q description = "db subnets for rds_one" - - subnet_ids = [aws_subnet.main.id, aws_subnet.other.id] + subnet_ids = [aws_subnet.main.id, aws_subnet.other.id] } resource "aws_subnet" "main" { @@ -6597,7 +6593,7 @@ resource "aws_db_subnet_group" "test" { } data "aws_rds_engine_version" "default" { - provider = "awsalternate" + provider = "awsalternate" engine = "mysql" } From 2706b53a072e1491bec7ae24b9f123fd60e9924b Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Tue, 8 Mar 2022 16:32:21 -0500 Subject: [PATCH 12/32] More flint --- internal/service/rds/cluster.go | 4 ---- internal/service/rds/global_cluster.go | 3 --- internal/service/rds/instance_test.go | 4 ++-- internal/service/rds/verify.go | 5 ----- 4 files changed, 2 insertions(+), 14 deletions(-) diff --git a/internal/service/rds/cluster.go b/internal/service/rds/cluster.go index 31391e56678..4836782c5bd 100644 --- a/internal/service/rds/cluster.go +++ b/internal/service/rds/cluster.go @@ -559,7 +559,6 @@ func resourceClusterCreate(d *schema.ResourceData, meta interface{}) error { } if attr, ok := d.GetOk("engine_version"); ok { - fmt.Printf("[CREATE/cluster/snapshot_identifier] engine_version: %s\n", attr.(string)) opts.EngineVersion = aws.String(attr.(string)) } @@ -655,7 +654,6 @@ func resourceClusterCreate(d *schema.ResourceData, meta interface{}) error { } if attr, ok := d.GetOk("engine_version"); ok { - fmt.Printf("[CREATE/cluster/s3_import] engine_version: %s\n", attr.(string)) createOpts.EngineVersion = aws.String(attr.(string)) } @@ -873,7 +871,6 @@ func resourceClusterCreate(d *schema.ResourceData, meta interface{}) error { } if attr, ok := d.GetOk("engine_version"); ok { - fmt.Printf("[CREATE/cluster/else] engine_version: %s\n", attr.(string)) createOpts.EngineVersion = aws.String(attr.(string)) } @@ -1186,7 +1183,6 @@ func resourceClusterUpdate(d *schema.ResourceData, meta interface{}) error { } if d.HasChange("engine_version") { - fmt.Printf("[UPDATE/cluster] engine_version: %s\n", d.Get("engine_version").(string)) req.EngineVersion = aws.String(d.Get("engine_version").(string)) requestUpdate = true } diff --git a/internal/service/rds/global_cluster.go b/internal/service/rds/global_cluster.go index 674f4e6fa79..28bd6004fec 100644 --- a/internal/service/rds/global_cluster.go +++ b/internal/service/rds/global_cluster.go @@ -128,7 +128,6 @@ func resourceGlobalClusterCreate(d *schema.ResourceData, meta interface{}) error } if v, ok := d.GetOk("engine_version"); ok { - fmt.Printf("[CREATE/global_cluster] engine_version: %s\n", v.(string)) input.EngineVersion = aws.String(v.(string)) } @@ -193,7 +192,6 @@ func resourceGlobalClusterRead(d *schema.ResourceData, meta interface{}) error { d.Set("deletion_protection", globalCluster.DeletionProtection) d.Set("engine", globalCluster.Engine) d.Set("engine_version", globalCluster.EngineVersion) - fmt.Printf("[READ/global_cluster] engine_verison: %s\n", aws.StringValue(globalCluster.EngineVersion)) d.Set("global_cluster_identifier", globalCluster.GlobalClusterIdentifier) if err := d.Set("global_cluster_members", flattenGlobalClusterMembers(globalCluster.GlobalClusterMembers)); err != nil { @@ -215,7 +213,6 @@ func resourceGlobalClusterUpdate(d *schema.ResourceData, meta interface{}) error } if d.HasChange("engine_version") { - fmt.Printf("[UPDATE/global_cluster] engine_version: %s\n", d.Get("engine_version").(string)) if err := resourceGlobalClusterUpgradeEngineVersion(d, conn); err != nil { return err } diff --git a/internal/service/rds/instance_test.go b/internal/service/rds/instance_test.go index 4a37d60c133..ca3b4baaf4b 100644 --- a/internal/service/rds/instance_test.go +++ b/internal/service/rds/instance_test.go @@ -4185,7 +4185,7 @@ resource "aws_db_instance" "test" { func testAccInstanceConfig_MajorVersionOnly() string { return acctest.ConfigCompose( testAccInstanceConfig_orderableClassMySQL(), - fmt.Sprintf(` + ` resource "aws_db_instance" "test" { allocated_storage = 10 backup_retention_period = 0 @@ -4203,7 +4203,7 @@ resource "aws_db_instance" "test" { # validation error). maintenance_window = "Fri:09:00-Fri:09:30" } -`)) +`) } func testAccInstanceConfig_namePrefix(identifierPrefix string) string { diff --git a/internal/service/rds/verify.go b/internal/service/rds/verify.go index 11ec581641e..c7df67724dc 100644 --- a/internal/service/rds/verify.go +++ b/internal/service/rds/verify.go @@ -1,8 +1,6 @@ package rds import ( - "fmt" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) @@ -15,10 +13,7 @@ func compareActualEngineVersion(d *schema.ResourceData, oldVersion string, newVe if oldVersion != newVersion && string(append([]byte(oldVersion), []byte(".")...)) != newVersionSubstr { d.Set("engine_version", newVersion) - fmt.Printf("[READ/cluster] engine_version: %s\n", newVersion) } d.Set("engine_version_actual", newVersion) - fmt.Printf("[READ/cluster] engine_version_actual: %s\n", newVersion) - } From bd7bdd783370b2f0bf5af606d8d86b818a8aee54 Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Thu, 10 Mar 2022 17:49:26 -0500 Subject: [PATCH 13/32] Fix additional tests --- internal/service/rds/cluster_instance_test.go | 6 +- internal/service/rds/cluster_test.go | 48 +++++--- .../rds/engine_version_data_source_test.go | 12 +- internal/service/rds/event_subscription.go | 4 +- internal/service/rds/global_cluster.go | 4 + internal/service/rds/global_cluster_test.go | 79 +++++++----- .../service/rds/instance_data_source_test.go | 113 +++++++++++------- internal/service/rds/wait.go | 13 +- 8 files changed, 171 insertions(+), 108 deletions(-) diff --git a/internal/service/rds/cluster_instance_test.go b/internal/service/rds/cluster_instance_test.go index 649138ddf61..d688a4a6f6d 100644 --- a/internal/service/rds/cluster_instance_test.go +++ b/internal/service/rds/cluster_instance_test.go @@ -656,7 +656,7 @@ func TestAccRDSClusterInstance_PerformanceInsightsKMSKeyIDAuroraMySQL1_defaultKe }, { Config: testAccClusterInstancePerformanceInsightsKMSKeyIdAuroraMySQL1Config(rName, engine), - ExpectError: regexp.MustCompile(`InvalidParameterCombination: You cannot change your Performance Insights KMS key`), + ExpectError: regexp.MustCompile(`InvalidParameterCombination: You .* change your Performance Insights KMS key`), }, }, }) @@ -728,7 +728,7 @@ func TestAccRDSClusterInstance_PerformanceInsightsKMSKeyIDAuroraMySQL2_defaultKe }, { Config: testAccClusterInstancePerformanceInsightsKMSKeyIdAuroraMySQL2Config(rName, engine, engineVersion), - ExpectError: regexp.MustCompile(`InvalidParameterCombination: You cannot change your Performance Insights KMS key`), + ExpectError: regexp.MustCompile(`InvalidParameterCombination: You .* change your Performance Insights KMS key`), }, }, }) @@ -838,7 +838,7 @@ func TestAccRDSClusterInstance_PerformanceInsightsKMSKeyIDAuroraPostgresql_defau }, { Config: testAccClusterInstancePerformanceInsightsKMSKeyIdAuroraPostgresqlConfig(rName, engine), - ExpectError: regexp.MustCompile(`InvalidParameterCombination: You cannot change your Performance Insights KMS key`), + ExpectError: regexp.MustCompile(`InvalidParameterCombination: You .* change your Performance Insights KMS key`), }, }, }) diff --git a/internal/service/rds/cluster_test.go b/internal/service/rds/cluster_test.go index 0ac9a15bc8a..d0abe29c25e 100644 --- a/internal/service/rds/cluster_test.go +++ b/internal/service/rds/cluster_test.go @@ -91,8 +91,8 @@ func TestAccRDSCluster_allowMajorVersionUpgrade(t *testing.T) { // 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" + engineVersion1 := "12.9" + engineVersion2 := "13.5" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -144,8 +144,8 @@ func TestAccRDSCluster_allowMajorVersionUpgradeWithCustomParametersApplyImm(t *t // either by having a new data source created or implementing the testing similar // to TestAccAWSDmsReplicationInstance_EngineVersion engine := "aurora-postgresql" - engineVersion1 := "11.9" - engineVersion2 := "12.4" + engineVersion1 := "12.9" + engineVersion2 := "13.5" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -183,8 +183,8 @@ func TestAccRDSCluster_allowMajorVersionUpgradeWithCustomParameters(t *testing.T // 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" + engineVersion1 := "12.9" + engineVersion2 := "13.5" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -1242,7 +1242,7 @@ func TestAccRDSCluster_GlobalClusterIdentifier_secondaryClustersWriteForwarding( func TestAccRDSCluster_port(t *testing.T) { var dbCluster1, dbCluster2 rds.DBCluster - rInt := sdkacctest.RandInt() + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_rds_cluster.test" resource.ParallelTest(t, resource.TestCase{ @@ -1252,14 +1252,14 @@ func TestAccRDSCluster_port(t *testing.T) { CheckDestroy: testAccCheckClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccClusterConfig_Port(rInt, 5432), + Config: testAccClusterConfig_Port(rName, 5432), Check: resource.ComposeTestCheckFunc( testAccCheckClusterExists(resourceName, &dbCluster1), resource.TestCheckResourceAttr(resourceName, "port", "5432"), ), }, { - Config: testAccClusterConfig_Port(rInt, 2345), + Config: testAccClusterConfig_Port(rName, 2345), Check: resource.ComposeTestCheckFunc( testAccCheckClusterExists(resourceName, &dbCluster2), resource.TestCheckResourceAttr(resourceName, "port", "2345"), @@ -2595,7 +2595,7 @@ func testAccClusterConfig_EngineVersion(upgrade bool, rInt int) string { return fmt.Sprintf(` data "aws_rds_engine_version" "test" { engine = "aurora-postgresql" - preferred_versions = ["9.6.3", "9.6.6", "9.6.8"] + preferred_versions = ["11.6", "11.7", "11.9"] } data "aws_rds_engine_version" "upgrade" { @@ -2666,19 +2666,19 @@ resource "aws_rds_cluster_instance" "test" { `, upgrade, rInt) } -func testAccClusterConfig_Port(rInt, port int) string { +func testAccClusterConfig_Port(rName string, port int) string { return fmt.Sprintf(` resource "aws_rds_cluster" "test" { - cluster_identifier = "tf-acc-test-%d" + cluster_identifier = %[1]q database_name = "mydb" - db_cluster_parameter_group_name = "default.aurora-postgresql11" + db_cluster_parameter_group_name = "default.aurora-postgresql13" engine = "aurora-postgresql" master_password = "mustbeeightcharaters" master_username = "foo" - port = %d + port = %[2]d skip_final_snapshot = true } -`, rInt, port) +`, rName, port) } func testAccClusterIncludingIAMRolesConfig(n int) string { @@ -3182,7 +3182,7 @@ func testAccClusterConfig_GlobalClusterIdentifier_EngineMode_Provisioned(rName s return fmt.Sprintf(` resource "aws_rds_global_cluster" "test" { engine = "aurora-postgresql" - engine_version = "10.11" + engine_version = "12.9" global_cluster_identifier = %[1]q } @@ -3409,10 +3409,20 @@ data "aws_availability_zones" "alternate" { } } +data "aws_rds_engine_version" "default" { + engine = "aurora-postgresql" +} + +data "aws_rds_orderable_db_instance" "test" { + engine = data.aws_rds_engine_version.default.engine + engine_version = data.aws_rds_engine_version.default.version + preferred_instance_classes = ["db.r5.large", "db.r5.xlarge", "db.r6g.large"] # Aurora global db may be limited to rx +} + resource "aws_rds_global_cluster" "test" { global_cluster_identifier = %[1]q - engine = "aurora-postgresql" - engine_version = "10.11" + engine = data.aws_rds_engine_version.default.engine + engine_version = data.aws_rds_engine_version.default.version } resource "aws_rds_cluster" "primary" { @@ -3431,7 +3441,7 @@ resource "aws_rds_cluster_instance" "primary" { engine = aws_rds_cluster.primary.engine engine_version = aws_rds_cluster.primary.engine_version identifier = "%[1]s-primary" - instance_class = "db.r4.large" # only db.r4 or db.r5 are valid for Aurora global db + instance_class = data.aws_rds_orderable_db_instance.test.instance_class } resource "aws_vpc" "alternate" { diff --git a/internal/service/rds/engine_version_data_source_test.go b/internal/service/rds/engine_version_data_source_test.go index 83189f55c7c..26d76153ca6 100644 --- a/internal/service/rds/engine_version_data_source_test.go +++ b/internal/service/rds/engine_version_data_source_test.go @@ -81,7 +81,7 @@ func TestAccRDSEngineVersionDataSource_preferred(t *testing.T) { { Config: testAccEngineVersionPreferredDataSourceConfig(), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "version", "5.7.19"), + resource.TestCheckResourceAttr(dataSourceName, "version", "8.0.27"), ), }, }, @@ -129,9 +129,9 @@ func testAccEngineVersionPreCheck(t *testing.T) { func testAccEngineVersionBasicDataSourceConfig(engine, version, paramGroup string) string { return fmt.Sprintf(` data "aws_rds_engine_version" "test" { - engine = %q - version = %q - parameter_group_family = %q + engine = %[1]q + version = %[2]q + parameter_group_family = %[3]q } `, engine, version, paramGroup) } @@ -140,7 +140,7 @@ func testAccEngineVersionUpgradeTargetsDataSourceConfig() string { return ` data "aws_rds_engine_version" "test" { engine = "mysql" - version = "5.7.17" + version = "8.0.27" } ` } @@ -149,7 +149,7 @@ func testAccEngineVersionPreferredDataSourceConfig() string { return ` data "aws_rds_engine_version" "test" { engine = "mysql" - preferred_versions = ["85.9.12", "5.7.19", "5.7.17"] + preferred_versions = ["85.9.12", "8.0.27", "8.0.26"] } ` } diff --git a/internal/service/rds/event_subscription.go b/internal/service/rds/event_subscription.go index 4b45d79ee36..5b5711d5b5c 100644 --- a/internal/service/rds/event_subscription.go +++ b/internal/service/rds/event_subscription.go @@ -193,9 +193,7 @@ func resourceEventSubscriptionUpdate(d *schema.ResourceData, meta interface{}) e SubscriptionName: aws.String(d.Id()), } - if d.HasChange("enabled") { - input.Enabled = aws.Bool(d.Get("enabled").(bool)) - } + input.Enabled = aws.Bool(d.Get("enabled").(bool)) if d.HasChange("event_categories") { input.EventCategories = flex.ExpandStringSet(d.Get("event_categories").(*schema.Set)) diff --git a/internal/service/rds/global_cluster.go b/internal/service/rds/global_cluster.go index 28bd6004fec..5032a90cb7b 100644 --- a/internal/service/rds/global_cluster.go +++ b/internal/service/rds/global_cluster.go @@ -563,6 +563,10 @@ func resourceGlobalClusterUpgradeMinorEngineVersion(clusterMembers *schema.Set, return resource.RetryableError(err) } + if tfawserr.ErrMessageContains(err, "InvalidParameterValue", "Invalid database cluster identifier") { + return resource.RetryableError(err) + } + if tfawserr.ErrMessageContains(err, rds.ErrCodeInvalidDBClusterStateFault, "Cannot modify engine version without a primary instance in DB cluster") { return resource.NonRetryableError(err) } diff --git a/internal/service/rds/global_cluster_test.go b/internal/service/rds/global_cluster_test.go index ffb72cf43ec..db9c725e3f0 100644 --- a/internal/service/rds/global_cluster_test.go +++ b/internal/service/rds/global_cluster_test.go @@ -183,10 +183,10 @@ func TestAccRDSGlobalCluster_EngineVersion_aurora(t *testing.T) { CheckDestroy: testAccCheckGlobalClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccGlobalClusterEngineVersionConfig(rName, "aurora", "5.6.10a"), + Config: testAccGlobalClusterEngineVersionConfig(rName, "aurora"), Check: resource.ComposeTestCheckFunc( testAccCheckGlobalClusterExists(resourceName, &globalCluster1), - resource.TestCheckResourceAttr(resourceName, "engine_version", "5.6.10a"), + resource.TestCheckResourceAttrPair(resourceName, "engine_version", "data.aws_rds_engine_version.default", "version"), ), }, { @@ -210,17 +210,17 @@ func TestAccRDSGlobalCluster_engineVersionUpdateMinor(t *testing.T) { CheckDestroy: testAccCheckGlobalClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccGlobalClusterWithPrimaryEngineVersionConfig(rName, "aurora-mysql", "5.7.mysql_aurora.2.10.1"), + Config: testAccGlobalClusterWithPrimaryEngineVersionConfig(rName, "aurora-postgresql", "13.4"), Check: resource.ComposeTestCheckFunc( testAccCheckGlobalClusterExists(resourceName, &globalCluster1), ), }, { - Config: testAccGlobalClusterWithPrimaryEngineVersionConfig(rName, "aurora-mysql", "5.7.mysql_aurora.2.10.2"), + Config: testAccGlobalClusterWithPrimaryEngineVersionConfig(rName, "aurora-postgresql", "13.5"), Check: resource.ComposeTestCheckFunc( testAccCheckGlobalClusterExists(resourceName, &globalCluster2), testAccCheckGlobalClusterNotRecreated(&globalCluster1, &globalCluster2), - resource.TestCheckResourceAttr(resourceName, "engine_version", "5.7.mysql_aurora.2.10.2"), + resource.TestCheckResourceAttr(resourceName, "engine_version", "13.5"), ), }, { @@ -244,18 +244,17 @@ func TestAccRDSGlobalCluster_engineVersionUpdateMajor(t *testing.T) { CheckDestroy: testAccCheckGlobalClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccGlobalClusterWithPrimaryEngineVersionConfig(rName, "aurora", "5.7.mysql_aurora.2.10.2"), + Config: testAccGlobalClusterWithPrimaryEngineVersionConfig(rName, "aurora", "5.6.mysql_aurora.1.23.4"), Check: resource.ComposeTestCheckFunc( testAccCheckGlobalClusterExists(resourceName, &globalCluster1), ), }, { - Config: testAccGlobalClusterWithPrimaryEngineVersionConfig(rName, "aurora", "8.0.mysql_aurora.3.01.0"), - ExpectNonEmptyPlan: true, + Config: testAccGlobalClusterWithPrimaryEngineVersionConfig(rName, "aurora-mysql", "5.7.mysql_aurora.2.10.2"), Check: resource.ComposeTestCheckFunc( testAccCheckGlobalClusterExists(resourceName, &globalCluster2), testAccCheckGlobalClusterNotRecreated(&globalCluster1, &globalCluster2), - resource.TestCheckResourceAttr(resourceName, "engine_version", "8.0.mysql_aurora.3.01.0"), + resource.TestCheckResourceAttr(resourceName, "engine_version", "5.7.mysql_aurora.2.10.2"), ), }, { @@ -279,10 +278,10 @@ func TestAccRDSGlobalCluster_EngineVersion_auroraMySQL(t *testing.T) { CheckDestroy: testAccCheckGlobalClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccGlobalClusterEngineVersionConfig(rName, "aurora-mysql", "5.7.mysql_aurora.2.07.1"), + Config: testAccGlobalClusterEngineVersionConfig(rName, "aurora-mysql"), Check: resource.ComposeTestCheckFunc( testAccCheckGlobalClusterExists(resourceName, &globalCluster1), - resource.TestCheckResourceAttr(resourceName, "engine_version", "5.7.mysql_aurora.2.07.1"), + resource.TestCheckResourceAttrPair(resourceName, "engine_version", "data.aws_rds_engine_version.default", "version"), ), }, { @@ -306,10 +305,10 @@ func TestAccRDSGlobalCluster_EngineVersion_auroraPostgresql(t *testing.T) { CheckDestroy: testAccCheckGlobalClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccGlobalClusterEngineVersionConfig(rName, "aurora-postgresql", "10.11"), + Config: testAccGlobalClusterEngineVersionConfig(rName, "aurora-postgresql"), Check: resource.ComposeTestCheckFunc( testAccCheckGlobalClusterExists(resourceName, &globalCluster1), - resource.TestCheckResourceAttr(resourceName, "engine_version", "10.11"), + resource.TestCheckResourceAttrPair(resourceName, "engine_version", "data.aws_rds_engine_version.default", "version"), ), }, { @@ -564,35 +563,47 @@ resource "aws_rds_global_cluster" "test" { `, engine, rName) } -func testAccGlobalClusterEngineVersionConfig(rName, engine, engineVersion string) string { +func testAccGlobalClusterEngineVersionConfig(rName, engine string) string { return fmt.Sprintf(` +data "aws_rds_engine_version" "default" { + engine = %[1]q +} + resource "aws_rds_global_cluster" "test" { - engine = %[1]q - engine_version = %[2]q - global_cluster_identifier = %[3]q + engine = data.aws_rds_engine_version.default.engine + engine_version = data.aws_rds_engine_version.default.version + global_cluster_identifier = %[2]q } -`, engine, engineVersion, rName) +`, engine, rName) } func testAccGlobalClusterWithPrimaryEngineVersionConfig(rName, engine, engineVersion string) string { return fmt.Sprintf(` +data "aws_rds_orderable_db_instance" "test" { + engine = %[1]q + engine_version = %[2]q + preferred_instance_classes = ["db.r5.large", "db.r5.xlarge", "db.r6g.large"] # Aurora global db may be limited to rx +} + resource "aws_rds_global_cluster" "test" { - engine = %[1]q - engine_version = %[2]q + engine = data.aws_rds_orderable_db_instance.test.engine + engine_version = data.aws_rds_orderable_db_instance.test.engine_version global_cluster_identifier = %[3]q } +// checkout the newly working global cluster stuff in cluster + resource "aws_rds_cluster" "test" { apply_immediately = true allow_major_version_upgrade = true cluster_identifier = %[3]q - engine = %[1]q - engine_version = %[2]q + engine = data.aws_rds_orderable_db_instance.test.engine + engine_version = data.aws_rds_orderable_db_instance.test.engine_version master_password = "mustbeeightcharacters" master_username = "test" skip_final_snapshot = true - global_cluster_identifier = aws_rds_global_cluster.test.global_cluster_identifier + global_cluster_identifier = aws_rds_global_cluster.test.id lifecycle { ignore_changes = [global_cluster_identifier] @@ -602,10 +613,10 @@ resource "aws_rds_cluster" "test" { resource "aws_rds_cluster_instance" "test" { apply_immediately = true cluster_identifier = aws_rds_cluster.test.id - engine = %[1]q - engine_version = %[2]q + engine = data.aws_rds_orderable_db_instance.test.engine + engine_version = data.aws_rds_orderable_db_instance.test.engine_version identifier = %[3]q - instance_class = "db.r3.large" + instance_class = data.aws_rds_orderable_db_instance.test.instance_class lifecycle { ignore_changes = [engine_version] @@ -616,10 +627,14 @@ resource "aws_rds_cluster_instance" "test" { func testAccGlobalClusterSourceClusterIdentifierConfig(rName string) string { return fmt.Sprintf(` +data "aws_rds_engine_version" "default" { + engine = "aurora-postgresql" +} + resource "aws_rds_cluster" "test" { cluster_identifier = %[1]q - engine = "aurora-postgresql" - engine_version = "10.11" # Minimum supported version for Global Clusters + engine = data.aws_rds_engine_version.default.engine + engine_version = data.aws_rds_engine_version.default.version master_password = "mustbeeightcharacters" master_username = "test" skip_final_snapshot = true @@ -641,10 +656,14 @@ resource "aws_rds_global_cluster" "test" { func testAccGlobalClusterSourceClusterIdentifierStorageEncryptedConfig(rName string) string { return fmt.Sprintf(` +data "aws_rds_engine_version" "default" { + engine = "aurora-postgresql" +} + resource "aws_rds_cluster" "test" { cluster_identifier = %[1]q - engine = "aurora-postgresql" - engine_version = "10.11" # Minimum supported version for Global Clusters + engine = data.aws_rds_engine_version.default.engine + engine_version = data.aws_rds_engine_version.default.version master_password = "mustbeeightcharacters" master_username = "test" skip_final_snapshot = true diff --git a/internal/service/rds/instance_data_source_test.go b/internal/service/rds/instance_data_source_test.go index 832f18ae86e..bbedf381724 100644 --- a/internal/service/rds/instance_data_source_test.go +++ b/internal/service/rds/instance_data_source_test.go @@ -12,6 +12,7 @@ import ( func TestAccRDSInstanceDataSource_basic(t *testing.T) { rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + dataSourceName := "data.aws_db_instance.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -21,23 +22,23 @@ func TestAccRDSInstanceDataSource_basic(t *testing.T) { { Config: testAccInstanceDataSourceConfig(rName), Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttrSet("data.aws_db_instance.bar", "address"), - resource.TestCheckResourceAttrSet("data.aws_db_instance.bar", "allocated_storage"), - resource.TestCheckResourceAttrSet("data.aws_db_instance.bar", "auto_minor_version_upgrade"), - resource.TestCheckResourceAttrSet("data.aws_db_instance.bar", "db_instance_class"), - resource.TestCheckResourceAttrSet("data.aws_db_instance.bar", "db_name"), - resource.TestCheckResourceAttrSet("data.aws_db_instance.bar", "db_subnet_group"), - resource.TestCheckResourceAttrSet("data.aws_db_instance.bar", "endpoint"), - resource.TestCheckResourceAttrSet("data.aws_db_instance.bar", "engine"), - resource.TestCheckResourceAttrSet("data.aws_db_instance.bar", "hosted_zone_id"), - resource.TestCheckResourceAttrSet("data.aws_db_instance.bar", "master_username"), - resource.TestCheckResourceAttrSet("data.aws_db_instance.bar", "port"), - resource.TestCheckResourceAttrSet("data.aws_db_instance.bar", "multi_az"), - resource.TestCheckResourceAttrSet("data.aws_db_instance.bar", "enabled_cloudwatch_logs_exports.0"), - resource.TestCheckResourceAttrSet("data.aws_db_instance.bar", "enabled_cloudwatch_logs_exports.1"), - resource.TestCheckResourceAttrPair("data.aws_db_instance.bar", "resource_id", "aws_db_instance.bar", "resource_id"), - resource.TestCheckResourceAttrPair("data.aws_db_instance.bar", "tags.%", "aws_db_instance.bar", "tags.%"), - resource.TestCheckResourceAttrPair("data.aws_db_instance.bar", "tags.Environment", "aws_db_instance.bar", "tags.Environment"), + resource.TestCheckResourceAttrSet(dataSourceName, "address"), + resource.TestCheckResourceAttrSet(dataSourceName, "allocated_storage"), + resource.TestCheckResourceAttrSet(dataSourceName, "auto_minor_version_upgrade"), + resource.TestCheckResourceAttrSet(dataSourceName, "db_instance_class"), + resource.TestCheckResourceAttrSet(dataSourceName, "db_name"), + resource.TestCheckResourceAttrSet(dataSourceName, "db_subnet_group"), + resource.TestCheckResourceAttrSet(dataSourceName, "endpoint"), + resource.TestCheckResourceAttrSet(dataSourceName, "engine"), + resource.TestCheckResourceAttrSet(dataSourceName, "hosted_zone_id"), + resource.TestCheckResourceAttrSet(dataSourceName, "master_username"), + resource.TestCheckResourceAttrSet(dataSourceName, "port"), + resource.TestCheckResourceAttrSet(dataSourceName, "multi_az"), + resource.TestCheckResourceAttrSet(dataSourceName, "enabled_cloudwatch_logs_exports.0"), + resource.TestCheckResourceAttrSet(dataSourceName, "enabled_cloudwatch_logs_exports.1"), + resource.TestCheckResourceAttrPair(dataSourceName, "resource_id", "aws_db_instance.test", "resource_id"), + resource.TestCheckResourceAttrPair(dataSourceName, "tags.%", "aws_db_instance.test", "tags.%"), + resource.TestCheckResourceAttrPair(dataSourceName, "tags.Environment", "aws_db_instance.test", "tags.Environment"), ), }, }, @@ -46,6 +47,7 @@ func TestAccRDSInstanceDataSource_basic(t *testing.T) { func TestAccRDSInstanceDataSource_ec2Classic(t *testing.T) { rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + dataSourceName := "data.aws_db_instance.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t); acctest.PreCheckEC2Classic(t) }, @@ -55,7 +57,7 @@ func TestAccRDSInstanceDataSource_ec2Classic(t *testing.T) { { Config: testAccInstanceDataSourceConfig_ec2Classic(rName), Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("data.aws_db_instance.bar", "db_subnet_group", ""), + resource.TestCheckResourceAttr(dataSourceName, "db_subnet_group", ""), ), }, }, @@ -63,24 +65,47 @@ func TestAccRDSInstanceDataSource_ec2Classic(t *testing.T) { } func testAccInstanceDataSourceConfig(rName string) string { - return fmt.Sprintf(` -data "aws_rds_orderable_db_instance" "test" { - engine = "mariadb" - preferred_instance_classes = ["db.t3.micro", "db.t2.micro", "db.t3.small"] + return acctest.ConfigCompose( + testAccInstanceConfig_orderableClassMariadb(), + acctest.ConfigAvailableAZsNoOptIn(), + fmt.Sprintf(` +resource "aws_vpc" "test" { + cidr_block = "10.0.0.0/16" + + tags = { + Name = %[1]q + } } -resource "aws_db_instance" "bar" { - identifier = %[1]q +resource "aws_subnet" "test" { + count = 2 - allocated_storage = 10 - engine = data.aws_rds_orderable_db_instance.test.engine - instance_class = data.aws_rds_orderable_db_instance.test.instance_class - name = "baz" - password = "barbarbarbar" - username = "foo" + availability_zone = data.aws_availability_zones.available.names[count.index] + cidr_block = "10.0.${count.index}.0/24" + vpc_id = aws_vpc.test.id + tags = { + Name = %[1]q + } +} + +resource "aws_db_subnet_group" "test" { + name = %[1]q + subnet_ids = aws_subnet.test[*].id +} + +resource "aws_db_instance" "test" { + allocated_storage = 10 backup_retention_period = 0 + db_subnet_group_name = aws_db_subnet_group.test.name + engine = data.aws_rds_engine_version.default.engine + engine_version = data.aws_rds_engine_version.default.version + identifier = %[1]q + instance_class = data.aws_rds_orderable_db_instance.test.instance_class + name = "baz" + password = "barbarbarbar" skip_final_snapshot = true + username = "foo" enabled_cloudwatch_logs_exports = [ "audit", @@ -92,39 +117,45 @@ resource "aws_db_instance" "bar" { } } -data "aws_db_instance" "bar" { - db_instance_identifier = aws_db_instance.bar.identifier +data "aws_db_instance" "test" { + db_instance_identifier = aws_db_instance.test.identifier } -`, rName) +`, rName)) } func testAccInstanceDataSourceConfig_ec2Classic(rName string) string { return acctest.ConfigCompose( acctest.ConfigEC2ClassicRegionProvider(), fmt.Sprintf(` +data "aws_rds_engine_version" "default" { + engine = "mysql" +} + +# EC2-Classic specific data "aws_rds_orderable_db_instance" "test" { - engine = "mysql" - engine_version = "8.0.25" - preferred_instance_classes = ["db.t2.micro", "db.m3.medium", "db.m3.large", "db.r3.large"] + engine = data.aws_rds_engine_version.default.engine + engine_version = data.aws_rds_engine_version.default.version + preferred_instance_classes = ["db.m3.medium", "db.m3.large", "db.r3.large"] } -resource "aws_db_instance" "bar" { +resource "aws_db_instance" "test" { identifier = %[1]q allocated_storage = 10 engine = data.aws_rds_orderable_db_instance.test.engine engine_version = data.aws_rds_orderable_db_instance.test.engine_version instance_class = data.aws_rds_orderable_db_instance.test.instance_class - name = "baz" + storage_type = data.aws_rds_orderable_db_instance.test.storage_type + db_name = "baz" password = "barbarbarbar" username = "foo" publicly_accessible = true security_group_names = ["default"] - parameter_group_name = "default.mysql8.0" + parameter_group_name = "default.${data.aws_rds_engine_version.default.parameter_group_family}" skip_final_snapshot = true } -data "aws_db_instance" "bar" { - db_instance_identifier = aws_db_instance.bar.identifier +data "aws_db_instance" "test" { + db_instance_identifier = aws_db_instance.test.identifier } `, rName)) } diff --git a/internal/service/rds/wait.go b/internal/service/rds/wait.go index 2edd2eb0326..c55a9ac8399 100644 --- a/internal/service/rds/wait.go +++ b/internal/service/rds/wait.go @@ -54,12 +54,13 @@ func waitEventSubscriptionDeleted(conn *rds.RDS, id string, timeout time.Duratio func waitEventSubscriptionUpdated(conn *rds.RDS, id string, timeout time.Duration) (*rds.EventSubscription, error) { stateConf := &resource.StateChangeConf{ - Pending: []string{EventSubscriptionStatusModifying}, - Target: []string{EventSubscriptionStatusActive}, - Refresh: statusEventSubscription(conn, id), - Timeout: timeout, - MinTimeout: 10 * time.Second, - Delay: 30 * time.Second, + Pending: []string{EventSubscriptionStatusModifying}, + Target: []string{EventSubscriptionStatusActive}, + Refresh: statusEventSubscription(conn, id), + Timeout: timeout, + MinTimeout: 10 * time.Second, + Delay: 30 * time.Second, + ContinuousTargetOccurence: 2, } outputRaw, err := stateConf.WaitForState() From 904b06b8e3024b7baba618170f69df2a9fc95adf Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Thu, 10 Mar 2022 20:45:22 -0500 Subject: [PATCH 14/32] rds: Fix additional issues --- .changelog/23560.txt | 11 +++ internal/service/rds/cluster.go | 6 +- internal/service/rds/cluster_endpoint.go | 12 +-- internal/service/rds/global_cluster.go | 92 ++++++++++++------- internal/service/rds/global_cluster_test.go | 4 +- internal/service/rds/wait.go | 2 +- .../docs/r/rds_global_cluster.html.markdown | 9 ++ 7 files changed, 92 insertions(+), 44 deletions(-) create mode 100644 .changelog/23560.txt diff --git a/.changelog/23560.txt b/.changelog/23560.txt new file mode 100644 index 00000000000..ad9eaf3f32f --- /dev/null +++ b/.changelog/23560.txt @@ -0,0 +1,11 @@ +```release-note:bug +resource/aws_rds_event_subscription: Fix issue where `enabled` was sometimes not updated +``` + +```release-note:bug +resource/aws_db_instance: Fix issues where configured update timeout was not respected, and update would fail if instance were in the process of being configured. +``` + +```release-note:bug +resource/aws_rds_global_cluster: Fix in-place DB Cluster minor version upgrade error: "Invalid database cluster identifier" +``` \ No newline at end of file diff --git a/internal/service/rds/cluster.go b/internal/service/rds/cluster.go index 4836782c5bd..681a403b00b 100644 --- a/internal/service/rds/cluster.go +++ b/internal/service/rds/cluster.go @@ -990,7 +990,7 @@ func resourceClusterCreate(d *schema.ResourceData, meta interface{}) error { } log.Printf("[INFO] Waiting for RDS Cluster (%s) to be available", d.Id()) - err = waitForRDSClusterUpdate(conn, d.Id(), d.Timeout(schema.TimeoutCreate)) + err = waitForClusterUpdate(conn, d.Id(), d.Timeout(schema.TimeoutCreate)) if err != nil { return fmt.Errorf("error waiting for RDS Cluster (%s) to be available: %s", d.Id(), err) } @@ -1288,7 +1288,7 @@ func resourceClusterUpdate(d *schema.ResourceData, meta interface{}) error { } log.Printf("[INFO] Waiting for RDS Cluster (%s) to be available", d.Id()) - err = waitForRDSClusterUpdate(conn, d.Id(), d.Timeout(schema.TimeoutUpdate)) + err = waitForClusterUpdate(conn, d.Id(), d.Timeout(schema.TimeoutUpdate)) if err != nil { return fmt.Errorf("error waiting for RDS Cluster (%s) to be available: %s", d.Id(), err) } @@ -1506,7 +1506,7 @@ var resourceClusterUpdatePendingStates = []string{ "upgrading", } -func waitForRDSClusterUpdate(conn *rds.RDS, id string, timeout time.Duration) error { +func waitForClusterUpdate(conn *rds.RDS, id string, timeout time.Duration) error { stateConf := &resource.StateChangeConf{ Pending: resourceClusterUpdatePendingStates, Target: []string{"available"}, diff --git a/internal/service/rds/cluster_endpoint.go b/internal/service/rds/cluster_endpoint.go index 805303b1b1f..bdf9beed532 100644 --- a/internal/service/rds/cluster_endpoint.go +++ b/internal/service/rds/cluster_endpoint.go @@ -18,9 +18,9 @@ import ( ) const ( - AWSRDSClusterEndpointCreateTimeout = 30 * time.Minute - AWSRDSClusterEndpointRetryDelay = 5 * time.Second - ClusterEndpointRetryMinTimeout = 3 * time.Second + clusterEndpointCreateTimeout = 30 * time.Minute + clusterEndpointRetryDelay = 5 * time.Second + ClusterEndpointRetryMinTimeout = 3 * time.Second ) func ResourceClusterEndpoint() *schema.Resource { @@ -114,7 +114,7 @@ func resourceClusterEndpointCreate(d *schema.ResourceData, meta interface{}) err d.SetId(endpointId) - err = resourceClusterEndpointWaitForAvailable(AWSRDSClusterEndpointCreateTimeout, d.Id(), conn) + err = resourceClusterEndpointWaitForAvailable(clusterEndpointCreateTimeout, d.Id(), conn) if err != nil { return err } @@ -252,7 +252,7 @@ func resourceClusterEndpointWaitForDestroy(timeout time.Duration, id string, con Target: []string{"destroyed"}, Refresh: DBClusterEndpointStateRefreshFunc(conn, id), Timeout: timeout, - Delay: AWSRDSClusterEndpointRetryDelay, + Delay: clusterEndpointRetryDelay, MinTimeout: ClusterEndpointRetryMinTimeout, } _, err := stateConf.WaitForState() @@ -270,7 +270,7 @@ func resourceClusterEndpointWaitForAvailable(timeout time.Duration, id string, c Target: []string{"available"}, Refresh: DBClusterEndpointStateRefreshFunc(conn, id), Timeout: timeout, - Delay: AWSRDSClusterEndpointRetryDelay, + Delay: clusterEndpointRetryDelay, MinTimeout: ClusterEndpointRetryMinTimeout, } diff --git a/internal/service/rds/global_cluster.go b/internal/service/rds/global_cluster.go index 5032a90cb7b..994b8f2c46b 100644 --- a/internal/service/rds/global_cluster.go +++ b/internal/service/rds/global_cluster.go @@ -3,8 +3,10 @@ package rds import ( "fmt" "log" + "strings" "time" + "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/rds" "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" @@ -16,7 +18,9 @@ import ( ) const ( - rdsGlobalClusterRemovalTimeout = 2 * time.Minute + GlobalClusterRemovalTimeout = 30 * time.Minute + globalClusterCreateTimeout = 30 * time.Minute + globalClusterUpdateTimeout = 30 * time.Minute ) func ResourceGlobalCluster() *schema.Resource { @@ -29,6 +33,12 @@ func ResourceGlobalCluster() *schema.Resource { State: schema.ImportStatePassthrough, }, + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(globalClusterCreateTimeout), + Update: schema.DefaultTimeout(globalClusterUpdateTimeout), + Delete: schema.DefaultTimeout(GlobalClusterRemovalTimeout), + }, + Schema: map[string]*schema.Schema{ "arn": { Type: schema.TypeString, @@ -153,7 +163,7 @@ func resourceGlobalClusterCreate(d *schema.ResourceData, meta interface{}) error d.SetId(aws.StringValue(output.GlobalCluster.GlobalClusterIdentifier)) - if err := waitForGlobalClusterCreation(conn, d.Id()); err != nil { + if err := waitForGlobalClusterCreation(conn, d.Id(), d.Timeout(schema.TimeoutCreate)); err != nil { return fmt.Errorf("error waiting for RDS Global Cluster (%s) availability: %s", d.Id(), err) } @@ -213,7 +223,7 @@ func resourceGlobalClusterUpdate(d *schema.ResourceData, meta interface{}) error } if d.HasChange("engine_version") { - if err := resourceGlobalClusterUpgradeEngineVersion(d, conn); err != nil { + if err := globalClusterUpgradeEngineVersion(d, conn); err != nil { return err } } @@ -229,14 +239,14 @@ func resourceGlobalClusterUpdate(d *schema.ResourceData, meta interface{}) error return fmt.Errorf("error deleting RDS Global Cluster: %s", err) } - if err := waitForGlobalClusterUpdate(conn, d.Id()); err != nil { + if err := waitForGlobalClusterUpdate(conn, d.Id(), d.Timeout(schema.TimeoutUpdate)); err != nil { return fmt.Errorf("error waiting for RDS Global Cluster (%s) update: %s", d.Id(), err) } return resourceGlobalClusterRead(d, meta) } -func resourceGlobalClusterGetIdByARN(conn *rds.RDS, arn string) string { +func globalClusterGetIDByARN(conn *rds.RDS, arn string) string { result, err := conn.DescribeDBClusters(&rds.DescribeDBClustersInput{}) if err != nil { return "" @@ -281,7 +291,7 @@ func resourceGlobalClusterDelete(d *schema.ResourceData, meta interface{}) error return fmt.Errorf("error removing RDS DB Cluster (%s) from Global Cluster (%s): %w", dbClusterArn, d.Id(), err) } - if err := waitForGlobalClusterRemoval(conn, dbClusterArn); err != nil { + if err := waitForGlobalClusterRemoval(conn, dbClusterArn, d.Timeout(schema.TimeoutDelete)); err != nil { return fmt.Errorf("error waiting for RDS DB Cluster (%s) removal from RDS Global Cluster (%s): %w", dbClusterArn, d.Id(), err) } } @@ -295,7 +305,7 @@ func resourceGlobalClusterDelete(d *schema.ResourceData, meta interface{}) error // Allow for eventual consistency // InvalidGlobalClusterStateFault: Global Cluster arn:aws:rds::123456789012:global-cluster:tf-acc-test-5618525093076697001-0 is not empty - err := resource.Retry(1*time.Minute, func() *resource.RetryError { + err := resource.Retry(d.Timeout(schema.TimeoutDelete), func() *resource.RetryError { _, err := conn.DeleteGlobalCluster(input) if tfawserr.ErrMessageContains(err, rds.ErrCodeInvalidGlobalClusterStateFault, "is not empty") { @@ -321,7 +331,7 @@ func resourceGlobalClusterDelete(d *schema.ResourceData, meta interface{}) error return fmt.Errorf("error deleting RDS Global Cluster: %s", err) } - if err := WaitForGlobalClusterDeletion(conn, d.Id()); err != nil { + if err := WaitForGlobalClusterDeletion(conn, d.Id(), d.Timeout(schema.TimeoutDelete)); err != nil { return fmt.Errorf("error waiting for RDS Global Cluster (%s) deletion: %s", d.Id(), err) } @@ -414,7 +424,7 @@ func DescribeGlobalClusterFromClusterARN(conn *rds.RDS, dbClusterARN string) (*r return globalCluster, err } -func rdsGlobalClusterRefreshFunc(conn *rds.RDS, globalClusterID string) resource.StateRefreshFunc { +func globalClusterRefreshFunc(conn *rds.RDS, globalClusterID string) resource.StateRefreshFunc { return func() (interface{}, string, error) { globalCluster, err := DescribeGlobalCluster(conn, globalClusterID) @@ -434,12 +444,12 @@ func rdsGlobalClusterRefreshFunc(conn *rds.RDS, globalClusterID string) resource } } -func waitForGlobalClusterCreation(conn *rds.RDS, globalClusterID string) error { +func waitForGlobalClusterCreation(conn *rds.RDS, globalClusterID string, timeout time.Duration) error { stateConf := &resource.StateChangeConf{ Pending: []string{"creating"}, Target: []string{"available"}, - Refresh: rdsGlobalClusterRefreshFunc(conn, globalClusterID), - Timeout: 10 * time.Minute, + Refresh: globalClusterRefreshFunc(conn, globalClusterID), + Timeout: timeout, } log.Printf("[DEBUG] Waiting for RDS Global Cluster (%s) availability", globalClusterID) @@ -448,12 +458,12 @@ func waitForGlobalClusterCreation(conn *rds.RDS, globalClusterID string) error { return err } -func waitForGlobalClusterUpdate(conn *rds.RDS, globalClusterID string) error { +func waitForGlobalClusterUpdate(conn *rds.RDS, globalClusterID string, timeout time.Duration) error { stateConf := &resource.StateChangeConf{ Pending: []string{"modifying", "upgrading"}, Target: []string{"available"}, - Refresh: rdsGlobalClusterRefreshFunc(conn, globalClusterID), - Timeout: 10 * time.Minute, + Refresh: globalClusterRefreshFunc(conn, globalClusterID), + Timeout: timeout, Delay: 30 * time.Second, } @@ -463,15 +473,15 @@ func waitForGlobalClusterUpdate(conn *rds.RDS, globalClusterID string) error { return err } -func WaitForGlobalClusterDeletion(conn *rds.RDS, globalClusterID string) error { +func WaitForGlobalClusterDeletion(conn *rds.RDS, globalClusterID string, timeout time.Duration) error { stateConf := &resource.StateChangeConf{ Pending: []string{ "available", "deleting", }, Target: []string{"deleted"}, - Refresh: rdsGlobalClusterRefreshFunc(conn, globalClusterID), - Timeout: 10 * time.Minute, + Refresh: globalClusterRefreshFunc(conn, globalClusterID), + Timeout: timeout, NotFoundChecks: 1, } @@ -485,11 +495,11 @@ func WaitForGlobalClusterDeletion(conn *rds.RDS, globalClusterID string) error { return err } -func waitForGlobalClusterRemoval(conn *rds.RDS, dbClusterIdentifier string) error { +func waitForGlobalClusterRemoval(conn *rds.RDS, dbClusterIdentifier string, timeout time.Duration) error { var globalCluster *rds.GlobalCluster stillExistsErr := fmt.Errorf("RDS DB Cluster still exists in RDS Global Cluster") - err := resource.Retry(rdsGlobalClusterRemovalTimeout, func() *resource.RetryError { + err := resource.Retry(timeout, func() *resource.RetryError { var err error globalCluster, err = DescribeGlobalClusterFromClusterARN(conn, dbClusterIdentifier) @@ -520,13 +530,13 @@ func waitForGlobalClusterRemoval(conn *rds.RDS, dbClusterIdentifier string) erro return nil } -func resourceGlobalClusterUpgradeMajorEngineVersion(clusterId string, engineVersion string, conn *rds.RDS) error { +func globalClusterUpgradeMajorEngineVersion(clusterId string, engineVersion string, conn *rds.RDS) error { input := &rds.ModifyGlobalClusterInput{ GlobalClusterIdentifier: aws.String(clusterId), } input.AllowMajorVersionUpgrade = aws.Bool(true) input.EngineVersion = aws.String(engineVersion) - err := resource.Retry(rdsClusterInitiateUpgradeTimeout, func() *resource.RetryError { + err := resource.Retry(clusterInitiateUpgradeTimeout, func() *resource.RetryError { _, err := conn.ModifyGlobalCluster(input) if err != nil { if tfawserr.ErrCodeEquals(err, rds.ErrCodeGlobalClusterNotFoundFault) { @@ -547,26 +557,42 @@ func resourceGlobalClusterUpgradeMajorEngineVersion(clusterId string, engineVers return err } -func resourceGlobalClusterUpgradeMinorEngineVersion(clusterMembers *schema.Set, engineVersion string, conn *rds.RDS) error { +func globalClusterUpgradeMinorEngineVersion(clusterMembers *schema.Set, engineVersion string, conn *rds.RDS) error { for _, clusterMemberRaw := range clusterMembers.List() { clusterMember := clusterMemberRaw.(map[string]interface{}) + if clusterMemberArn, ok := clusterMember["db_cluster_arn"]; ok && clusterMemberArn.(string) != "" { + parsedARN, err := arn.Parse(clusterMemberArn.(string)) + + if err != nil { + return fmt.Errorf("could not parse ARN while upgrading RDS Global Cluster minor engine version: %w", err) + } + + dbi := "" + + if parsedARN.Resource != "" { + parts := strings.Split(parsedARN.Resource, ":") + + if len(parts) < 2 { + return fmt.Errorf("could not get DB Cluster ID from parsing ARN while upgrading RDS Global Cluster minor engine version: %w", err) + } + + dbi = parts[1] + } + modInput := &rds.ModifyDBClusterInput{ ApplyImmediately: aws.Bool(true), - DBClusterIdentifier: aws.String(clusterMemberArn.(string)), + DBClusterIdentifier: aws.String(dbi), EngineVersion: aws.String(engineVersion), } - err := resource.Retry(rdsClusterInitiateUpgradeTimeout, func() *resource.RetryError { + + err = resource.Retry(clusterInitiateUpgradeTimeout, func() *resource.RetryError { _, err := conn.ModifyDBCluster(modInput) if err != nil { if tfawserr.ErrMessageContains(err, "InvalidParameterValue", "IAM role ARN value is invalid or does not include the required permissions") { return resource.RetryableError(err) } - if tfawserr.ErrMessageContains(err, "InvalidParameterValue", "Invalid database cluster identifier") { - return resource.RetryableError(err) - } - if tfawserr.ErrMessageContains(err, rds.ErrCodeInvalidDBClusterStateFault, "Cannot modify engine version without a primary instance in DB cluster") { return resource.NonRetryableError(err) } @@ -592,11 +618,11 @@ func resourceGlobalClusterUpgradeMinorEngineVersion(clusterMembers *schema.Set, return nil } -func resourceGlobalClusterUpgradeEngineVersion(d *schema.ResourceData, conn *rds.RDS) error { +func globalClusterUpgradeEngineVersion(d *schema.ResourceData, conn *rds.RDS) error { log.Printf("[DEBUG] Upgrading RDS Global Cluster (%s) engine version: %s", d.Id(), d.Get("engine_version")) - err := resourceGlobalClusterUpgradeMajorEngineVersion(d.Id(), d.Get("engine_version").(string), conn) + err := globalClusterUpgradeMajorEngineVersion(d.Id(), d.Get("engine_version").(string), conn) if tfawserr.ErrMessageContains(err, "InvalidParameterValue", "ModifyGlobalCluster only supports Major Version Upgrades. To patch the members of your global cluster to a newer minor version you need to call ModifyDbCluster in each one of them.") { - err = resourceGlobalClusterUpgradeMinorEngineVersion(d.Get("global_cluster_members").(*schema.Set), d.Get("engine_version").(string), conn) + err = globalClusterUpgradeMinorEngineVersion(d.Get("global_cluster_members").(*schema.Set), d.Get("engine_version").(string), conn) if err != nil { return err } @@ -608,7 +634,7 @@ func resourceGlobalClusterUpgradeEngineVersion(d *schema.ResourceData, conn *rds return err } for _, clusterMember := range globalCluster.GlobalClusterMembers { - err := waitForRDSClusterUpdate(conn, resourceGlobalClusterGetIdByARN(conn, aws.StringValue(clusterMember.DBClusterArn)), d.Timeout(schema.TimeoutUpdate)) + err := waitForClusterUpdate(conn, globalClusterGetIDByARN(conn, aws.StringValue(clusterMember.DBClusterArn)), d.Timeout(schema.TimeoutUpdate)) if err != nil { return err } diff --git a/internal/service/rds/global_cluster_test.go b/internal/service/rds/global_cluster_test.go index db9c725e3f0..638ada23f4c 100644 --- a/internal/service/rds/global_cluster_test.go +++ b/internal/service/rds/global_cluster_test.go @@ -210,12 +210,14 @@ func TestAccRDSGlobalCluster_engineVersionUpdateMinor(t *testing.T) { CheckDestroy: testAccCheckGlobalClusterDestroy, Steps: []resource.TestStep{ { + //Config: testAccGlobalClusterWithPrimaryEngineVersionConfig(rName, "aurora", "5.6.mysql_aurora.1.22.2"), Config: testAccGlobalClusterWithPrimaryEngineVersionConfig(rName, "aurora-postgresql", "13.4"), Check: resource.ComposeTestCheckFunc( testAccCheckGlobalClusterExists(resourceName, &globalCluster1), ), }, { + //Config: testAccGlobalClusterWithPrimaryEngineVersionConfig(rName, "aurora", "5.6.mysql_aurora.1.23.2"), Config: testAccGlobalClusterWithPrimaryEngineVersionConfig(rName, "aurora-postgresql", "13.5"), Check: resource.ComposeTestCheckFunc( testAccCheckGlobalClusterExists(resourceName, &globalCluster2), @@ -488,7 +490,7 @@ func testAccCheckGlobalClusterDisappears(globalCluster *rds.GlobalCluster) resou return err } - return tfrds.WaitForGlobalClusterDeletion(conn, aws.StringValue(globalCluster.GlobalClusterIdentifier)) + return tfrds.WaitForGlobalClusterDeletion(conn, aws.StringValue(globalCluster.GlobalClusterIdentifier), tfrds.GlobalClusterRemovalTimeout) } } diff --git a/internal/service/rds/wait.go b/internal/service/rds/wait.go index c55a9ac8399..096fe77f506 100644 --- a/internal/service/rds/wait.go +++ b/internal/service/rds/wait.go @@ -8,7 +8,7 @@ import ( ) const ( - rdsClusterInitiateUpgradeTimeout = 5 * time.Minute + clusterInitiateUpgradeTimeout = 5 * time.Minute dbClusterRoleAssociationCreatedTimeout = 5 * time.Minute dbClusterRoleAssociationDeletedTimeout = 5 * time.Minute diff --git a/website/docs/r/rds_global_cluster.html.markdown b/website/docs/r/rds_global_cluster.html.markdown index 48aa664fd2e..ad39c887419 100644 --- a/website/docs/r/rds_global_cluster.html.markdown +++ b/website/docs/r/rds_global_cluster.html.markdown @@ -187,6 +187,15 @@ In addition to all arguments above, the following attributes are exported: * `global_cluster_resource_id` - AWS Region-unique, immutable identifier for the global database cluster. This identifier is found in AWS CloudTrail log entries whenever the AWS KMS key for the DB cluster is accessed * `id` - RDS Global Cluster identifier +## Timeouts + +`aws_rds_global_cluster` provides the following +[Timeouts](https://www.terraform.io/docs/configuration/blocks/resources/syntax.html#operation-timeouts) configuration options: + +- `create` - (Default `30 minutes`) +- `update` - (Default `30 minutes`) +- `delete` - (Default `30 minutes`) + ## Import `aws_rds_global_cluster` can be imported by using the RDS Global Cluster identifier, e.g., From 4fa0778196f4f339a2047053edf4bd0aaee19788 Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Thu, 10 Mar 2022 20:56:31 -0500 Subject: [PATCH 15/32] Update changelog --- .changelog/23560.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.changelog/23560.txt b/.changelog/23560.txt index ad9eaf3f32f..681fa41670f 100644 --- a/.changelog/23560.txt +++ b/.changelog/23560.txt @@ -8,4 +8,8 @@ resource/aws_db_instance: Fix issues where configured update timeout was not res ```release-note:bug resource/aws_rds_global_cluster: Fix in-place DB Cluster minor version upgrade error: "Invalid database cluster identifier" -``` \ No newline at end of file +``` + +```release-note:enhancement +resource/aws_rds_global_cluster: Add configurable timeouts +``` From 23bfced1578e24ed6174452e6eb5e274cd364165 Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Thu, 10 Mar 2022 21:18:12 -0500 Subject: [PATCH 16/32] Add session to client --- internal/conns/conns.go | 2 + internal/service/rds/global_cluster_test.go | 103 +++++++++++++++++++- internal/service/rds/sweep.go | 2 +- 3 files changed, 103 insertions(+), 4 deletions(-) diff --git a/internal/conns/conns.go b/internal/conns/conns.go index e0658523a0b..db3f008434a 100644 --- a/internal/conns/conns.go +++ b/internal/conns/conns.go @@ -1141,6 +1141,7 @@ type AWSClient struct { ServiceDiscoveryConn *servicediscovery.ServiceDiscovery ServiceQuotasConn *servicequotas.ServiceQuotas SESConn *ses.SES + Session *session.Session SESV2Conn *sesv2.SESV2 SFNConn *sfn.SFN ShieldConn *shield.Shield @@ -1540,6 +1541,7 @@ func (c *Config) Client(ctx context.Context) (interface{}, diag.Diagnostics) { ServiceQuotasConn: servicequotas.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints[ServiceQuotas])})), SESConn: ses.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints[SES])})), SESV2Conn: sesv2.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints[SESV2])})), + Session: sess, SFNConn: sfn.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints[SFN])})), SignerConn: signer.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints[Signer])})), SimpleDBConn: simpledb.New(sess.Copy(&aws.Config{Endpoint: aws.String(c.Endpoints[SimpleDB])})), diff --git a/internal/service/rds/global_cluster_test.go b/internal/service/rds/global_cluster_test.go index 638ada23f4c..4ab1dd98861 100644 --- a/internal/service/rds/global_cluster_test.go +++ b/internal/service/rds/global_cluster_test.go @@ -11,6 +11,7 @@ import ( "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" sdkacctest "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" "github.com/hashicorp/terraform-provider-aws/internal/acctest" "github.com/hashicorp/terraform-provider-aws/internal/conns" @@ -198,7 +199,7 @@ func TestAccRDSGlobalCluster_EngineVersion_aurora(t *testing.T) { }) } -func TestAccRDSGlobalCluster_engineVersionUpdateMinor(t *testing.T) { +func TestAccRDSGlobalCluster_EngineVersion_updateMinor(t *testing.T) { var globalCluster1, globalCluster2 rds.GlobalCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_rds_global_cluster.test" @@ -234,7 +235,7 @@ func TestAccRDSGlobalCluster_engineVersionUpdateMinor(t *testing.T) { }) } -func TestAccRDSGlobalCluster_engineVersionUpdateMajor(t *testing.T) { +func TestAccRDSGlobalCluster_EngineVersion_updateMajor(t *testing.T) { var globalCluster1, globalCluster2 rds.GlobalCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_rds_global_cluster.test" @@ -268,6 +269,36 @@ func TestAccRDSGlobalCluster_engineVersionUpdateMajor(t *testing.T) { }) } +func TestAccRDSGlobalCluster_EngineVersion_updateMinorMultiRegion(t *testing.T) { + var providers []*schema.Provider + var globalCluster1, globalCluster2 rds.GlobalCluster + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_rds_global_cluster.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(t); testAccPreCheckGlobalCluster(t) }, + ErrorCheck: acctest.ErrorCheck(t, rds.EndpointsID), + ProviderFactories: acctest.FactoriesAlternate(&providers), + CheckDestroy: testAccCheckGlobalClusterDestroy, + Steps: []resource.TestStep{ + { + Config: testAccGlobalClusterEngineVersionUpgradeMultiRegionConfig(rName, "aurora", "5.6.mysql_aurora.1.22.2"), + Check: resource.ComposeTestCheckFunc( + testAccCheckGlobalClusterExists(resourceName, &globalCluster1), + ), + }, + { + Config: testAccGlobalClusterEngineVersionUpgradeMultiRegionConfig(rName, "aurora", "5.6.mysql_aurora.1.23.2"), + Check: resource.ComposeTestCheckFunc( + testAccCheckGlobalClusterExists(resourceName, &globalCluster2), + testAccCheckGlobalClusterNotRecreated(&globalCluster1, &globalCluster2), + resource.TestCheckResourceAttr(resourceName, "engine_version", "5.6.mysql_aurora.1.23.2"), + ), + }, + }, + }) +} + func TestAccRDSGlobalCluster_EngineVersion_auroraMySQL(t *testing.T) { var globalCluster1 rds.GlobalCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -295,7 +326,7 @@ func TestAccRDSGlobalCluster_EngineVersion_auroraMySQL(t *testing.T) { }) } -func TestAccRDSGlobalCluster_EngineVersion_auroraPostgresql(t *testing.T) { +func TestAccRDSGlobalCluster_EngineVersion_auroraPostgreSQL(t *testing.T) { var globalCluster1 rds.GlobalCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_rds_global_cluster.test" @@ -627,6 +658,72 @@ resource "aws_rds_cluster_instance" "test" { `, engine, engineVersion, rName) } +func testAccGlobalClusterEngineVersionUpgradeMultiRegionConfig(rName, engine, engineVersion string) string { + return acctest.ConfigCompose( + acctest.ConfigAlternateRegionProvider(), + fmt.Sprintf(` +resource "aws_rds_global_cluster" "test" { + engine = %[1]q + engine_version = %[2]q + global_cluster_identifier = %[3]q +} + +resource "aws_rds_cluster" "test" { + allow_major_version_upgrade = true + apply_immediately = true + cluster_identifier = %[3]q + database_name = "totoro" + engine = aws_rds_global_cluster.test.engine + engine_version = aws_rds_global_cluster.test.engine_version + global_cluster_identifier = aws_rds_global_cluster.test.global_cluster_identifier + master_password = "mustbeeightcharacters" + master_username = "test" + skip_final_snapshot = true + + lifecycle { + ignore_changes = [global_cluster_identifier] + } +} + +resource "aws_rds_cluster_instance" "test" { + apply_immediately = true + cluster_identifier = aws_rds_cluster.test.id + engine = aws_rds_global_cluster.test.engine + engine_version = aws_rds_global_cluster.test.engine_version + identifier = %[3]q + instance_class = "db.r3.large" +} + +resource "aws_rds_cluster" "test2" { + provider = "awsalternate" + + allow_major_version_upgrade = true + apply_immediately = true + cluster_identifier = "%[3]s-2" + engine = %[1]q + engine_version = %[2]q + global_cluster_identifier = aws_rds_global_cluster.test.global_cluster_identifier + replication_source_identifier = aws_rds_cluster.test.arn + skip_final_snapshot = true + + lifecycle { + ignore_changes = [global_cluster_identifier] + } +} + +resource "aws_rds_cluster_instance" "test2" { + provider = "awsalternate" + + apply_immediately = true + cluster_identifier = aws_rds_cluster.test2.id + engine = %[1]q + engine_version = %[2]q + identifier = "%[3]s-2" + instance_class = "db.r3.large" +} +`, engine, engineVersion, rName)) +} + func testAccGlobalClusterSourceClusterIdentifierConfig(rName string) string { return fmt.Sprintf(` data "aws_rds_engine_version" "default" { diff --git a/internal/service/rds/sweep.go b/internal/service/rds/sweep.go index 8997ecea70e..7af82b991bf 100644 --- a/internal/service/rds/sweep.go +++ b/internal/service/rds/sweep.go @@ -346,7 +346,7 @@ func sweepGlobalClusters(region string) error { continue } - if err := WaitForGlobalClusterDeletion(conn, id); err != nil { + if err := WaitForGlobalClusterDeletion(conn, id, 30*time.Minute); err != nil { log.Printf("[ERROR] Failure while waiting for RDS Global Cluster (%s) to be deleted: %s", id, err) } } From eadfece0a2e09d3ad405885b703521f7814304a6 Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Thu, 10 Mar 2022 21:46:28 -0500 Subject: [PATCH 17/32] Glint in your eye --- internal/service/rds/global_cluster.go | 30 +++++++++++++++------ internal/service/rds/global_cluster_test.go | 2 +- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/internal/service/rds/global_cluster.go b/internal/service/rds/global_cluster.go index 994b8f2c46b..2d2b4165bb6 100644 --- a/internal/service/rds/global_cluster.go +++ b/internal/service/rds/global_cluster.go @@ -223,7 +223,7 @@ func resourceGlobalClusterUpdate(d *schema.ResourceData, meta interface{}) error } if d.HasChange("engine_version") { - if err := globalClusterUpgradeEngineVersion(d, conn); err != nil { + if err := globalClusterUpgradeEngineVersion(d, meta); err != nil { return err } } @@ -530,7 +530,7 @@ func waitForGlobalClusterRemoval(conn *rds.RDS, dbClusterIdentifier string, time return nil } -func globalClusterUpgradeMajorEngineVersion(clusterId string, engineVersion string, conn *rds.RDS) error { +func globalClusterUpgradeMajorEngineVersion(conn *rds.RDS, clusterId string, engineVersion string) error { input := &rds.ModifyGlobalClusterInput{ GlobalClusterIdentifier: aws.String(clusterId), } @@ -557,7 +557,9 @@ func globalClusterUpgradeMajorEngineVersion(clusterId string, engineVersion stri return err } -func globalClusterUpgradeMinorEngineVersion(clusterMembers *schema.Set, engineVersion string, conn *rds.RDS) error { +func globalClusterUpgradeMinorEngineVersion(meta interface{}, clusterMembers *schema.Set, engineVersion string) error { + conn := meta.(*conns.AWSClient).RDSConn + for _, clusterMemberRaw := range clusterMembers.List() { clusterMember := clusterMemberRaw.(map[string]interface{}) @@ -569,6 +571,10 @@ func globalClusterUpgradeMinorEngineVersion(clusterMembers *schema.Set, engineVe } dbi := "" + useConn := conn + + // DBClusterIdentifier supposedly can be either ARN or ID, and both used to work, + // but as of now, only ID works if parsedARN.Resource != "" { parts := strings.Split(parsedARN.Resource, ":") @@ -580,6 +586,10 @@ func globalClusterUpgradeMinorEngineVersion(clusterMembers *schema.Set, engineVe dbi = parts[1] } + if parsedARN.Region != meta.(*conns.AWSClient).Region { + useConn = rds.New(meta.(*conns.AWSClient).Session, aws.NewConfig().WithRegion(parsedARN.Region)) + } + modInput := &rds.ModifyDBClusterInput{ ApplyImmediately: aws.Bool(true), DBClusterIdentifier: aws.String(dbi), @@ -587,7 +597,7 @@ func globalClusterUpgradeMinorEngineVersion(clusterMembers *schema.Set, engineVe } err = resource.Retry(clusterInitiateUpgradeTimeout, func() *resource.RetryError { - _, err := conn.ModifyDBCluster(modInput) + _, err := useConn.ModifyDBCluster(modInput) if err != nil { if tfawserr.ErrMessageContains(err, "InvalidParameterValue", "IAM role ARN value is invalid or does not include the required permissions") { return resource.RetryableError(err) @@ -604,12 +614,14 @@ func globalClusterUpgradeMinorEngineVersion(clusterMembers *schema.Set, engineVe } return nil }) + if tfresource.TimedOut(err) { - _, err := conn.ModifyDBCluster(modInput) + _, err := useConn.ModifyDBCluster(modInput) if err != nil { return err } } + if err != nil { return fmt.Errorf("failed to update engine_version on RDS Global Cluster member (%s): %s", clusterMemberArn, err) } @@ -618,11 +630,13 @@ func globalClusterUpgradeMinorEngineVersion(clusterMembers *schema.Set, engineVe return nil } -func globalClusterUpgradeEngineVersion(d *schema.ResourceData, conn *rds.RDS) error { +func globalClusterUpgradeEngineVersion(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*conns.AWSClient).RDSConn + log.Printf("[DEBUG] Upgrading RDS Global Cluster (%s) engine version: %s", d.Id(), d.Get("engine_version")) - err := globalClusterUpgradeMajorEngineVersion(d.Id(), d.Get("engine_version").(string), conn) + err := globalClusterUpgradeMajorEngineVersion(conn, d.Id(), d.Get("engine_version").(string)) if tfawserr.ErrMessageContains(err, "InvalidParameterValue", "ModifyGlobalCluster only supports Major Version Upgrades. To patch the members of your global cluster to a newer minor version you need to call ModifyDbCluster in each one of them.") { - err = globalClusterUpgradeMinorEngineVersion(d.Get("global_cluster_members").(*schema.Set), d.Get("engine_version").(string), conn) + err = globalClusterUpgradeMinorEngineVersion(meta, d.Get("global_cluster_members").(*schema.Set), d.Get("engine_version").(string)) if err != nil { return err } diff --git a/internal/service/rds/global_cluster_test.go b/internal/service/rds/global_cluster_test.go index 4ab1dd98861..2da19aa07e9 100644 --- a/internal/service/rds/global_cluster_test.go +++ b/internal/service/rds/global_cluster_test.go @@ -708,7 +708,7 @@ resource "aws_rds_cluster" "test2" { lifecycle { ignore_changes = [global_cluster_identifier] - } + } } resource "aws_rds_cluster_instance" "test2" { From ab96f11e7441c6263afb24bb3f48bc4841bdd661 Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Fri, 11 Mar 2022 08:59:39 -0500 Subject: [PATCH 18/32] Remove bad comment --- internal/service/rds/global_cluster_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/internal/service/rds/global_cluster_test.go b/internal/service/rds/global_cluster_test.go index 2da19aa07e9..d73d82f8883 100644 --- a/internal/service/rds/global_cluster_test.go +++ b/internal/service/rds/global_cluster_test.go @@ -624,8 +624,6 @@ resource "aws_rds_global_cluster" "test" { global_cluster_identifier = %[3]q } -// checkout the newly working global cluster stuff in cluster - resource "aws_rds_cluster" "test" { apply_immediately = true allow_major_version_upgrade = true From 1f4c4b4ae31b8608f8025dca9d8fbb32c0029013 Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Sat, 12 Mar 2022 21:40:08 -0500 Subject: [PATCH 19/32] rds_global_cluster: Fix upgrade capability --- internal/service/rds/cluster.go | 5 +- internal/service/rds/global_cluster.go | 255 ++++++++++++++------ internal/service/rds/global_cluster_test.go | 222 ++++++++++++++--- internal/service/rds/wait.go | 2 +- 4 files changed, 368 insertions(+), 116 deletions(-) diff --git a/internal/service/rds/cluster.go b/internal/service/rds/cluster.go index 681a403b00b..b6c459a00ef 100644 --- a/internal/service/rds/cluster.go +++ b/internal/service/rds/cluster.go @@ -139,6 +139,7 @@ func ResourceCluster() *schema.Resource { "global_cluster_identifier": { Type: schema.TypeString, Optional: true, + Computed: true, }, "enable_global_write_forwarding": { @@ -953,8 +954,7 @@ func resourceClusterCreate(d *schema.ResourceData, meta interface{}) error { log.Printf("[INFO] RDS Cluster ID: %s", d.Id()) - log.Println( - "[INFO] Waiting for RDS Cluster to be available") + log.Println("[INFO] Waiting for RDS Cluster to be available") stateConf := &resource.StateChangeConf{ Pending: resourceClusterCreatePendingStates, @@ -1515,6 +1515,7 @@ func waitForClusterUpdate(conn *rds.RDS, id string, timeout time.Duration) error MinTimeout: 10 * time.Second, Delay: 30 * time.Second, // Wait 30 secs before starting } + _, err := stateConf.WaitForState() return err } diff --git a/internal/service/rds/global_cluster.go b/internal/service/rds/global_cluster.go index 2d2b4165bb6..ed8a62e9554 100644 --- a/internal/service/rds/global_cluster.go +++ b/internal/service/rds/global_cluster.go @@ -8,6 +8,7 @@ import ( "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/endpoints" "github.com/aws/aws-sdk-go/service/rds" "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" @@ -20,7 +21,7 @@ import ( const ( GlobalClusterRemovalTimeout = 30 * time.Minute globalClusterCreateTimeout = 30 * time.Minute - globalClusterUpdateTimeout = 30 * time.Minute + globalClusterUpdateTimeout = 5 * time.Minute ) func ResourceGlobalCluster() *schema.Resource { @@ -246,19 +247,6 @@ func resourceGlobalClusterUpdate(d *schema.ResourceData, meta interface{}) error return resourceGlobalClusterRead(d, meta) } -func globalClusterGetIDByARN(conn *rds.RDS, arn string) string { - result, err := conn.DescribeDBClusters(&rds.DescribeDBClustersInput{}) - if err != nil { - return "" - } - for _, cluster := range result.DBClusters { - if aws.StringValue(cluster.DBClusterArn) == arn { - return aws.StringValue(cluster.DBClusterIdentifier) - } - } - return "" -} - func resourceGlobalClusterDelete(d *schema.ResourceData, meta interface{}) error { conn := meta.(*conns.AWSClient).RDSConn @@ -444,6 +432,32 @@ func globalClusterRefreshFunc(conn *rds.RDS, globalClusterID string) resource.St } } +func globalClusterVersionRefreshFunc(conn *rds.RDS, globalClusterID string) resource.StateRefreshFunc { + return func() (interface{}, string, error) { + globalCluster, err := DescribeGlobalCluster(conn, globalClusterID) + + if tfawserr.ErrCodeEquals(err, rds.ErrCodeGlobalClusterNotFoundFault) { + return nil, "deleted", nil + } + + if err != nil { + return nil, "", fmt.Errorf("error reading RDS Global Cluster (%s): %s", globalClusterID, err) + } + + if globalCluster == nil { + return nil, "deleted", nil + } + + status := aws.StringValue(globalCluster.Status) + + if status == rds.CustomEngineVersionStatusAvailable { + status = aws.StringValue(globalCluster.EngineVersion) + } + + return globalCluster, status, nil + } +} + func waitForGlobalClusterCreation(conn *rds.RDS, globalClusterID string, timeout time.Duration) error { stateConf := &resource.StateChangeConf{ Pending: []string{"creating"}, @@ -473,6 +487,21 @@ func waitForGlobalClusterUpdate(conn *rds.RDS, globalClusterID string, timeout t return err } +func waitForGlobalClusterVersionUpdate(conn *rds.RDS, globalClusterID, version string, timeout time.Duration) error { + stateConf := &resource.StateChangeConf{ + Pending: []string{"modifying", "upgrading"}, + Target: []string{version}, + Refresh: globalClusterVersionRefreshFunc(conn, globalClusterID), + Timeout: timeout, + Delay: 30 * time.Second, + } + + log.Printf("[DEBUG] Waiting for RDS Global Cluster (%s) version sync", globalClusterID) + _, err := stateConf.WaitForState() + + return err +} + func WaitForGlobalClusterDeletion(conn *rds.RDS, globalClusterID string, timeout time.Duration) error { stateConf := &resource.StateChangeConf{ Pending: []string{ @@ -530,18 +559,24 @@ func waitForGlobalClusterRemoval(conn *rds.RDS, dbClusterIdentifier string, time return nil } -func globalClusterUpgradeMajorEngineVersion(conn *rds.RDS, clusterId string, engineVersion string) error { +func globalClusterUpgradeMajorEngineVersion(meta interface{}, clusterId string, engineVersion string) error { + conn := meta.(*conns.AWSClient).RDSConn + input := &rds.ModifyGlobalClusterInput{ GlobalClusterIdentifier: aws.String(clusterId), } + input.AllowMajorVersionUpgrade = aws.Bool(true) input.EngineVersion = aws.String(engineVersion) + err := resource.Retry(clusterInitiateUpgradeTimeout, func() *resource.RetryError { _, err := conn.ModifyGlobalCluster(input) + if err != nil { if tfawserr.ErrCodeEquals(err, rds.ErrCodeGlobalClusterNotFoundFault) { return resource.NonRetryableError(err) } + if tfawserr.ErrMessageContains(err, "InvalidParameterValue", "ModifyGlobalCluster only supports Major Version Upgrades. To patch the members of your global cluster to a newer minor version you need to call ModifyDbCluster in each one of them.") { return resource.NonRetryableError(err) } @@ -551,107 +586,177 @@ func globalClusterUpgradeMajorEngineVersion(conn *rds.RDS, clusterId string, eng return nil }) + if tfresource.TimedOut(err) { _, err = conn.ModifyGlobalCluster(input) } + + if err != nil { + return fmt.Errorf("while upgrading major version of RDS Global Cluster (%s): %w", clusterId, err) + } + + globalCluster, err := DescribeGlobalCluster(conn, clusterId) + + if err != nil { + return fmt.Errorf("while upgrading major version of RDS Global Cluster (%s): %w", clusterId, err) + } + + for _, clusterMember := range globalCluster.GlobalClusterMembers { + arnID := aws.StringValue(clusterMember.DBClusterArn) + + if arnID == "" { + continue + } + + dbi, clusterRegion, err := ClusterIDRegionFromARN(arnID) + + if err != nil { + return fmt.Errorf("while upgrading RDS Global Cluster Cluster minor engine version: %w", err) + } + + if dbi == "" { + continue + } + + useConn := conn // clusters may not all be in the same region + + if clusterRegion != meta.(*conns.AWSClient).Region { + useConn = rds.New(meta.(*conns.AWSClient).Session, aws.NewConfig().WithRegion(clusterRegion)) + } + + if err := waitForClusterUpdate(useConn, dbi, clusterInitiateUpgradeTimeout); err != nil { + return fmt.Errorf("failed to update engine_version, waiting for RDS Global Cluster (%s) to update: %s", dbi, err) + } + } + return err } -func globalClusterUpgradeMinorEngineVersion(meta interface{}, clusterMembers *schema.Set, engineVersion string) error { +func ClusterIDRegionFromARN(arnID string) (string, string, error) { + parsedARN, err := arn.Parse(arnID) + + if err != nil { + return "", "", fmt.Errorf("could not parse ARN (%s): %w", arnID, err) + } + + dbi := "" + + if parsedARN.Resource != "" { + parts := strings.Split(parsedARN.Resource, ":") + + if len(parts) < 2 { + return "", "", fmt.Errorf("could not get DB Cluster ID from parsing ARN (%s): %w", arnID, err) + } + + if parsedARN.Service != endpoints.RdsServiceID || parts[0] != "cluster" { + return "", "", fmt.Errorf("wrong ARN (%s) for a DB Cluster", arnID) + } + + dbi = parts[1] + } + + return dbi, parsedARN.Region, nil +} + +func globalClusterUpgradeMinorEngineVersion(meta interface{}, clusterMembers *schema.Set, clusterID, engineVersion string) error { conn := meta.(*conns.AWSClient).RDSConn for _, clusterMemberRaw := range clusterMembers.List() { clusterMember := clusterMemberRaw.(map[string]interface{}) - if clusterMemberArn, ok := clusterMember["db_cluster_arn"]; ok && clusterMemberArn.(string) != "" { - parsedARN, err := arn.Parse(clusterMemberArn.(string)) - - if err != nil { - return fmt.Errorf("could not parse ARN while upgrading RDS Global Cluster minor engine version: %w", err) - } + // DBClusterIdentifier supposedly can be either ARN or ID, and both used to work, + // but as of now, only ID works + if clusterMemberArn, ok := clusterMember["db_cluster_arn"]; !ok || clusterMemberArn.(string) == "" { + continue + } - dbi := "" - useConn := conn + arnID := clusterMember["db_cluster_arn"].(string) - // DBClusterIdentifier supposedly can be either ARN or ID, and both used to work, - // but as of now, only ID works + dbi, clusterRegion, err := ClusterIDRegionFromARN(arnID) - if parsedARN.Resource != "" { - parts := strings.Split(parsedARN.Resource, ":") + if err != nil { + return fmt.Errorf("while upgrading RDS Global Cluster Cluster minor engine version: %w", err) + } - if len(parts) < 2 { - return fmt.Errorf("could not get DB Cluster ID from parsing ARN while upgrading RDS Global Cluster minor engine version: %w", err) - } + if dbi == "" { + continue + } - dbi = parts[1] - } + useConn := conn - if parsedARN.Region != meta.(*conns.AWSClient).Region { - useConn = rds.New(meta.(*conns.AWSClient).Session, aws.NewConfig().WithRegion(parsedARN.Region)) - } + if clusterRegion != meta.(*conns.AWSClient).Region { + useConn = rds.New(meta.(*conns.AWSClient).Session, aws.NewConfig().WithRegion(clusterRegion)) + } - modInput := &rds.ModifyDBClusterInput{ - ApplyImmediately: aws.Bool(true), - DBClusterIdentifier: aws.String(dbi), - EngineVersion: aws.String(engineVersion), - } + modInput := &rds.ModifyDBClusterInput{ + ApplyImmediately: aws.Bool(true), + DBClusterIdentifier: aws.String(dbi), + EngineVersion: aws.String(engineVersion), + } - err = resource.Retry(clusterInitiateUpgradeTimeout, func() *resource.RetryError { - _, err := useConn.ModifyDBCluster(modInput) - if err != nil { - if tfawserr.ErrMessageContains(err, "InvalidParameterValue", "IAM role ARN value is invalid or does not include the required permissions") { - return resource.RetryableError(err) - } + err = resource.Retry(clusterInitiateUpgradeTimeout, func() *resource.RetryError { + _, err := useConn.ModifyDBCluster(modInput) - if tfawserr.ErrMessageContains(err, rds.ErrCodeInvalidDBClusterStateFault, "Cannot modify engine version without a primary instance in DB cluster") { - return resource.NonRetryableError(err) - } + if err != nil { + if tfawserr.ErrMessageContains(err, "InvalidParameterValue", "IAM role ARN value is invalid or does not include the required permissions") { + return resource.RetryableError(err) + } - if tfawserr.ErrCodeEquals(err, rds.ErrCodeInvalidDBClusterStateFault) { - return resource.RetryableError(err) - } + if tfawserr.ErrMessageContains(err, rds.ErrCodeInvalidDBClusterStateFault, "Cannot modify engine version without a primary instance in DB cluster") { return resource.NonRetryableError(err) } - return nil - }) - if tfresource.TimedOut(err) { - _, err := useConn.ModifyDBCluster(modInput) - if err != nil { - return err + if tfawserr.ErrCodeEquals(err, rds.ErrCodeInvalidDBClusterStateFault) { + return resource.RetryableError(err) } + + return resource.NonRetryableError(err) } + return nil + }) + + if tfresource.TimedOut(err) { + _, err := useConn.ModifyDBCluster(modInput) if err != nil { - return fmt.Errorf("failed to update engine_version on RDS Global Cluster member (%s): %s", clusterMemberArn, err) + return err } } + + if err != nil { + return fmt.Errorf("failed to update engine_version on RDS Global Cluster Cluster (%s): %s", dbi, err) + } + + if err := waitForClusterUpdate(useConn, dbi, clusterInitiateUpgradeTimeout); err != nil { + return fmt.Errorf("failed to update engine_version, waiting for RDS Global Cluster Cluster (%s) to update: %s", dbi, err) + } + } + + if err := waitForGlobalClusterVersionUpdate(conn, clusterID, engineVersion, clusterInitiateUpgradeTimeout); err != nil { + return fmt.Errorf("failed to update engine_version, waiting for RDS Global Cluster (%s) to update: %s", clusterID, err) } + return nil } func globalClusterUpgradeEngineVersion(d *schema.ResourceData, meta interface{}) error { - conn := meta.(*conns.AWSClient).RDSConn - log.Printf("[DEBUG] Upgrading RDS Global Cluster (%s) engine version: %s", d.Id(), d.Get("engine_version")) - err := globalClusterUpgradeMajorEngineVersion(conn, d.Id(), d.Get("engine_version").(string)) + + err := globalClusterUpgradeMajorEngineVersion(meta, d.Id(), d.Get("engine_version").(string)) + if tfawserr.ErrMessageContains(err, "InvalidParameterValue", "ModifyGlobalCluster only supports Major Version Upgrades. To patch the members of your global cluster to a newer minor version you need to call ModifyDbCluster in each one of them.") { - err = globalClusterUpgradeMinorEngineVersion(meta, d.Get("global_cluster_members").(*schema.Set), d.Get("engine_version").(string)) + err = globalClusterUpgradeMinorEngineVersion(meta, d.Get("global_cluster_members").(*schema.Set), d.Id(), d.Get("engine_version").(string)) + if err != nil { - return err + return fmt.Errorf("while upgrading minor version of RDS Global Cluster (%s): %w", d.Id(), err) } - } else if err != nil { - return err + + return nil } - globalCluster, err := DescribeGlobalCluster(conn, d.Id()) + if err != nil { - return err - } - for _, clusterMember := range globalCluster.GlobalClusterMembers { - err := waitForClusterUpdate(conn, globalClusterGetIDByARN(conn, aws.StringValue(clusterMember.DBClusterArn)), d.Timeout(schema.TimeoutUpdate)) - if err != nil { - return err - } + return fmt.Errorf("while upgrading major version of RDS Global Cluster (%s): %w", d.Id(), err) } + return nil } diff --git a/internal/service/rds/global_cluster_test.go b/internal/service/rds/global_cluster_test.go index d73d82f8883..71674e82c96 100644 --- a/internal/service/rds/global_cluster_test.go +++ b/internal/service/rds/global_cluster_test.go @@ -18,6 +18,77 @@ import ( tfrds "github.com/hashicorp/terraform-provider-aws/internal/service/rds" ) +func TestClusterIDRegionFromARN(t *testing.T) { + testCases := []struct { + TestName string + Input string + ExpectedID string + ExpectedRegion string + ExpectedErr bool + }{ + { + TestName: "empty", + Input: "", + ExpectedID: "", + ExpectedRegion: "", + ExpectedErr: true, + }, + { + TestName: "normal ARN", + Input: "arn:aws:rds:us-west-2:012345678901:cluster:tf-acc-test-1467354933239945971", + ExpectedID: "tf-acc-test-1467354933239945971", + ExpectedRegion: "us-west-2", + ExpectedErr: false, + }, + { + TestName: "another good ARN", + Input: "arn:aws:rds:us-east-1:012345678901:cluster:tf-acc-test-1467354933239945971", + ExpectedID: "tf-acc-test-1467354933239945971", + ExpectedRegion: "us-east-1", + ExpectedErr: false, + }, + { + TestName: "no account", + Input: "arn:aws:rds:us-east-2::cluster:tf-acc-test-1467354933239945971", + ExpectedID: "tf-acc-test-1467354933239945971", + ExpectedRegion: "us-east-2", + ExpectedErr: false, + }, + { + TestName: "wrong service", + Input: "arn:aws:connect:us-west-2:012345678901:instance/1032bdc4-d72c-5490-a9fa-3c9b4dba67bb", + ExpectedID: "", + ExpectedRegion: "", + ExpectedErr: true, + }, + { + TestName: "wrong resource", + Input: "arn:aws:rds:us-east-2::notacluster:tf-acc-test-1467354933239945971", + ExpectedID: "", + ExpectedRegion: "", + ExpectedErr: true, + }, + } + + for _, testCase := range testCases { + t.Run(testCase.TestName, func(t *testing.T) { + gotID, gotRegion, gotErr := tfrds.ClusterIDRegionFromARN(testCase.Input) + + if gotErr != nil && !testCase.ExpectedErr { + t.Errorf("got no error, expected one: %s", testCase.Input) + } + + if gotID != testCase.ExpectedID { + t.Errorf("got %s, expected %s", gotID, testCase.ExpectedID) + } + + if gotRegion != testCase.ExpectedRegion { + t.Errorf("got %s, expected %s", gotRegion, testCase.ExpectedRegion) + } + }) + } +} + func TestAccRDSGlobalCluster_basic(t *testing.T) { var globalCluster1 rds.GlobalCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -272,7 +343,9 @@ func TestAccRDSGlobalCluster_EngineVersion_updateMajor(t *testing.T) { func TestAccRDSGlobalCluster_EngineVersion_updateMinorMultiRegion(t *testing.T) { var providers []*schema.Provider var globalCluster1, globalCluster2 rds.GlobalCluster - rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + rNameGlobal := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) // don't need to be unique but makes debugging easier + rNamePrimary := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + rNameSecondary := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_rds_global_cluster.test" resource.ParallelTest(t, resource.TestCase{ @@ -282,17 +355,49 @@ func TestAccRDSGlobalCluster_EngineVersion_updateMinorMultiRegion(t *testing.T) CheckDestroy: testAccCheckGlobalClusterDestroy, Steps: []resource.TestStep{ { - Config: testAccGlobalClusterEngineVersionUpgradeMultiRegionConfig(rName, "aurora", "5.6.mysql_aurora.1.22.2"), + Config: testAccGlobalClusterEngineVersionUpgradeMultiRegionConfig(rNameGlobal, rNamePrimary, rNameSecondary, "aurora-mysql", "5.7.mysql_aurora.2.07.5"), Check: resource.ComposeTestCheckFunc( testAccCheckGlobalClusterExists(resourceName, &globalCluster1), ), }, { - Config: testAccGlobalClusterEngineVersionUpgradeMultiRegionConfig(rName, "aurora", "5.6.mysql_aurora.1.23.2"), + Config: testAccGlobalClusterEngineVersionUpgradeMultiRegionConfig(rNameGlobal, rNamePrimary, rNameSecondary, "aurora-mysql", "5.7.mysql_aurora.2.07.7"), Check: resource.ComposeTestCheckFunc( testAccCheckGlobalClusterExists(resourceName, &globalCluster2), testAccCheckGlobalClusterNotRecreated(&globalCluster1, &globalCluster2), - resource.TestCheckResourceAttr(resourceName, "engine_version", "5.6.mysql_aurora.1.23.2"), + resource.TestCheckResourceAttr(resourceName, "engine_version", "5.7.mysql_aurora.2.07.7"), + ), + }, + }, + }) +} + +func TestAccRDSGlobalCluster_EngineVersion_updateMajorMultiRegion(t *testing.T) { + var providers []*schema.Provider + var globalCluster1, globalCluster2 rds.GlobalCluster + rNameGlobal := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) // don't need to be unique but makes debugging easier + rNamePrimary := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + rNameSecondary := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_rds_global_cluster.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(t); testAccPreCheckGlobalCluster(t) }, + ErrorCheck: acctest.ErrorCheck(t, rds.EndpointsID), + ProviderFactories: acctest.FactoriesAlternate(&providers), + CheckDestroy: testAccCheckGlobalClusterDestroy, + Steps: []resource.TestStep{ + { + Config: testAccGlobalClusterEngineVersionUpgradeMultiRegionConfig(rNameGlobal, rNamePrimary, rNameSecondary, "aurora", "5.6.mysql_aurora.1.23.4"), + Check: resource.ComposeTestCheckFunc( + testAccCheckGlobalClusterExists(resourceName, &globalCluster1), + ), + }, + { + Config: testAccGlobalClusterEngineVersionUpgradeMultiRegionConfig(rNameGlobal, rNamePrimary, rNameSecondary, "aurora-mysql", "5.7.mysql_aurora.2.10.2"), + Check: resource.ComposeTestCheckFunc( + testAccCheckGlobalClusterExists(resourceName, &globalCluster2), + testAccCheckGlobalClusterNotRecreated(&globalCluster1, &globalCluster2), + resource.TestCheckResourceAttr(resourceName, "engine_version", "5.7.mysql_aurora.2.10.2"), ), }, }, @@ -656,70 +761,111 @@ resource "aws_rds_cluster_instance" "test" { `, engine, engineVersion, rName) } -func testAccGlobalClusterEngineVersionUpgradeMultiRegionConfig(rName, engine, engineVersion string) string { +func testAccGlobalClusterEngineVersionUpgradeMultiRegionConfig(rNameGlobal, rNamePrimary, rNameSecondary, engine, engineVersion string) string { return acctest.ConfigCompose( - acctest.ConfigAlternateRegionProvider(), + acctest.ConfigMultipleRegionProvider(2), fmt.Sprintf(` +data "aws_region" "current" {} + +data "aws_availability_zones" "alternate" { + provider = "awsalternate" + state = "available" + + filter { + name = "opt-in-status" + values = ["opt-in-not-required"] + } +} + resource "aws_rds_global_cluster" "test" { - engine = %[1]q - engine_version = %[2]q - global_cluster_identifier = %[3]q + global_cluster_identifier = %[1]q + engine = %[2]q + engine_version = %[3]q } -resource "aws_rds_cluster" "test" { +resource "aws_rds_cluster" "primary" { allow_major_version_upgrade = true apply_immediately = true - cluster_identifier = %[3]q + cluster_identifier = %[4]q database_name = "totoro" engine = aws_rds_global_cluster.test.engine engine_version = aws_rds_global_cluster.test.engine_version - global_cluster_identifier = aws_rds_global_cluster.test.global_cluster_identifier - master_password = "mustbeeightcharacters" - master_username = "test" + global_cluster_identifier = aws_rds_global_cluster.test.id + master_password = "satsukimae" + master_username = "maesatsuki" skip_final_snapshot = true lifecycle { - ignore_changes = [global_cluster_identifier] + ignore_changes = [engine_version] } } -resource "aws_rds_cluster_instance" "test" { +resource "aws_rds_cluster_instance" "primary" { apply_immediately = true - cluster_identifier = aws_rds_cluster.test.id - engine = aws_rds_global_cluster.test.engine - engine_version = aws_rds_global_cluster.test.engine_version - identifier = %[3]q - instance_class = "db.r3.large" + cluster_identifier = aws_rds_cluster.primary.id + engine = aws_rds_cluster.primary.engine + engine_version = aws_rds_cluster.primary.engine_version + identifier = %[4]q + instance_class = "db.r4.large" } -resource "aws_rds_cluster" "test2" { - provider = "awsalternate" +resource "aws_vpc" "alternate" { + provider = "awsalternate" + cidr_block = "10.0.0.0/16" + + tags = { + Name = %[5]q + } +} + +resource "aws_subnet" "alternate" { + provider = "awsalternate" + count = 3 + vpc_id = aws_vpc.alternate.id + availability_zone = data.aws_availability_zones.alternate.names[count.index] + cidr_block = "10.0.${count.index}.0/24" + tags = { + Name = %[5]q + } +} + +resource "aws_db_subnet_group" "alternate" { + provider = "awsalternate" + name = %[5]q + subnet_ids = aws_subnet.alternate[*].id +} + +resource "aws_rds_cluster" "secondary" { + provider = "awsalternate" allow_major_version_upgrade = true apply_immediately = true - cluster_identifier = "%[3]s-2" - engine = %[1]q - engine_version = %[2]q - global_cluster_identifier = aws_rds_global_cluster.test.global_cluster_identifier - replication_source_identifier = aws_rds_cluster.test.arn + cluster_identifier = %[5]q + engine = aws_rds_global_cluster.test.engine + engine_version = aws_rds_global_cluster.test.engine_version + global_cluster_identifier = aws_rds_global_cluster.test.id skip_final_snapshot = true lifecycle { - ignore_changes = [global_cluster_identifier] + ignore_changes = [ + replication_source_identifier, + engine_version, + ] } -} -resource "aws_rds_cluster_instance" "test2" { - provider = "awsalternate" + depends_on = [aws_rds_cluster_instance.primary] +} +resource "aws_rds_cluster_instance" "secondary" { + provider = "awsalternate" apply_immediately = true - cluster_identifier = aws_rds_cluster.test2.id - engine = %[1]q - engine_version = %[2]q - identifier = "%[3]s-2" - instance_class = "db.r3.large" + cluster_identifier = aws_rds_cluster.secondary.id + engine = aws_rds_cluster.secondary.engine + engine_version = aws_rds_cluster.secondary.engine_version + identifier = %[5]q + instance_class = "db.r4.large" } -`, engine, engineVersion, rName)) +`, rNameGlobal, engine, engineVersion, rNamePrimary, rNameSecondary)) } func testAccGlobalClusterSourceClusterIdentifierConfig(rName string) string { diff --git a/internal/service/rds/wait.go b/internal/service/rds/wait.go index 096fe77f506..2450b406f6a 100644 --- a/internal/service/rds/wait.go +++ b/internal/service/rds/wait.go @@ -8,7 +8,7 @@ import ( ) const ( - clusterInitiateUpgradeTimeout = 5 * time.Minute + clusterInitiateUpgradeTimeout = 30 * time.Minute dbClusterRoleAssociationCreatedTimeout = 5 * time.Minute dbClusterRoleAssociationDeletedTimeout = 5 * time.Minute From dc7e520af8fae2156a51fe0bbcc7410de1f0e69a Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Sat, 12 Mar 2022 21:42:24 -0500 Subject: [PATCH 20/32] Update changelog --- .changelog/23560.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changelog/23560.txt b/.changelog/23560.txt index 681fa41670f..167ba9437ae 100644 --- a/.changelog/23560.txt +++ b/.changelog/23560.txt @@ -7,7 +7,7 @@ resource/aws_db_instance: Fix issues where configured update timeout was not res ``` ```release-note:bug -resource/aws_rds_global_cluster: Fix in-place DB Cluster minor version upgrade error: "Invalid database cluster identifier" +resource/aws_rds_global_cluster: Fix ability to perform DB Cluster minor version upgrades of clusters in distinct regions, including error: "Invalid database cluster identifier" ``` ```release-note:enhancement From 35947129fbf421f3428652fe75197b3a18cd55fa Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Sat, 12 Mar 2022 22:12:58 -0500 Subject: [PATCH 21/32] Fix waiter error --- internal/service/rds/global_cluster.go | 6 +-- .../docs/r/rds_global_cluster.html.markdown | 43 +++++++++++++++++-- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/internal/service/rds/global_cluster.go b/internal/service/rds/global_cluster.go index ed8a62e9554..2df05f605fd 100644 --- a/internal/service/rds/global_cluster.go +++ b/internal/service/rds/global_cluster.go @@ -432,7 +432,7 @@ func globalClusterRefreshFunc(conn *rds.RDS, globalClusterID string) resource.St } } -func globalClusterVersionRefreshFunc(conn *rds.RDS, globalClusterID string) resource.StateRefreshFunc { +func globalClusterVersionRefreshFunc(conn *rds.RDS, globalClusterID, engineVersion string) resource.StateRefreshFunc { return func() (interface{}, string, error) { globalCluster, err := DescribeGlobalCluster(conn, globalClusterID) @@ -450,7 +450,7 @@ func globalClusterVersionRefreshFunc(conn *rds.RDS, globalClusterID string) reso status := aws.StringValue(globalCluster.Status) - if status == rds.CustomEngineVersionStatusAvailable { + if status == rds.CustomEngineVersionStatusAvailable && aws.StringValue(globalCluster.EngineVersion) == engineVersion { status = aws.StringValue(globalCluster.EngineVersion) } @@ -491,7 +491,7 @@ func waitForGlobalClusterVersionUpdate(conn *rds.RDS, globalClusterID, version s stateConf := &resource.StateChangeConf{ Pending: []string{"modifying", "upgrading"}, Target: []string{version}, - Refresh: globalClusterVersionRefreshFunc(conn, globalClusterID), + Refresh: globalClusterVersionRefreshFunc(conn, globalClusterID, version), Timeout: timeout, Delay: 30 * time.Second, } diff --git a/website/docs/r/rds_global_cluster.html.markdown b/website/docs/r/rds_global_cluster.html.markdown index ad39c887419..7ce3e88701b 100644 --- a/website/docs/r/rds_global_cluster.html.markdown +++ b/website/docs/r/rds_global_cluster.html.markdown @@ -162,16 +162,53 @@ resource "aws_rds_global_cluster" "example" { } ``` +### Upgrading Engine Versions + +When you upgrade the version of an `aws_rds_global_cluster`, Terraform will attempt to in-place upgrade the engine versions of all associated clusters. Since the `aws_rds_cluster` resource is being updated through the `aws_rds_global_cluster`, you are likely to get an error (`Provider produced inconsistent final plan`). To avoid this, use the `lifecycle` `ignore_changes` meta argument as shown below. + +```terraform +resource "aws_rds_global_cluster" "example" { + global_cluster_identifier = "kyivkharkiv" + engine = "aurora-mysql" + engine_version = "5.7.mysql_aurora.2.07.5" +} + +resource "aws_rds_cluster" "primary" { + allow_major_version_upgrade = true + apply_immediately = true + cluster_identifier = "odessadnipro" + database_name = "totoro" + engine = aws_rds_global_cluster.example.engine + engine_version = aws_rds_global_cluster.example.engine_version + global_cluster_identifier = aws_rds_global_cluster.example.id + master_password = "satsukimae" + master_username = "maesatsuki" + skip_final_snapshot = true + + lifecycle { + ignore_changes = [engine_version] + } +} + +resource "aws_rds_cluster_instance" "primary" { + apply_immediately = true + cluster_identifier = aws_rds_cluster.primary.id + engine = aws_rds_cluster.primary.engine + engine_version = aws_rds_cluster.primary.engine_version + identifier = "donetsklviv" + instance_class = "db.r4.large" +} +``` + ## Argument Reference The following arguments are supported: -* `global_cluster_identifier` - (Required, Forces new resources) The global cluster identifier. +* `global_cluster_identifier` - (Required, Forces new resources) Global cluster identifier. * `database_name` - (Optional, Forces new resources) Name for an automatically created database on cluster creation. * `deletion_protection` - (Optional) If the Global Cluster should have deletion protection enabled. The database can't be deleted when this value is set to `true`. The default is `false`. * `engine` - (Optional, Forces new resources) Name of the database engine to be used for this DB cluster. Terraform will only perform drift detection if a configuration value is provided. Valid values: `aurora`, `aurora-mysql`, `aurora-postgresql`. Defaults to `aurora`. Conflicts with `source_db_cluster_identifier`. -* `engine_version` - (Optional) Engine version of the Aurora global database. Upgrading the engine version will result in all cluster members being immediately updated. - * **NOTE:** When the engine is set to `aurora-mysql`, an engine version compatible with global database is required. The earliest available version is `5.7.mysql_aurora.2.06.0`. +* `engine_version` - (Optional) Engine version of the Aurora global database. The `engine`, `engine_version`, and `instance_class` (on the `aws_rds_cluster_instance`) must together support global databases. See [Using Amazon Aurora global databases](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/aurora-global-database.html) for more information. By upgrading the engine version, Terraform will upgrade cluster members. **NOTE:** To avoid an `inconsistent final plan` error while upgrading, use the `lifecycle` `ignore_changes` for `engine_version` meta argument on the associated `aws_rds_cluster` resource as shown above in [Upgrading Engine Versions](#upgrading-engine-versions) example. * `force_destroy` - (Optional) Enable to remove DB Cluster members from Global Cluster on destroy. Required with `source_db_cluster_identifier`. * `source_db_cluster_identifier` - (Optional) Amazon Resource Name (ARN) to use as the primary DB Cluster of the Global Cluster on creation. Terraform cannot perform drift detection of this value. * `storage_encrypted` - (Optional, Forces new resources) Specifies whether the DB cluster is encrypted. The default is `false` unless `source_db_cluster_identifier` is specified and encrypted. Terraform will only perform drift detection if a configuration value is provided. From 23299c8a33f769cf7c7d289dd2d57d81daba0a35 Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Sat, 12 Mar 2022 22:19:05 -0500 Subject: [PATCH 22/32] Update changelog --- .changelog/23560.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changelog/23560.txt b/.changelog/23560.txt index 167ba9437ae..b6c3749f681 100644 --- a/.changelog/23560.txt +++ b/.changelog/23560.txt @@ -7,7 +7,7 @@ resource/aws_db_instance: Fix issues where configured update timeout was not res ``` ```release-note:bug -resource/aws_rds_global_cluster: Fix ability to perform DB Cluster minor version upgrades of clusters in distinct regions, including error: "Invalid database cluster identifier" +resource/aws_rds_global_cluster: Fix ability to perform cluster version upgrades, including of clusters in distinct regions, such as error: "Invalid database cluster identifier" ``` ```release-note:enhancement From 9ca642bb9ba62274bc84b8b06b6e023c27369a0b Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Sat, 12 Mar 2022 22:20:22 -0500 Subject: [PATCH 23/32] Update changelog --- .changelog/23560.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changelog/23560.txt b/.changelog/23560.txt index b6c3749f681..5787a897152 100644 --- a/.changelog/23560.txt +++ b/.changelog/23560.txt @@ -7,7 +7,7 @@ resource/aws_db_instance: Fix issues where configured update timeout was not res ``` ```release-note:bug -resource/aws_rds_global_cluster: Fix ability to perform cluster version upgrades, including of clusters in distinct regions, such as error: "Invalid database cluster identifier" +resource/aws_rds_global_cluster: Fix ability to perform cluster version upgrades, including of clusters in distinct regions, such as previously got error: "Invalid database cluster identifier" ``` ```release-note:enhancement From 910f0e36ee6cbf78a98db07d9af6d7ce2f988a36 Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Sat, 12 Mar 2022 22:23:22 -0500 Subject: [PATCH 24/32] rds_cluster: Restore to original schema --- internal/service/rds/cluster.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/service/rds/cluster.go b/internal/service/rds/cluster.go index b6c459a00ef..32084974fe2 100644 --- a/internal/service/rds/cluster.go +++ b/internal/service/rds/cluster.go @@ -139,7 +139,6 @@ func ResourceCluster() *schema.Resource { "global_cluster_identifier": { Type: schema.TypeString, Optional: true, - Computed: true, }, "enable_global_write_forwarding": { From 9963e7b7dab820f6b05c090bc778a32fc027ce0f Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Sat, 12 Mar 2022 22:25:07 -0500 Subject: [PATCH 25/32] rds_global_cluster: Fix timeout --- internal/service/rds/global_cluster.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/rds/global_cluster.go b/internal/service/rds/global_cluster.go index 2df05f605fd..934b4fb00c0 100644 --- a/internal/service/rds/global_cluster.go +++ b/internal/service/rds/global_cluster.go @@ -21,7 +21,7 @@ import ( const ( GlobalClusterRemovalTimeout = 30 * time.Minute globalClusterCreateTimeout = 30 * time.Minute - globalClusterUpdateTimeout = 5 * time.Minute + globalClusterUpdateTimeout = 30 * time.Minute ) func ResourceGlobalCluster() *schema.Resource { From d888392caf9717b112b7987c23db09a43ce56050 Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Mon, 14 Mar 2022 12:24:15 -0400 Subject: [PATCH 26/32] rds_global_cluster: Finally --- internal/service/rds/global_cluster.go | 38 ++++++++++++++----- .../docs/r/rds_global_cluster.html.markdown | 2 +- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/internal/service/rds/global_cluster.go b/internal/service/rds/global_cluster.go index 934b4fb00c0..f019af4e942 100644 --- a/internal/service/rds/global_cluster.go +++ b/internal/service/rds/global_cluster.go @@ -21,7 +21,7 @@ import ( const ( GlobalClusterRemovalTimeout = 30 * time.Minute globalClusterCreateTimeout = 30 * time.Minute - globalClusterUpdateTimeout = 30 * time.Minute + globalClusterUpdateTimeout = 60 * time.Minute ) func ResourceGlobalCluster() *schema.Resource { @@ -489,7 +489,7 @@ func waitForGlobalClusterUpdate(conn *rds.RDS, globalClusterID string, timeout t func waitForGlobalClusterVersionUpdate(conn *rds.RDS, globalClusterID, version string, timeout time.Duration) error { stateConf := &resource.StateChangeConf{ - Pending: []string{"modifying", "upgrading"}, + Pending: []string{"modifying", "upgrading", "available"}, Target: []string{version}, Refresh: globalClusterVersionRefreshFunc(conn, globalClusterID, version), Timeout: timeout, @@ -559,11 +559,11 @@ func waitForGlobalClusterRemoval(conn *rds.RDS, dbClusterIdentifier string, time return nil } -func globalClusterUpgradeMajorEngineVersion(meta interface{}, clusterId string, engineVersion string) error { +func globalClusterUpgradeMajorEngineVersion(meta interface{}, clusterID string, engineVersion string) error { conn := meta.(*conns.AWSClient).RDSConn input := &rds.ModifyGlobalClusterInput{ - GlobalClusterIdentifier: aws.String(clusterId), + GlobalClusterIdentifier: aws.String(clusterID), } input.AllowMajorVersionUpgrade = aws.Bool(true) @@ -592,13 +592,13 @@ func globalClusterUpgradeMajorEngineVersion(meta interface{}, clusterId string, } if err != nil { - return fmt.Errorf("while upgrading major version of RDS Global Cluster (%s): %w", clusterId, err) + return fmt.Errorf("while upgrading major version of RDS Global Cluster (%s): %w", clusterID, err) } - globalCluster, err := DescribeGlobalCluster(conn, clusterId) + globalCluster, err := DescribeGlobalCluster(conn, clusterID) if err != nil { - return fmt.Errorf("while upgrading major version of RDS Global Cluster (%s): %w", clusterId, err) + return fmt.Errorf("while upgrading major version of RDS Global Cluster (%s): %w", clusterID, err) } for _, clusterMember := range globalCluster.GlobalClusterMembers { @@ -661,6 +661,8 @@ func ClusterIDRegionFromARN(arnID string) (string, string, error) { func globalClusterUpgradeMinorEngineVersion(meta interface{}, clusterMembers *schema.Set, clusterID, engineVersion string) error { conn := meta.(*conns.AWSClient).RDSConn + log.Printf("[INFO] Performing RDS Global Cluster (%s) minor version (%s) upgrade", clusterID, engineVersion) + for _, clusterMemberRaw := range clusterMembers.List() { clusterMember := clusterMemberRaw.(map[string]interface{}) @@ -694,6 +696,8 @@ func globalClusterUpgradeMinorEngineVersion(meta interface{}, clusterMembers *sc EngineVersion: aws.String(engineVersion), } + log.Printf("[INFO] Performing RDS Global Cluster (%s) Cluster (%s) minor version (%s) upgrade", clusterID, dbi, engineVersion) + err = resource.Retry(clusterInitiateUpgradeTimeout, func() *resource.RetryError { _, err := useConn.ModifyDBCluster(modInput) @@ -727,13 +731,29 @@ func globalClusterUpgradeMinorEngineVersion(meta interface{}, clusterMembers *sc return fmt.Errorf("failed to update engine_version on RDS Global Cluster Cluster (%s): %s", dbi, err) } + log.Printf("[INFO] Waiting for RDS Global Cluster (%s) Cluster (%s) minor version (%s) upgrade", clusterID, dbi, engineVersion) if err := waitForClusterUpdate(useConn, dbi, clusterInitiateUpgradeTimeout); err != nil { return fmt.Errorf("failed to update engine_version, waiting for RDS Global Cluster Cluster (%s) to update: %s", dbi, err) } } - if err := waitForGlobalClusterVersionUpdate(conn, clusterID, engineVersion, clusterInitiateUpgradeTimeout); err != nil { - return fmt.Errorf("failed to update engine_version, waiting for RDS Global Cluster (%s) to update: %s", clusterID, err) + globalCluster, err := DescribeGlobalCluster(conn, clusterID) + + if tfawserr.ErrCodeEquals(err, rds.ErrCodeGlobalClusterNotFoundFault) { + return fmt.Errorf("after upgrading engine_version, could not find RDS Global Cluster (%s): %s", clusterID, err) + } + + if err != nil { + return fmt.Errorf("after minor engine_version upgrade to RDS Global Cluster (%s): %s", clusterID, err) + } + + if globalCluster == nil { + return fmt.Errorf("after minor engine_version upgrade to RDS Global Cluster (%s): empty response", clusterID) + } + + if aws.StringValue(globalCluster.EngineVersion) != engineVersion { + log.Printf("[DEBUG] RDS Global Cluster (%s) upgrade did not take effect, trying again", clusterID) + return globalClusterUpgradeMinorEngineVersion(meta, clusterMembers, clusterID, engineVersion) } return nil diff --git a/website/docs/r/rds_global_cluster.html.markdown b/website/docs/r/rds_global_cluster.html.markdown index 7ce3e88701b..ccb51211999 100644 --- a/website/docs/r/rds_global_cluster.html.markdown +++ b/website/docs/r/rds_global_cluster.html.markdown @@ -164,7 +164,7 @@ resource "aws_rds_global_cluster" "example" { ### Upgrading Engine Versions -When you upgrade the version of an `aws_rds_global_cluster`, Terraform will attempt to in-place upgrade the engine versions of all associated clusters. Since the `aws_rds_cluster` resource is being updated through the `aws_rds_global_cluster`, you are likely to get an error (`Provider produced inconsistent final plan`). To avoid this, use the `lifecycle` `ignore_changes` meta argument as shown below. +When you upgrade the version of an `aws_rds_global_cluster`, Terraform will attempt to in-place upgrade the engine versions of all associated clusters. Since the `aws_rds_cluster` resource is being updated through the `aws_rds_global_cluster`, you are likely to get an error (`Provider produced inconsistent final plan`). To avoid this, use the `lifecycle` `ignore_changes` meta argument as shown below on the `aws_rds_cluster`. ```terraform resource "aws_rds_global_cluster" "example" { From 86acf3385db8e7bd40274589306bb8102cdef9cc Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Mon, 14 Mar 2022 12:49:41 -0400 Subject: [PATCH 27/32] Linted windows --- internal/service/rds/global_cluster_test.go | 26 ++++++++++----------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/internal/service/rds/global_cluster_test.go b/internal/service/rds/global_cluster_test.go index 71674e82c96..c87bfd42b79 100644 --- a/internal/service/rds/global_cluster_test.go +++ b/internal/service/rds/global_cluster_test.go @@ -35,35 +35,35 @@ func TestClusterIDRegionFromARN(t *testing.T) { }, { TestName: "normal ARN", - Input: "arn:aws:rds:us-west-2:012345678901:cluster:tf-acc-test-1467354933239945971", + Input: "arn:aws:rds:us-west-2:012345678901:cluster:tf-acc-test-1467354933239945971", // lintignore:AWSAT003,AWSAT005 ExpectedID: "tf-acc-test-1467354933239945971", ExpectedRegion: "us-west-2", ExpectedErr: false, }, { TestName: "another good ARN", - Input: "arn:aws:rds:us-east-1:012345678901:cluster:tf-acc-test-1467354933239945971", + Input: "arn:aws:rds:us-east-1:012345678901:cluster:tf-acc-test-1467354933239945971", // lintignore:AWSAT003,AWSAT005 ExpectedID: "tf-acc-test-1467354933239945971", ExpectedRegion: "us-east-1", ExpectedErr: false, }, { TestName: "no account", - Input: "arn:aws:rds:us-east-2::cluster:tf-acc-test-1467354933239945971", + Input: "arn:aws:rds:us-east-2::cluster:tf-acc-test-1467354933239945971", // lintignore:AWSAT003,AWSAT005 ExpectedID: "tf-acc-test-1467354933239945971", ExpectedRegion: "us-east-2", ExpectedErr: false, }, { TestName: "wrong service", - Input: "arn:aws:connect:us-west-2:012345678901:instance/1032bdc4-d72c-5490-a9fa-3c9b4dba67bb", + Input: "arn:aws:connect:us-west-2:012345678901:instance/1032bdc4-d72c-5490-a9fa-3c9b4dba67bb", // lintignore:AWSAT003,AWSAT005 ExpectedID: "", ExpectedRegion: "", ExpectedErr: true, }, { TestName: "wrong resource", - Input: "arn:aws:rds:us-east-2::notacluster:tf-acc-test-1467354933239945971", + Input: "arn:aws:rds:us-east-2::notacluster:tf-acc-test-1467354933239945971", // lintignore:AWSAT003,AWSAT005 ExpectedID: "", ExpectedRegion: "", ExpectedErr: true, @@ -837,14 +837,14 @@ resource "aws_db_subnet_group" "alternate" { } resource "aws_rds_cluster" "secondary" { - provider = "awsalternate" - allow_major_version_upgrade = true - apply_immediately = true - cluster_identifier = %[5]q - engine = aws_rds_global_cluster.test.engine - engine_version = aws_rds_global_cluster.test.engine_version - global_cluster_identifier = aws_rds_global_cluster.test.id - skip_final_snapshot = true + provider = "awsalternate" + allow_major_version_upgrade = true + apply_immediately = true + cluster_identifier = %[5]q + engine = aws_rds_global_cluster.test.engine + engine_version = aws_rds_global_cluster.test.engine_version + global_cluster_identifier = aws_rds_global_cluster.test.id + skip_final_snapshot = true lifecycle { ignore_changes = [ From b88585b927c84647ba15cd5ab609764e4ab077cd Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Mon, 14 Mar 2022 13:02:05 -0400 Subject: [PATCH 28/32] Final lint --- internal/service/rds/global_cluster_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/service/rds/global_cluster_test.go b/internal/service/rds/global_cluster_test.go index c87bfd42b79..44f1fc99963 100644 --- a/internal/service/rds/global_cluster_test.go +++ b/internal/service/rds/global_cluster_test.go @@ -37,21 +37,21 @@ func TestClusterIDRegionFromARN(t *testing.T) { TestName: "normal ARN", Input: "arn:aws:rds:us-west-2:012345678901:cluster:tf-acc-test-1467354933239945971", // lintignore:AWSAT003,AWSAT005 ExpectedID: "tf-acc-test-1467354933239945971", - ExpectedRegion: "us-west-2", + ExpectedRegion: "us-west-2", // lintignore:AWSAT003 ExpectedErr: false, }, { TestName: "another good ARN", Input: "arn:aws:rds:us-east-1:012345678901:cluster:tf-acc-test-1467354933239945971", // lintignore:AWSAT003,AWSAT005 ExpectedID: "tf-acc-test-1467354933239945971", - ExpectedRegion: "us-east-1", + ExpectedRegion: "us-east-1", // lintignore:AWSAT003 ExpectedErr: false, }, { TestName: "no account", Input: "arn:aws:rds:us-east-2::cluster:tf-acc-test-1467354933239945971", // lintignore:AWSAT003,AWSAT005 ExpectedID: "tf-acc-test-1467354933239945971", - ExpectedRegion: "us-east-2", + ExpectedRegion: "us-east-2", // lintignore:AWSAT003 ExpectedErr: false, }, { From 7424144b66b8b4e99641942f40a705d5a5b89192 Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Mon, 14 Mar 2022 13:44:56 -0400 Subject: [PATCH 29/32] Remove unused --- internal/service/rds/global_cluster.go | 41 -------------------------- 1 file changed, 41 deletions(-) diff --git a/internal/service/rds/global_cluster.go b/internal/service/rds/global_cluster.go index f019af4e942..fd45ed01482 100644 --- a/internal/service/rds/global_cluster.go +++ b/internal/service/rds/global_cluster.go @@ -432,32 +432,6 @@ func globalClusterRefreshFunc(conn *rds.RDS, globalClusterID string) resource.St } } -func globalClusterVersionRefreshFunc(conn *rds.RDS, globalClusterID, engineVersion string) resource.StateRefreshFunc { - return func() (interface{}, string, error) { - globalCluster, err := DescribeGlobalCluster(conn, globalClusterID) - - if tfawserr.ErrCodeEquals(err, rds.ErrCodeGlobalClusterNotFoundFault) { - return nil, "deleted", nil - } - - if err != nil { - return nil, "", fmt.Errorf("error reading RDS Global Cluster (%s): %s", globalClusterID, err) - } - - if globalCluster == nil { - return nil, "deleted", nil - } - - status := aws.StringValue(globalCluster.Status) - - if status == rds.CustomEngineVersionStatusAvailable && aws.StringValue(globalCluster.EngineVersion) == engineVersion { - status = aws.StringValue(globalCluster.EngineVersion) - } - - return globalCluster, status, nil - } -} - func waitForGlobalClusterCreation(conn *rds.RDS, globalClusterID string, timeout time.Duration) error { stateConf := &resource.StateChangeConf{ Pending: []string{"creating"}, @@ -487,21 +461,6 @@ func waitForGlobalClusterUpdate(conn *rds.RDS, globalClusterID string, timeout t return err } -func waitForGlobalClusterVersionUpdate(conn *rds.RDS, globalClusterID, version string, timeout time.Duration) error { - stateConf := &resource.StateChangeConf{ - Pending: []string{"modifying", "upgrading", "available"}, - Target: []string{version}, - Refresh: globalClusterVersionRefreshFunc(conn, globalClusterID, version), - Timeout: timeout, - Delay: 30 * time.Second, - } - - log.Printf("[DEBUG] Waiting for RDS Global Cluster (%s) version sync", globalClusterID) - _, err := stateConf.WaitForState() - - return err -} - func WaitForGlobalClusterDeletion(conn *rds.RDS, globalClusterID string, timeout time.Duration) error { stateConf := &resource.StateChangeConf{ Pending: []string{ From 974fa731d058f902859c8722e5989400245e4134 Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Mon, 14 Mar 2022 14:16:02 -0400 Subject: [PATCH 30/32] rds: Add long-test guards --- internal/service/rds/cluster_endpoint_test.go | 8 + internal/service/rds/cluster_instance_test.go | 96 ++++ internal/service/rds/cluster_test.go | 124 ++++++ internal/service/rds/global_cluster_test.go | 16 + .../service/rds/instance_data_source_test.go | 8 + .../rds/instance_role_association_test.go | 8 + internal/service/rds/instance_test.go | 416 ++++++++++++++++++ internal/service/rds/option_group_test.go | 4 + .../orderable_instance_data_source_test.go | 40 ++ .../service/rds/proxy_data_source_test.go | 4 + .../rds/proxy_default_target_group_test.go | 32 ++ internal/service/rds/proxy_endpoint_test.go | 24 + internal/service/rds/proxy_target_test.go | 12 + internal/service/rds/proxy_test.go | 48 ++ .../service/rds/snapshot_data_source_test.go | 4 + internal/service/rds/snapshot_test.go | 12 + 16 files changed, 856 insertions(+) diff --git a/internal/service/rds/cluster_endpoint_test.go b/internal/service/rds/cluster_endpoint_test.go index c463959741a..754bad93244 100644 --- a/internal/service/rds/cluster_endpoint_test.go +++ b/internal/service/rds/cluster_endpoint_test.go @@ -18,6 +18,10 @@ import ( ) func TestAccRDSClusterEndpoint_basic(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + rInt := sdkacctest.RandInt() var customReaderEndpoint rds.DBClusterEndpoint var customEndpoint rds.DBClusterEndpoint @@ -61,6 +65,10 @@ func TestAccRDSClusterEndpoint_basic(t *testing.T) { } func TestAccRDSClusterEndpoint_tags(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + rInt := sdkacctest.RandInt() var customReaderEndpoint rds.DBClusterEndpoint resourceName := "aws_rds_cluster_endpoint.reader" diff --git a/internal/service/rds/cluster_instance_test.go b/internal/service/rds/cluster_instance_test.go index d688a4a6f6d..a2a18595f16 100644 --- a/internal/service/rds/cluster_instance_test.go +++ b/internal/service/rds/cluster_instance_test.go @@ -19,6 +19,10 @@ import ( ) func TestAccRDSClusterInstance_basic(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var v rds.DBInstance resourceName := "aws_rds_cluster_instance.cluster_instances" @@ -66,6 +70,10 @@ func TestAccRDSClusterInstance_basic(t *testing.T) { } func TestAccRDSClusterInstance_isAlreadyBeingDeleted(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var v rds.DBInstance resourceName := "aws_rds_cluster_instance.cluster_instances" rInt := sdkacctest.RandInt() @@ -103,6 +111,10 @@ func TestAccRDSClusterInstance_isAlreadyBeingDeleted(t *testing.T) { } func TestAccRDSClusterInstance_az(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var v rds.DBInstance resourceName := "aws_rds_cluster_instance.cluster_instances" availabilityZonesDataSourceName := "data.aws_availability_zones.available" @@ -135,6 +147,10 @@ func TestAccRDSClusterInstance_az(t *testing.T) { } func TestAccRDSClusterInstance_namePrefix(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var v rds.DBInstance rInt := sdkacctest.RandInt() resourceName := "aws_rds_cluster_instance.test" @@ -168,6 +184,10 @@ func TestAccRDSClusterInstance_namePrefix(t *testing.T) { } func TestAccRDSClusterInstance_generatedName(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var v rds.DBInstance resourceName := "aws_rds_cluster_instance.test" @@ -199,6 +219,10 @@ func TestAccRDSClusterInstance_generatedName(t *testing.T) { } func TestAccRDSClusterInstance_kmsKey(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var v rds.DBInstance kmsKeyResourceName := "aws_kms_key.foo" resourceName := "aws_rds_cluster_instance.cluster_instances" @@ -231,6 +255,10 @@ func TestAccRDSClusterInstance_kmsKey(t *testing.T) { // https://github.com/hashicorp/terraform/issues/5350 func TestAccRDSClusterInstance_disappears(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var v rds.DBInstance resourceName := "aws_rds_cluster_instance.cluster_instances" @@ -253,6 +281,10 @@ func TestAccRDSClusterInstance_disappears(t *testing.T) { } func TestAccRDSClusterInstance_publiclyAccessible(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_rds_cluster_instance.test" @@ -291,6 +323,10 @@ func TestAccRDSClusterInstance_publiclyAccessible(t *testing.T) { } func TestAccRDSClusterInstance_copyTagsToSnapshot(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance rds.DBInstance rNameSuffix := sdkacctest.RandInt() resourceName := "aws_rds_cluster_instance.cluster_instances" @@ -329,6 +365,10 @@ func TestAccRDSClusterInstance_copyTagsToSnapshot(t *testing.T) { } func TestAccRDSClusterInstance_monitoringInterval(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance rds.DBInstance resourceName := "aws_rds_cluster_instance.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -381,6 +421,10 @@ func TestAccRDSClusterInstance_monitoringInterval(t *testing.T) { } func TestAccRDSClusterInstance_MonitoringRoleARN_enabledToDisabled(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance rds.DBInstance iamRoleResourceName := "aws_iam_role.test" resourceName := "aws_rds_cluster_instance.test" @@ -420,6 +464,10 @@ func TestAccRDSClusterInstance_MonitoringRoleARN_enabledToDisabled(t *testing.T) } func TestAccRDSClusterInstance_MonitoringRoleARN_enabledToRemoved(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance rds.DBInstance iamRoleResourceName := "aws_iam_role.test" resourceName := "aws_rds_cluster_instance.test" @@ -458,6 +506,10 @@ func TestAccRDSClusterInstance_MonitoringRoleARN_enabledToRemoved(t *testing.T) } func TestAccRDSClusterInstance_MonitoringRoleARN_removedToEnabled(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance rds.DBInstance iamRoleResourceName := "aws_iam_role.test" resourceName := "aws_rds_cluster_instance.test" @@ -496,6 +548,10 @@ func TestAccRDSClusterInstance_MonitoringRoleARN_removedToEnabled(t *testing.T) } func TestAccRDSClusterInstance_PerformanceInsightsEnabled_auroraMySQL1(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance rds.DBInstance resourceName := "aws_rds_cluster_instance.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -528,6 +584,10 @@ func TestAccRDSClusterInstance_PerformanceInsightsEnabled_auroraMySQL1(t *testin } func TestAccRDSClusterInstance_PerformanceInsightsEnabled_auroraMySQL2(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance rds.DBInstance resourceName := "aws_rds_cluster_instance.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -561,6 +621,10 @@ func TestAccRDSClusterInstance_PerformanceInsightsEnabled_auroraMySQL2(t *testin } func TestAccRDSClusterInstance_PerformanceInsightsEnabled_auroraPostgresql(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance rds.DBInstance resourceName := "aws_rds_cluster_instance.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -593,6 +657,10 @@ func TestAccRDSClusterInstance_PerformanceInsightsEnabled_auroraPostgresql(t *te } func TestAccRDSClusterInstance_PerformanceInsightsKMSKeyID_auroraMySQL1(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance rds.DBInstance kmsKeyResourceName := "aws_kms_key.test" resourceName := "aws_rds_cluster_instance.test" @@ -627,6 +695,10 @@ func TestAccRDSClusterInstance_PerformanceInsightsKMSKeyID_auroraMySQL1(t *testi } func TestAccRDSClusterInstance_PerformanceInsightsKMSKeyIDAuroraMySQL1_defaultKeyToCustomKey(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance rds.DBInstance resourceName := "aws_rds_cluster_instance.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -663,6 +735,10 @@ func TestAccRDSClusterInstance_PerformanceInsightsKMSKeyIDAuroraMySQL1_defaultKe } func TestAccRDSClusterInstance_PerformanceInsightsKMSKeyID_auroraMySQL2(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance rds.DBInstance kmsKeyResourceName := "aws_kms_key.test" resourceName := "aws_rds_cluster_instance.test" @@ -698,6 +774,10 @@ func TestAccRDSClusterInstance_PerformanceInsightsKMSKeyID_auroraMySQL2(t *testi } func TestAccRDSClusterInstance_PerformanceInsightsKMSKeyIDAuroraMySQL2_defaultKeyToCustomKey(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance rds.DBInstance resourceName := "aws_rds_cluster_instance.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -735,6 +815,10 @@ func TestAccRDSClusterInstance_PerformanceInsightsKMSKeyIDAuroraMySQL2_defaultKe } func TestAccRDSClusterInstance_performanceInsightsRetentionPeriod(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance rds.DBInstance resourceName := "aws_rds_cluster_instance.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -775,6 +859,10 @@ func TestAccRDSClusterInstance_performanceInsightsRetentionPeriod(t *testing.T) } func TestAccRDSClusterInstance_PerformanceInsightsKMSKeyID_auroraPostgresql(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance rds.DBInstance kmsKeyResourceName := "aws_kms_key.test" resourceName := "aws_rds_cluster_instance.test" @@ -809,6 +897,10 @@ func TestAccRDSClusterInstance_PerformanceInsightsKMSKeyID_auroraPostgresql(t *t } func TestAccRDSClusterInstance_PerformanceInsightsKMSKeyIDAuroraPostgresql_defaultKeyToCustomKey(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance rds.DBInstance resourceName := "aws_rds_cluster_instance.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -845,6 +937,10 @@ func TestAccRDSClusterInstance_PerformanceInsightsKMSKeyIDAuroraPostgresql_defau } func TestAccRDSClusterInstance_caCertificateIdentifier(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_rds_cluster_instance.test" diff --git a/internal/service/rds/cluster_test.go b/internal/service/rds/cluster_test.go index d0abe29c25e..5324b6bcd2f 100644 --- a/internal/service/rds/cluster_test.go +++ b/internal/service/rds/cluster_test.go @@ -84,6 +84,10 @@ func TestAccRDSCluster_basic(t *testing.T) { } func TestAccRDSCluster_allowMajorVersionUpgrade(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbCluster1, dbCluster2 rds.DBCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_rds_cluster.test" @@ -137,6 +141,10 @@ func TestAccRDSCluster_allowMajorVersionUpgrade(t *testing.T) { } func TestAccRDSCluster_allowMajorVersionUpgradeWithCustomParametersApplyImm(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbCluster1, dbCluster2 rds.DBCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_rds_cluster.test" @@ -176,6 +184,10 @@ func TestAccRDSCluster_allowMajorVersionUpgradeWithCustomParametersApplyImm(t *t } func TestAccRDSCluster_allowMajorVersionUpgradeWithCustomParameters(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbCluster1, dbCluster2 rds.DBCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_rds_cluster.test" @@ -229,6 +241,10 @@ func TestAccRDSCluster_allowMajorVersionUpgradeWithCustomParameters(t *testing.T } func TestAccRDSCluster_onlyMajorVersion(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbCluster1 rds.DBCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_rds_cluster.test" @@ -364,6 +380,10 @@ func TestAccRDSCluster_dbSubnetGroupName(t *testing.T) { } func TestAccRDSCluster_s3Restore(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var v rds.DBCluster resourceName := "aws_rds_cluster.test" bucket := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -388,6 +408,10 @@ func TestAccRDSCluster_s3Restore(t *testing.T) { } func TestAccRDSCluster_pointInTimeRestore(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var v rds.DBCluster var c rds.DBCluster @@ -414,6 +438,10 @@ func TestAccRDSCluster_pointInTimeRestore(t *testing.T) { } func TestAccRDSCluster_PointInTimeRestore_enabledCloudWatchLogsExports(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var v rds.DBCluster var c rds.DBCluster @@ -725,6 +753,10 @@ func TestAccRDSCluster_copyTagsToSnapshot(t *testing.T) { } func TestAccRDSCluster_ReplicationSourceIdentifier_kmsKeyID(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var primaryCluster rds.DBCluster var replicaCluster rds.DBCluster resourceName := "aws_rds_cluster.test" @@ -846,6 +878,10 @@ func TestAccRDSCluster_deletionProtection(t *testing.T) { } func TestAccRDSCluster_engineMode(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbCluster1, dbCluster2 rds.DBCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -948,6 +984,10 @@ func TestAccRDSCluster_EngineMode_parallelQuery(t *testing.T) { } func TestAccRDSCluster_engineVersion(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbCluster rds.DBCluster rInt := sdkacctest.RandInt() resourceName := "aws_rds_cluster.test" @@ -976,6 +1016,10 @@ func TestAccRDSCluster_engineVersion(t *testing.T) { } func TestAccRDSCluster_engineVersionWithPrimaryInstance(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbCluster rds.DBCluster rInt := sdkacctest.RandInt() resourceName := "aws_rds_cluster.test" @@ -1145,6 +1189,10 @@ func TestAccRDSCluster_GlobalClusterIdentifierEngineMode_provisioned(t *testing. // Reference: https://github.com/hashicorp/terraform-provider-aws/issues/13126 func TestAccRDSCluster_GlobalClusterIdentifier_primarySecondaryClusters(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var providers []*schema.Provider var primaryDbCluster, secondaryDbCluster rds.DBCluster @@ -1178,6 +1226,10 @@ func TestAccRDSCluster_GlobalClusterIdentifier_primarySecondaryClusters(t *testi // Reference: https://github.com/hashicorp/terraform-provider-aws/issues/13715 func TestAccRDSCluster_GlobalClusterIdentifier_replicationSourceIdentifier(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var providers []*schema.Provider var primaryDbCluster, secondaryDbCluster rds.DBCluster @@ -1208,6 +1260,10 @@ func TestAccRDSCluster_GlobalClusterIdentifier_replicationSourceIdentifier(t *te // Reference: https://github.com/hashicorp/terraform-provider-aws/issues/14457 func TestAccRDSCluster_GlobalClusterIdentifier_secondaryClustersWriteForwarding(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var providers []*schema.Provider var primaryDbCluster, secondaryDbCluster rds.DBCluster @@ -1270,6 +1326,10 @@ func TestAccRDSCluster_port(t *testing.T) { } func TestAccRDSCluster_scaling(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbCluster rds.DBCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -1339,6 +1399,10 @@ func TestAccRDSCluster_Scaling_defaultMinCapacity(t *testing.T) { } func TestAccRDSCluster_snapshotIdentifier(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbCluster, sourceDbCluster rds.DBCluster var dbClusterSnapshot rds.DBClusterSnapshot @@ -1366,6 +1430,10 @@ func TestAccRDSCluster_snapshotIdentifier(t *testing.T) { } func TestAccRDSCluster_SnapshotIdentifier_deletionProtection(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbCluster, sourceDbCluster rds.DBCluster var dbClusterSnapshot rds.DBClusterSnapshot @@ -1404,6 +1472,10 @@ func TestAccRDSCluster_SnapshotIdentifier_deletionProtection(t *testing.T) { } func TestAccRDSCluster_SnapshotIdentifierEngineMode_parallelQuery(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbCluster, sourceDbCluster rds.DBCluster var dbClusterSnapshot rds.DBClusterSnapshot @@ -1432,6 +1504,10 @@ func TestAccRDSCluster_SnapshotIdentifierEngineMode_parallelQuery(t *testing.T) } func TestAccRDSCluster_SnapshotIdentifierEngineMode_provisioned(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbCluster, sourceDbCluster rds.DBCluster var dbClusterSnapshot rds.DBClusterSnapshot @@ -1493,6 +1569,10 @@ func TestAccRDSCluster_SnapshotIdentifierEngineMode_serverless(t *testing.T) { // Reference: https://github.com/hashicorp/terraform-provider-aws/issues/6157 func TestAccRDSCluster_SnapshotIdentifierEngineVersion_different(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbCluster, sourceDbCluster rds.DBCluster var dbClusterSnapshot rds.DBClusterSnapshot @@ -1523,6 +1603,10 @@ func TestAccRDSCluster_SnapshotIdentifierEngineVersion_different(t *testing.T) { // Reference: https://github.com/hashicorp/terraform-provider-aws/issues/6157 func TestAccRDSCluster_SnapshotIdentifierEngineVersion_equal(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbCluster, sourceDbCluster rds.DBCluster var dbClusterSnapshot rds.DBClusterSnapshot @@ -1552,6 +1636,10 @@ func TestAccRDSCluster_SnapshotIdentifierEngineVersion_equal(t *testing.T) { } func TestAccRDSCluster_SnapshotIdentifier_kmsKeyID(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbCluster, sourceDbCluster rds.DBCluster var dbClusterSnapshot rds.DBClusterSnapshot @@ -1581,6 +1669,10 @@ func TestAccRDSCluster_SnapshotIdentifier_kmsKeyID(t *testing.T) { } func TestAccRDSCluster_SnapshotIdentifier_masterPassword(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbCluster, sourceDbCluster rds.DBCluster var dbClusterSnapshot rds.DBClusterSnapshot @@ -1609,6 +1701,10 @@ func TestAccRDSCluster_SnapshotIdentifier_masterPassword(t *testing.T) { } func TestAccRDSCluster_SnapshotIdentifier_masterUsername(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbCluster, sourceDbCluster rds.DBCluster var dbClusterSnapshot rds.DBClusterSnapshot @@ -1639,6 +1735,10 @@ func TestAccRDSCluster_SnapshotIdentifier_masterUsername(t *testing.T) { } func TestAccRDSCluster_SnapshotIdentifier_preferredBackupWindow(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbCluster, sourceDbCluster rds.DBCluster var dbClusterSnapshot rds.DBClusterSnapshot @@ -1667,6 +1767,10 @@ func TestAccRDSCluster_SnapshotIdentifier_preferredBackupWindow(t *testing.T) { } func TestAccRDSCluster_SnapshotIdentifier_preferredMaintenanceWindow(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbCluster, sourceDbCluster rds.DBCluster var dbClusterSnapshot rds.DBClusterSnapshot @@ -1695,6 +1799,10 @@ func TestAccRDSCluster_SnapshotIdentifier_preferredMaintenanceWindow(t *testing. } func TestAccRDSCluster_SnapshotIdentifier_tags(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbCluster, sourceDbCluster rds.DBCluster var dbClusterSnapshot rds.DBClusterSnapshot @@ -1724,6 +1832,10 @@ func TestAccRDSCluster_SnapshotIdentifier_tags(t *testing.T) { } func TestAccRDSCluster_SnapshotIdentifier_vpcSecurityGroupIDs(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbCluster, sourceDbCluster rds.DBCluster var dbClusterSnapshot rds.DBClusterSnapshot @@ -1755,6 +1867,10 @@ func TestAccRDSCluster_SnapshotIdentifier_vpcSecurityGroupIDs(t *testing.T) { // vpc_security_group_ids is set (which triggered the resource update function), // and tags is set which was missing its ARN used for tagging func TestAccRDSCluster_SnapshotIdentifierVPCSecurityGroupIDs_tags(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbCluster, sourceDbCluster rds.DBCluster var dbClusterSnapshot rds.DBClusterSnapshot @@ -1784,6 +1900,10 @@ func TestAccRDSCluster_SnapshotIdentifierVPCSecurityGroupIDs_tags(t *testing.T) } func TestAccRDSCluster_SnapshotIdentifier_encryptedRestore(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbCluster, sourceDbCluster rds.DBCluster var dbClusterSnapshot rds.DBClusterSnapshot @@ -1814,6 +1934,10 @@ func TestAccRDSCluster_SnapshotIdentifier_encryptedRestore(t *testing.T) { } func TestAccRDSCluster_enableHTTPEndpoint(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbCluster rds.DBCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) diff --git a/internal/service/rds/global_cluster_test.go b/internal/service/rds/global_cluster_test.go index 44f1fc99963..dc2c4d15892 100644 --- a/internal/service/rds/global_cluster_test.go +++ b/internal/service/rds/global_cluster_test.go @@ -271,6 +271,10 @@ func TestAccRDSGlobalCluster_EngineVersion_aurora(t *testing.T) { } func TestAccRDSGlobalCluster_EngineVersion_updateMinor(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var globalCluster1, globalCluster2 rds.GlobalCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_rds_global_cluster.test" @@ -307,6 +311,10 @@ func TestAccRDSGlobalCluster_EngineVersion_updateMinor(t *testing.T) { } func TestAccRDSGlobalCluster_EngineVersion_updateMajor(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var globalCluster1, globalCluster2 rds.GlobalCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_rds_global_cluster.test" @@ -341,6 +349,10 @@ func TestAccRDSGlobalCluster_EngineVersion_updateMajor(t *testing.T) { } func TestAccRDSGlobalCluster_EngineVersion_updateMinorMultiRegion(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var providers []*schema.Provider var globalCluster1, globalCluster2 rds.GlobalCluster rNameGlobal := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) // don't need to be unique but makes debugging easier @@ -373,6 +385,10 @@ func TestAccRDSGlobalCluster_EngineVersion_updateMinorMultiRegion(t *testing.T) } func TestAccRDSGlobalCluster_EngineVersion_updateMajorMultiRegion(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var providers []*schema.Provider var globalCluster1, globalCluster2 rds.GlobalCluster rNameGlobal := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) // don't need to be unique but makes debugging easier diff --git a/internal/service/rds/instance_data_source_test.go b/internal/service/rds/instance_data_source_test.go index bbedf381724..254aac723e1 100644 --- a/internal/service/rds/instance_data_source_test.go +++ b/internal/service/rds/instance_data_source_test.go @@ -11,6 +11,10 @@ import ( ) func TestAccRDSInstanceDataSource_basic(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) dataSourceName := "data.aws_db_instance.test" @@ -46,6 +50,10 @@ func TestAccRDSInstanceDataSource_basic(t *testing.T) { } func TestAccRDSInstanceDataSource_ec2Classic(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) dataSourceName := "data.aws_db_instance.test" diff --git a/internal/service/rds/instance_role_association_test.go b/internal/service/rds/instance_role_association_test.go index 6fd567d89cd..bab6d99f05d 100644 --- a/internal/service/rds/instance_role_association_test.go +++ b/internal/service/rds/instance_role_association_test.go @@ -16,6 +16,10 @@ import ( ) func TestAccRDSInstanceRoleAssociation_basic(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstanceRole1 rds.DBInstanceRole rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) dbInstanceResourceName := "aws_db_instance.test" @@ -47,6 +51,10 @@ func TestAccRDSInstanceRoleAssociation_basic(t *testing.T) { } func TestAccRDSInstanceRoleAssociation_disappears(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance1 rds.DBInstance var dbInstanceRole1 rds.DBInstanceRole rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) diff --git a/internal/service/rds/instance_test.go b/internal/service/rds/instance_test.go index ca3b4baaf4b..53c4aee5c0e 100644 --- a/internal/service/rds/instance_test.go +++ b/internal/service/rds/instance_test.go @@ -23,6 +23,10 @@ import ( ) func TestAccRDSInstance_basic(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance1 rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -92,6 +96,10 @@ func TestAccRDSInstance_basic(t *testing.T) { } func TestAccRDSInstance_NameDeprecated_basic(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance1 rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -162,6 +170,10 @@ func TestAccRDSInstance_NameDeprecated_basic(t *testing.T) { } func TestAccRDSInstance_onlyMajorVersion(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance1 rds.DBInstance resourceName := "aws_db_instance.test" engine := "mysql" @@ -195,6 +207,10 @@ func TestAccRDSInstance_onlyMajorVersion(t *testing.T) { } func TestAccRDSInstance_namePrefix(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var v rds.DBInstance const identifierPrefix = "tf-acc-test-prefix-" @@ -227,6 +243,10 @@ func TestAccRDSInstance_namePrefix(t *testing.T) { } func TestAccRDSInstance_nameGenerated(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var v rds.DBInstance const resourceName = "aws_db_instance.test" @@ -258,6 +278,10 @@ func TestAccRDSInstance_nameGenerated(t *testing.T) { } func TestAccRDSInstance_kmsKey(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var v rds.DBInstance kmsKeyResourceName := "aws_kms_key.foo" resourceName := "aws_db_instance.bar" @@ -294,6 +318,10 @@ func TestAccRDSInstance_kmsKey(t *testing.T) { } func TestAccRDSInstance_subnetGroup(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var v rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_db_instance.test" @@ -323,6 +351,10 @@ func TestAccRDSInstance_subnetGroup(t *testing.T) { } func TestAccRDSInstance_optionGroup(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var v rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -347,6 +379,10 @@ func TestAccRDSInstance_optionGroup(t *testing.T) { } func TestAccRDSInstance_iamAuth(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var v rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -370,6 +406,10 @@ func TestAccRDSInstance_iamAuth(t *testing.T) { } func TestAccRDSInstance_allowMajorVersionUpgrade(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance1 rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -412,6 +452,10 @@ func TestAccRDSInstance_allowMajorVersionUpgrade(t *testing.T) { } func TestAccRDSInstance_dbSubnetGroupName(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance rds.DBInstance var dbSubnetGroup rds.DBSubnetGroup @@ -469,6 +513,10 @@ func TestAccRDSInstance_DBSubnetGroupName_ramShared(t *testing.T) { } func TestAccRDSInstance_DBSubnetGroupName_vpcSecurityGroupIDs(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance rds.DBInstance var dbSubnetGroup rds.DBSubnetGroup @@ -495,6 +543,10 @@ func TestAccRDSInstance_DBSubnetGroupName_vpcSecurityGroupIDs(t *testing.T) { } func TestAccRDSInstance_deletionProtection(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -537,6 +589,10 @@ func TestAccRDSInstance_deletionProtection(t *testing.T) { } func TestAccRDSInstance_finalSnapshotIdentifier(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var snap rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -559,6 +615,10 @@ func TestAccRDSInstance_finalSnapshotIdentifier(t *testing.T) { } func TestAccRDSInstance_FinalSnapshotIdentifier_skipFinalSnapshot(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var snap rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -579,6 +639,10 @@ func TestAccRDSInstance_FinalSnapshotIdentifier_skipFinalSnapshot(t *testing.T) } func TestAccRDSInstance_isAlreadyBeingDeleted(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -617,6 +681,10 @@ func TestAccRDSInstance_isAlreadyBeingDeleted(t *testing.T) { } func TestAccRDSInstance_maxAllocatedStorage(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -661,6 +729,10 @@ func TestAccRDSInstance_maxAllocatedStorage(t *testing.T) { } func TestAccRDSInstance_password(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -700,6 +772,10 @@ func TestAccRDSInstance_password(t *testing.T) { } func TestAccRDSInstance_ReplicateSourceDB_basic(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance, sourceDbInstance rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -737,6 +813,10 @@ func TestAccRDSInstance_ReplicateSourceDB_basic(t *testing.T) { } func TestAccRDSInstance_ReplicateSourceDB_namePrefix(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var v rds.DBInstance sourceName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -770,6 +850,10 @@ func TestAccRDSInstance_ReplicateSourceDB_namePrefix(t *testing.T) { } func TestAccRDSInstance_ReplicateSourceDB_nameGenerated(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var v rds.DBInstance sourceName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -802,6 +886,10 @@ func TestAccRDSInstance_ReplicateSourceDB_nameGenerated(t *testing.T) { } func TestAccRDSInstance_ReplicateSourceDB_addLater(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance, sourceDbInstance rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -833,6 +921,10 @@ func TestAccRDSInstance_ReplicateSourceDB_addLater(t *testing.T) { } func TestAccRDSInstance_ReplicateSourceDB_allocatedStorage(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance, sourceDbInstance rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -859,6 +951,10 @@ func TestAccRDSInstance_ReplicateSourceDB_allocatedStorage(t *testing.T) { } func TestAccRDSInstance_ReplicateSourceDB_iops(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance, sourceDbInstance rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -885,6 +981,10 @@ func TestAccRDSInstance_ReplicateSourceDB_iops(t *testing.T) { } func TestAccRDSInstance_ReplicateSourceDB_allocatedStorageAndIops(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance, sourceDbInstance rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -912,6 +1012,10 @@ func TestAccRDSInstance_ReplicateSourceDB_allocatedStorageAndIops(t *testing.T) } func TestAccRDSInstance_ReplicateSourceDB_allowMajorVersionUpgrade(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance, sourceDbInstance rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -938,6 +1042,10 @@ func TestAccRDSInstance_ReplicateSourceDB_allowMajorVersionUpgrade(t *testing.T) } func TestAccRDSInstance_ReplicateSourceDB_autoMinorVersionUpgrade(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance, sourceDbInstance rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -964,6 +1072,10 @@ func TestAccRDSInstance_ReplicateSourceDB_autoMinorVersionUpgrade(t *testing.T) } func TestAccRDSInstance_ReplicateSourceDB_availabilityZone(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance, sourceDbInstance rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -989,6 +1101,10 @@ func TestAccRDSInstance_ReplicateSourceDB_availabilityZone(t *testing.T) { } func TestAccRDSInstance_ReplicateSourceDB_backupRetentionPeriod(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance, sourceDbInstance rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -1015,6 +1131,10 @@ func TestAccRDSInstance_ReplicateSourceDB_backupRetentionPeriod(t *testing.T) { } func TestAccRDSInstance_ReplicateSourceDB_backupWindow(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance, sourceDbInstance rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -1041,6 +1161,10 @@ func TestAccRDSInstance_ReplicateSourceDB_backupWindow(t *testing.T) { } func TestAccRDSInstance_ReplicateSourceDB_dbSubnetGroupName(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance rds.DBInstance var dbSubnetGroup rds.DBSubnetGroup var providers []*schema.Provider @@ -1071,6 +1195,10 @@ func TestAccRDSInstance_ReplicateSourceDB_dbSubnetGroupName(t *testing.T) { } func TestAccRDSInstance_ReplicateSourceDBDBSubnetGroupName_ramShared(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance rds.DBInstance var dbSubnetGroup rds.DBSubnetGroup var providers []*schema.Provider @@ -1103,6 +1231,10 @@ func TestAccRDSInstance_ReplicateSourceDBDBSubnetGroupName_ramShared(t *testing. } func TestAccRDSInstance_ReplicateSourceDBDBSubnetGroupName_vpcSecurityGroupIDs(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance rds.DBInstance var dbSubnetGroup rds.DBSubnetGroup var providers []*schema.Provider @@ -1181,6 +1313,10 @@ func TestAccRDSInstance_ReplicateSourceDB_deletionProtection(t *testing.T) { } func TestAccRDSInstance_ReplicateSourceDB_iamDatabaseAuthenticationEnabled(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance, sourceDbInstance rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -1207,6 +1343,10 @@ func TestAccRDSInstance_ReplicateSourceDB_iamDatabaseAuthenticationEnabled(t *te } func TestAccRDSInstance_ReplicateSourceDB_maintenanceWindow(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance, sourceDbInstance rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -1233,6 +1373,10 @@ func TestAccRDSInstance_ReplicateSourceDB_maintenanceWindow(t *testing.T) { } func TestAccRDSInstance_ReplicateSourceDB_maxAllocatedStorage(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance, sourceDbInstance rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -1259,6 +1403,10 @@ func TestAccRDSInstance_ReplicateSourceDB_maxAllocatedStorage(t *testing.T) { } func TestAccRDSInstance_ReplicateSourceDB_monitoring(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance, sourceDbInstance rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -1285,6 +1433,10 @@ func TestAccRDSInstance_ReplicateSourceDB_monitoring(t *testing.T) { } func TestAccRDSInstance_ReplicateSourceDB_multiAZ(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance, sourceDbInstance rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -1311,6 +1463,10 @@ func TestAccRDSInstance_ReplicateSourceDB_multiAZ(t *testing.T) { } func TestAccRDSInstance_ReplicateSourceDB_parameterGroupNameSameSetOnBoth(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance, sourceDbInstance rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -1340,6 +1496,10 @@ func TestAccRDSInstance_ReplicateSourceDB_parameterGroupNameSameSetOnBoth(t *tes } func TestAccRDSInstance_ReplicateSourceDB_parameterGroupNameDifferentSetOnBoth(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance, sourceDbInstance rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -1369,6 +1529,10 @@ func TestAccRDSInstance_ReplicateSourceDB_parameterGroupNameDifferentSetOnBoth(t } func TestAccRDSInstance_ReplicateSourceDB_parameterGroupNameReplicaCopiesValue(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance, sourceDbInstance rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -1397,6 +1561,10 @@ func TestAccRDSInstance_ReplicateSourceDB_parameterGroupNameReplicaCopiesValue(t } func TestAccRDSInstance_ReplicateSourceDB_parameterGroupNameSetOnReplica(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance, sourceDbInstance rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -1424,6 +1592,10 @@ func TestAccRDSInstance_ReplicateSourceDB_parameterGroupNameSetOnReplica(t *test } func TestAccRDSInstance_ReplicateSourceDB_port(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance, sourceDbInstance rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -1450,6 +1622,10 @@ func TestAccRDSInstance_ReplicateSourceDB_port(t *testing.T) { } func TestAccRDSInstance_ReplicateSourceDB_vpcSecurityGroupIDs(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance, sourceDbInstance rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -1476,6 +1652,10 @@ func TestAccRDSInstance_ReplicateSourceDB_vpcSecurityGroupIDs(t *testing.T) { } func TestAccRDSInstance_ReplicateSourceDB_caCertificateIdentifier(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance, sourceDbInstance rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -1504,6 +1684,10 @@ func TestAccRDSInstance_ReplicateSourceDB_caCertificateIdentifier(t *testing.T) } func TestAccRDSInstance_ReplicateSourceDB_replicaMode(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance, sourceDbInstance rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -1535,6 +1719,10 @@ func TestAccRDSInstance_ReplicateSourceDB_replicaMode(t *testing.T) { // InvalidDBInstanceState: Instance cannot currently reboot due to an in-progress management operation // https://github.com/hashicorp/terraform-provider-aws/issues/11905 func TestAccRDSInstance_ReplicateSourceDB_parameterGroupTwoStep(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance, sourceDbInstance rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -1706,6 +1894,10 @@ func TestAccRDSInstance_S3Import_nameGenerated(t *testing.T) { } func TestAccRDSInstance_SnapshotIdentifier_basic(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance, sourceDbInstance rds.DBInstance var dbSnapshot rds.DBSnapshot @@ -1745,6 +1937,10 @@ func TestAccRDSInstance_SnapshotIdentifier_basic(t *testing.T) { } func TestAccRDSInstance_SnapshotIdentifier_namePrefix(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var v rds.DBInstance sourceName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -1779,6 +1975,10 @@ func TestAccRDSInstance_SnapshotIdentifier_namePrefix(t *testing.T) { } func TestAccRDSInstance_SnapshotIdentifier_nameGenerated(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var v rds.DBInstance sourceName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -1812,6 +2012,10 @@ func TestAccRDSInstance_SnapshotIdentifier_nameGenerated(t *testing.T) { } func TestAccRDSInstance_SnapshotIdentifier_AssociationRemoved(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance1, dbInstance2 rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -1845,6 +2049,10 @@ func TestAccRDSInstance_SnapshotIdentifier_AssociationRemoved(t *testing.T) { } func TestAccRDSInstance_SnapshotIdentifier_allocatedStorage(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance, sourceDbInstance rds.DBInstance var dbSnapshot rds.DBSnapshot @@ -1873,6 +2081,10 @@ func TestAccRDSInstance_SnapshotIdentifier_allocatedStorage(t *testing.T) { } func TestAccRDSInstance_SnapshotIdentifier_io1Storage(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance, sourceDbInstance rds.DBInstance var dbSnapshot rds.DBSnapshot @@ -1901,6 +2113,10 @@ func TestAccRDSInstance_SnapshotIdentifier_io1Storage(t *testing.T) { } func TestAccRDSInstance_SnapshotIdentifier_allowMajorVersionUpgrade(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance, sourceDbInstance rds.DBInstance var dbSnapshot rds.DBSnapshot @@ -1929,6 +2145,10 @@ func TestAccRDSInstance_SnapshotIdentifier_allowMajorVersionUpgrade(t *testing.T } func TestAccRDSInstance_SnapshotIdentifier_autoMinorVersionUpgrade(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance, sourceDbInstance rds.DBInstance var dbSnapshot rds.DBSnapshot @@ -1957,6 +2177,10 @@ func TestAccRDSInstance_SnapshotIdentifier_autoMinorVersionUpgrade(t *testing.T) } func TestAccRDSInstance_SnapshotIdentifier_availabilityZone(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance, sourceDbInstance rds.DBInstance var dbSnapshot rds.DBSnapshot @@ -1984,6 +2208,10 @@ func TestAccRDSInstance_SnapshotIdentifier_availabilityZone(t *testing.T) { } func TestAccRDSInstance_SnapshotIdentifier_backupRetentionPeriodOverride(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance, sourceDbInstance rds.DBInstance var dbSnapshot rds.DBSnapshot @@ -2012,6 +2240,10 @@ func TestAccRDSInstance_SnapshotIdentifier_backupRetentionPeriodOverride(t *test } func TestAccRDSInstance_SnapshotIdentifier_backupRetentionPeriodUnset(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance, sourceDbInstance rds.DBInstance var dbSnapshot rds.DBSnapshot @@ -2040,6 +2272,10 @@ func TestAccRDSInstance_SnapshotIdentifier_backupRetentionPeriodUnset(t *testing } func TestAccRDSInstance_SnapshotIdentifier_backupWindow(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance, sourceDbInstance rds.DBInstance var dbSnapshot rds.DBSnapshot @@ -2068,6 +2304,10 @@ func TestAccRDSInstance_SnapshotIdentifier_backupWindow(t *testing.T) { } func TestAccRDSInstance_SnapshotIdentifier_dbSubnetGroupName(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance, sourceDbInstance rds.DBInstance var dbSnapshot rds.DBSnapshot var dbSubnetGroup rds.DBSubnetGroup @@ -2099,6 +2339,10 @@ func TestAccRDSInstance_SnapshotIdentifier_dbSubnetGroupName(t *testing.T) { } func TestAccRDSInstance_SnapshotIdentifier_dbSubnetGroupNameRAMShared(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance, sourceDbInstance rds.DBInstance var dbSnapshot rds.DBSnapshot var dbSubnetGroup rds.DBSubnetGroup @@ -2135,6 +2379,10 @@ func TestAccRDSInstance_SnapshotIdentifier_dbSubnetGroupNameRAMShared(t *testing } func TestAccRDSInstance_SnapshotIdentifier_dbSubnetGroupNameVPCSecurityGroupIDs(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance, sourceDbInstance rds.DBInstance var dbSnapshot rds.DBSnapshot var dbSubnetGroup rds.DBSubnetGroup @@ -2166,6 +2414,10 @@ func TestAccRDSInstance_SnapshotIdentifier_dbSubnetGroupNameVPCSecurityGroupIDs( } func TestAccRDSInstance_SnapshotIdentifier_deletionProtection(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance, sourceDbInstance rds.DBInstance var dbSnapshot rds.DBSnapshot @@ -2204,6 +2456,10 @@ func TestAccRDSInstance_SnapshotIdentifier_deletionProtection(t *testing.T) { } func TestAccRDSInstance_SnapshotIdentifier_iamDatabaseAuthenticationEnabled(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance, sourceDbInstance rds.DBInstance var dbSnapshot rds.DBSnapshot @@ -2232,6 +2488,10 @@ func TestAccRDSInstance_SnapshotIdentifier_iamDatabaseAuthenticationEnabled(t *t } func TestAccRDSInstance_SnapshotIdentifier_maintenanceWindow(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance, sourceDbInstance rds.DBInstance var dbSnapshot rds.DBSnapshot @@ -2260,6 +2520,10 @@ func TestAccRDSInstance_SnapshotIdentifier_maintenanceWindow(t *testing.T) { } func TestAccRDSInstance_SnapshotIdentifier_maxAllocatedStorage(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance, sourceDbInstance rds.DBInstance var dbSnapshot rds.DBSnapshot @@ -2288,6 +2552,10 @@ func TestAccRDSInstance_SnapshotIdentifier_maxAllocatedStorage(t *testing.T) { } func TestAccRDSInstance_SnapshotIdentifier_monitoring(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance, sourceDbInstance rds.DBInstance var dbSnapshot rds.DBSnapshot @@ -2316,6 +2584,10 @@ func TestAccRDSInstance_SnapshotIdentifier_monitoring(t *testing.T) { } func TestAccRDSInstance_SnapshotIdentifier_multiAZ(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance, sourceDbInstance rds.DBInstance var dbSnapshot rds.DBSnapshot @@ -2344,6 +2616,10 @@ func TestAccRDSInstance_SnapshotIdentifier_multiAZ(t *testing.T) { } func TestAccRDSInstance_SnapshotIdentifier_multiAZSQLServer(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance, sourceDbInstance rds.DBInstance var dbSnapshot rds.DBSnapshot @@ -2372,6 +2648,10 @@ func TestAccRDSInstance_SnapshotIdentifier_multiAZSQLServer(t *testing.T) { } func TestAccRDSInstance_SnapshotIdentifier_parameterGroupName(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance, sourceDbInstance rds.DBInstance var dbSnapshot rds.DBSnapshot @@ -2401,6 +2681,10 @@ func TestAccRDSInstance_SnapshotIdentifier_parameterGroupName(t *testing.T) { } func TestAccRDSInstance_SnapshotIdentifier_port(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance, sourceDbInstance rds.DBInstance var dbSnapshot rds.DBSnapshot @@ -2429,6 +2713,10 @@ func TestAccRDSInstance_SnapshotIdentifier_port(t *testing.T) { } func TestAccRDSInstance_SnapshotIdentifier_tags(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance, sourceDbInstance rds.DBInstance var dbSnapshot rds.DBSnapshot @@ -2490,6 +2778,10 @@ func TestAccRDSInstance_SnapshotIdentifier_tagsRemove(t *testing.T) { } func TestAccRDSInstance_SnapshotIdentifier_vpcSecurityGroupIDs(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance, sourceDbInstance rds.DBInstance var dbSnapshot rds.DBSnapshot @@ -2521,6 +2813,10 @@ func TestAccRDSInstance_SnapshotIdentifier_vpcSecurityGroupIDs(t *testing.T) { // vpc_security_group_ids is set (which triggered the resource update function), // and tags is set which was missing its ARN used for tagging func TestAccRDSInstance_SnapshotIdentifier_vpcSecurityGroupIDsTags(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance, sourceDbInstance rds.DBInstance var dbSnapshot rds.DBSnapshot @@ -2550,6 +2846,10 @@ func TestAccRDSInstance_SnapshotIdentifier_vpcSecurityGroupIDsTags(t *testing.T) } func TestAccRDSInstance_monitoringInterval(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance rds.DBInstance resourceName := "aws_db_instance.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -2604,6 +2904,10 @@ func TestAccRDSInstance_monitoringInterval(t *testing.T) { } func TestAccRDSInstance_MonitoringRoleARN_enabledToDisabled(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance rds.DBInstance iamRoleResourceName := "aws_iam_role.test" resourceName := "aws_db_instance.test" @@ -2645,6 +2949,10 @@ func TestAccRDSInstance_MonitoringRoleARN_enabledToDisabled(t *testing.T) { } func TestAccRDSInstance_MonitoringRoleARN_enabledToRemoved(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance rds.DBInstance iamRoleResourceName := "aws_iam_role.test" resourceName := "aws_db_instance.test" @@ -2685,6 +2993,10 @@ func TestAccRDSInstance_MonitoringRoleARN_enabledToRemoved(t *testing.T) { } func TestAccRDSInstance_MonitoringRoleARN_removedToEnabled(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance rds.DBInstance iamRoleResourceName := "aws_iam_role.test" resourceName := "aws_db_instance.test" @@ -2728,6 +3040,10 @@ func TestAccRDSInstance_MonitoringRoleARN_removedToEnabled(t *testing.T) { // We apply a plan, then change just the iops. If the apply succeeds, we // consider this a pass, as before in 3760 the request would fail func TestAccRDSInstance_separateIopsUpdate(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var v rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -2758,6 +3074,10 @@ func TestAccRDSInstance_separateIopsUpdate(t *testing.T) { } func TestAccRDSInstance_portUpdate(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var v rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -2789,6 +3109,10 @@ func TestAccRDSInstance_portUpdate(t *testing.T) { } func TestAccRDSInstance_MSSQL_tz(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var v rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_db_instance.test" @@ -2823,6 +3147,10 @@ func TestAccRDSInstance_MSSQL_tz(t *testing.T) { } func TestAccRDSInstance_MSSQL_domain(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var vBefore, vAfter rds.DBInstance resourceName := "aws_db_instance.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -2860,6 +3188,14 @@ func TestAccRDSInstance_MSSQL_domain(t *testing.T) { } func TestAccRDSInstance_MSSQL_domainSnapshotRestore(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var v, vRestoredInstance rds.DBInstance resourceName := "aws_db_instance.test" originResourceName := "aws_db_instance.origin" @@ -2888,6 +3224,10 @@ func TestAccRDSInstance_MSSQL_domainSnapshotRestore(t *testing.T) { } func TestAccRDSInstance_MySQL_snapshotRestoreWithEngineVersion(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var v, vRestoredInstance rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_db_instance.test" @@ -2914,6 +3254,10 @@ func TestAccRDSInstance_MySQL_snapshotRestoreWithEngineVersion(t *testing.T) { } func TestAccRDSInstance_minorVersion(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var v rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -2955,6 +3299,10 @@ func TestAccRDSInstance_ec2Classic(t *testing.T) { } func TestAccRDSInstance_cloudWatchLogsExport(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var v rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -2988,6 +3336,10 @@ func TestAccRDSInstance_cloudWatchLogsExport(t *testing.T) { } func TestAccRDSInstance_EnabledCloudWatchLogsExports_mySQL(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var v rds.DBInstance resourceName := "aws_db_instance.bar" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -3039,6 +3391,10 @@ func TestAccRDSInstance_EnabledCloudWatchLogsExports_mySQL(t *testing.T) { } func TestAccRDSInstance_EnabledCloudWatchLogsExports_msSQL(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -3073,6 +3429,10 @@ func TestAccRDSInstance_EnabledCloudWatchLogsExports_msSQL(t *testing.T) { } func TestAccRDSInstance_EnabledCloudWatchLogsExports_oracle(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -3108,6 +3468,10 @@ func TestAccRDSInstance_EnabledCloudWatchLogsExports_oracle(t *testing.T) { } func TestAccRDSInstance_EnabledCloudWatchLogsExports_postgresql(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -3143,6 +3507,10 @@ func TestAccRDSInstance_EnabledCloudWatchLogsExports_postgresql(t *testing.T) { } func TestAccRDSInstance_noDeleteAutomatedBackups(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -3495,6 +3863,10 @@ func testAccCheckInstanceEC2ClassicExists(resourceName string, v *rds.DBInstance // Reference: https://github.com/hashicorp/terraform-provider-aws/issues/8792 func TestAccRDSInstance_PerformanceInsightsEnabled_disabledToEnabled(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_db_instance.test" @@ -3534,6 +3906,10 @@ func TestAccRDSInstance_PerformanceInsightsEnabled_disabledToEnabled(t *testing. } func TestAccRDSInstance_PerformanceInsightsEnabled_enabledToDisabled(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_db_instance.test" @@ -3573,6 +3949,10 @@ func TestAccRDSInstance_PerformanceInsightsEnabled_enabledToDisabled(t *testing. } func TestAccRDSInstance_performanceInsightsKMSKeyID(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) kmsKeyResourceName := "aws_kms_key.test" @@ -3623,6 +4003,10 @@ func TestAccRDSInstance_performanceInsightsKMSKeyID(t *testing.T) { } func TestAccRDSInstance_performanceInsightsRetentionPeriod(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_db_instance.test" @@ -3664,6 +4048,10 @@ func TestAccRDSInstance_performanceInsightsRetentionPeriod(t *testing.T) { } func TestAccRDSInstance_ReplicateSourceDB_performanceInsightsEnabled(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance, sourceDbInstance rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -3693,6 +4081,10 @@ func TestAccRDSInstance_ReplicateSourceDB_performanceInsightsEnabled(t *testing. } func TestAccRDSInstance_SnapshotIdentifier_performanceInsightsEnabled(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance, sourceDbInstance rds.DBInstance var dbSnapshot rds.DBSnapshot @@ -3724,6 +4116,10 @@ func TestAccRDSInstance_SnapshotIdentifier_performanceInsightsEnabled(t *testing } func TestAccRDSInstance_caCertificateIdentifier(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance rds.DBInstance resourceName := "aws_db_instance.bar" @@ -3747,6 +4143,10 @@ func TestAccRDSInstance_caCertificateIdentifier(t *testing.T) { } func TestAccRDSInstance_RestoreToPointInTime_sourceIdentifier(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance, sourceDbInstance rds.DBInstance sourceName := "aws_db_instance.test" resourceName := "aws_db_instance.restore" @@ -3784,6 +4184,10 @@ func TestAccRDSInstance_RestoreToPointInTime_sourceIdentifier(t *testing.T) { } func TestAccRDSInstance_RestoreToPointInTime_sourceResourceID(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance, sourceDbInstance rds.DBInstance sourceName := "aws_db_instance.test" resourceName := "aws_db_instance.restore" @@ -3821,6 +4225,10 @@ func TestAccRDSInstance_RestoreToPointInTime_sourceResourceID(t *testing.T) { } func TestAccRDSInstance_NationalCharacterSet_oracle(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -3856,6 +4264,10 @@ func TestAccRDSInstance_NationalCharacterSet_oracle(t *testing.T) { } func TestAccRDSInstance_NoNationalCharacterSet_oracle(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -4059,6 +4471,10 @@ func TestAccRDSInstance_CoIPEnabled_snapshotIdentifier(t *testing.T) { } func TestAccRDSInstance_license(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance1 rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_db_instance.test" diff --git a/internal/service/rds/option_group_test.go b/internal/service/rds/option_group_test.go index 658c29d44b3..796b1c11bce 100644 --- a/internal/service/rds/option_group_test.go +++ b/internal/service/rds/option_group_test.go @@ -158,6 +158,10 @@ func TestAccRDSOptionGroup_optionGroupDescription(t *testing.T) { } func TestAccRDSOptionGroup_basicDestroyWithInstance(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_db_option_group.test" diff --git a/internal/service/rds/orderable_instance_data_source_test.go b/internal/service/rds/orderable_instance_data_source_test.go index 586dea7dd56..867337cc444 100644 --- a/internal/service/rds/orderable_instance_data_source_test.go +++ b/internal/service/rds/orderable_instance_data_source_test.go @@ -38,6 +38,10 @@ func TestAccRDSOrderableInstanceDataSource_basic(t *testing.T) { } func TestAccRDSOrderableInstanceDataSource_preferredClass(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + dataSourceName := "data.aws_rds_orderable_db_instance.test" preferredClass := "db.t3.micro" @@ -58,6 +62,10 @@ func TestAccRDSOrderableInstanceDataSource_preferredClass(t *testing.T) { } func TestAccRDSOrderableInstanceDataSource_preferredVersion(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + dataSourceName := "data.aws_rds_orderable_db_instance.test" resource.ParallelTest(t, resource.TestCase{ @@ -77,6 +85,10 @@ func TestAccRDSOrderableInstanceDataSource_preferredVersion(t *testing.T) { } func TestAccRDSOrderableInstanceDataSource_preferredClassAndVersion(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + dataSourceName := "data.aws_rds_orderable_db_instance.test" resource.ParallelTest(t, resource.TestCase{ @@ -97,6 +109,10 @@ func TestAccRDSOrderableInstanceDataSource_preferredClassAndVersion(t *testing.T } func TestAccRDSOrderableInstanceDataSource_supportsEnhancedMonitoring(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + dataSourceName := "data.aws_rds_orderable_db_instance.test" resource.ParallelTest(t, resource.TestCase{ @@ -116,6 +132,10 @@ func TestAccRDSOrderableInstanceDataSource_supportsEnhancedMonitoring(t *testing } func TestAccRDSOrderableInstanceDataSource_supportsIAMDatabaseAuthentication(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + dataSourceName := "data.aws_rds_orderable_db_instance.test" resource.ParallelTest(t, resource.TestCase{ @@ -135,6 +155,10 @@ func TestAccRDSOrderableInstanceDataSource_supportsIAMDatabaseAuthentication(t * } func TestAccRDSOrderableInstanceDataSource_supportsIops(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + dataSourceName := "data.aws_rds_orderable_db_instance.test" resource.ParallelTest(t, resource.TestCase{ @@ -154,6 +178,10 @@ func TestAccRDSOrderableInstanceDataSource_supportsIops(t *testing.T) { } func TestAccRDSOrderableInstanceDataSource_supportsKerberosAuthentication(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + dataSourceName := "data.aws_rds_orderable_db_instance.test" resource.ParallelTest(t, resource.TestCase{ @@ -173,6 +201,10 @@ func TestAccRDSOrderableInstanceDataSource_supportsKerberosAuthentication(t *tes } func TestAccRDSOrderableInstanceDataSource_supportsPerformanceInsights(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + dataSourceName := "data.aws_rds_orderable_db_instance.test" resource.ParallelTest(t, resource.TestCase{ @@ -196,6 +228,10 @@ func TestAccRDSOrderableInstanceDataSource_supportsPerformanceInsights(t *testin } func TestAccRDSOrderableInstanceDataSource_supportsStorageAutoScaling(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + dataSourceName := "data.aws_rds_orderable_db_instance.test" resource.ParallelTest(t, resource.TestCase{ @@ -215,6 +251,10 @@ func TestAccRDSOrderableInstanceDataSource_supportsStorageAutoScaling(t *testing } func TestAccRDSOrderableInstanceDataSource_supportsStorageEncryption(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + dataSourceName := "data.aws_rds_orderable_db_instance.test" resource.ParallelTest(t, resource.TestCase{ diff --git a/internal/service/rds/proxy_data_source_test.go b/internal/service/rds/proxy_data_source_test.go index 20059796af2..a0c3fc654d0 100644 --- a/internal/service/rds/proxy_data_source_test.go +++ b/internal/service/rds/proxy_data_source_test.go @@ -11,6 +11,10 @@ import ( ) func TestAccRDSProxyDataSource_basic(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + dataSourceName := "data.aws_db_proxy.test" resourceName := "aws_db_proxy.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) diff --git a/internal/service/rds/proxy_default_target_group_test.go b/internal/service/rds/proxy_default_target_group_test.go index 2b32dfea5c8..fb7c9558837 100644 --- a/internal/service/rds/proxy_default_target_group_test.go +++ b/internal/service/rds/proxy_default_target_group_test.go @@ -17,6 +17,10 @@ import ( ) func TestAccRDSProxyDefaultTargetGroup_basic(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbProxyTargetGroup rds.DBProxyTargetGroup resourceName := "aws_db_proxy_default_target_group.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -52,6 +56,10 @@ func TestAccRDSProxyDefaultTargetGroup_basic(t *testing.T) { } func TestAccRDSProxyDefaultTargetGroup_emptyConnectionPool(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbProxyTargetGroup rds.DBProxyTargetGroup resourceName := "aws_db_proxy_default_target_group.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -87,6 +95,10 @@ func TestAccRDSProxyDefaultTargetGroup_emptyConnectionPool(t *testing.T) { } func TestAccRDSProxyDefaultTargetGroup_connectionBorrowTimeout(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbProxyTargetGroup rds.DBProxyTargetGroup resourceName := "aws_db_proxy_default_target_group.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -121,6 +133,10 @@ func TestAccRDSProxyDefaultTargetGroup_connectionBorrowTimeout(t *testing.T) { } func TestAccRDSProxyDefaultTargetGroup_initQuery(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbProxyTargetGroup rds.DBProxyTargetGroup resourceName := "aws_db_proxy_default_target_group.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -155,6 +171,10 @@ func TestAccRDSProxyDefaultTargetGroup_initQuery(t *testing.T) { } func TestAccRDSProxyDefaultTargetGroup_maxConnectionsPercent(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbProxyTargetGroup rds.DBProxyTargetGroup resourceName := "aws_db_proxy_default_target_group.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -189,6 +209,10 @@ func TestAccRDSProxyDefaultTargetGroup_maxConnectionsPercent(t *testing.T) { } func TestAccRDSProxyDefaultTargetGroup_maxIdleConnectionsPercent(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbProxyTargetGroup rds.DBProxyTargetGroup resourceName := "aws_db_proxy_default_target_group.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -223,6 +247,10 @@ func TestAccRDSProxyDefaultTargetGroup_maxIdleConnectionsPercent(t *testing.T) { } func TestAccRDSProxyDefaultTargetGroup_sessionPinningFilters(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbProxyTargetGroup rds.DBProxyTargetGroup resourceName := "aws_db_proxy_default_target_group.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -259,6 +287,10 @@ func TestAccRDSProxyDefaultTargetGroup_sessionPinningFilters(t *testing.T) { } func TestAccRDSProxyDefaultTargetGroup_disappears(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var v rds.DBProxy dbProxyResourceName := "aws_db_proxy.test" resourceName := "aws_db_proxy_default_target_group.test" diff --git a/internal/service/rds/proxy_endpoint_test.go b/internal/service/rds/proxy_endpoint_test.go index 4950ec2fb32..cbd7fb9a7fc 100644 --- a/internal/service/rds/proxy_endpoint_test.go +++ b/internal/service/rds/proxy_endpoint_test.go @@ -16,6 +16,10 @@ import ( ) func TestAccRDSProxyEndpoint_basic(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var v rds.DBProxyEndpoint resourceName := "aws_db_proxy_endpoint.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -54,6 +58,10 @@ func TestAccRDSProxyEndpoint_basic(t *testing.T) { } func TestAccRDSProxyEndpoint_targetRole(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var v rds.DBProxyEndpoint resourceName := "aws_db_proxy_endpoint.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -81,6 +89,10 @@ func TestAccRDSProxyEndpoint_targetRole(t *testing.T) { } func TestAccRDSProxyEndpoint_vpcSecurityGroupIDs(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbProxy rds.DBProxyEndpoint resourceName := "aws_db_proxy_endpoint.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -118,6 +130,10 @@ func TestAccRDSProxyEndpoint_vpcSecurityGroupIDs(t *testing.T) { } func TestAccRDSProxyEndpoint_tags(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbProxy rds.DBProxyEndpoint resourceName := "aws_db_proxy_endpoint.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -163,6 +179,10 @@ func TestAccRDSProxyEndpoint_tags(t *testing.T) { } func TestAccRDSProxyEndpoint_disappears(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var v rds.DBProxyEndpoint resourceName := "aws_db_proxy_endpoint.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -185,6 +205,10 @@ func TestAccRDSProxyEndpoint_disappears(t *testing.T) { } func TestAccRDSProxyEndpoint_Disappears_proxy(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var v rds.DBProxyEndpoint resourceName := "aws_db_proxy_endpoint.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) diff --git a/internal/service/rds/proxy_target_test.go b/internal/service/rds/proxy_target_test.go index fdff5dba7f5..130ad3287a7 100644 --- a/internal/service/rds/proxy_target_test.go +++ b/internal/service/rds/proxy_target_test.go @@ -15,6 +15,10 @@ import ( ) func TestAccRDSProxyTarget_instance(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbProxyTarget rds.DBProxyTarget resourceName := "aws_db_proxy_target.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -47,6 +51,10 @@ func TestAccRDSProxyTarget_instance(t *testing.T) { } func TestAccRDSProxyTarget_cluster(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbProxyTarget rds.DBProxyTarget resourceName := "aws_db_proxy_target.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -79,6 +87,10 @@ func TestAccRDSProxyTarget_cluster(t *testing.T) { } func TestAccRDSProxyTarget_disappears(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbProxyTarget rds.DBProxyTarget resourceName := "aws_db_proxy_target.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) diff --git a/internal/service/rds/proxy_test.go b/internal/service/rds/proxy_test.go index 54805bb5632..a82436edc39 100644 --- a/internal/service/rds/proxy_test.go +++ b/internal/service/rds/proxy_test.go @@ -17,6 +17,10 @@ import ( ) func TestAccRDSProxy_basic(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var v rds.DBProxy resourceName := "aws_db_proxy.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -59,6 +63,10 @@ func TestAccRDSProxy_basic(t *testing.T) { } func TestAccRDSProxy_name(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbProxy rds.DBProxy resourceName := "aws_db_proxy.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -94,6 +102,10 @@ func TestAccRDSProxy_name(t *testing.T) { } func TestAccRDSProxy_debugLogging(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbProxy rds.DBProxy resourceName := "aws_db_proxy.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -128,6 +140,10 @@ func TestAccRDSProxy_debugLogging(t *testing.T) { } func TestAccRDSProxy_idleClientTimeout(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbProxy rds.DBProxy resourceName := "aws_db_proxy.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -162,6 +178,10 @@ func TestAccRDSProxy_idleClientTimeout(t *testing.T) { } func TestAccRDSProxy_requireTLS(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbProxy rds.DBProxy resourceName := "aws_db_proxy.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -196,6 +216,10 @@ func TestAccRDSProxy_requireTLS(t *testing.T) { } func TestAccRDSProxy_roleARN(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbProxy rds.DBProxy resourceName := "aws_db_proxy.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -231,6 +255,10 @@ func TestAccRDSProxy_roleARN(t *testing.T) { } func TestAccRDSProxy_vpcSecurityGroupIDs(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbProxy rds.DBProxy resourceName := "aws_db_proxy.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -268,6 +296,10 @@ func TestAccRDSProxy_vpcSecurityGroupIDs(t *testing.T) { } func TestAccRDSProxy_authDescription(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbProxy rds.DBProxy resourceName := "aws_db_proxy.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -303,6 +335,10 @@ func TestAccRDSProxy_authDescription(t *testing.T) { } func TestAccRDSProxy_authIAMAuth(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbProxy rds.DBProxy resourceName := "aws_db_proxy.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -338,6 +374,10 @@ func TestAccRDSProxy_authIAMAuth(t *testing.T) { } func TestAccRDSProxy_authSecretARN(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbProxy rds.DBProxy resourceName := "aws_db_proxy.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -373,6 +413,10 @@ func TestAccRDSProxy_authSecretARN(t *testing.T) { } func TestAccRDSProxy_tags(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbProxy rds.DBProxy resourceName := "aws_db_proxy.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -409,6 +453,10 @@ func TestAccRDSProxy_tags(t *testing.T) { } func TestAccRDSProxy_disappears(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var v rds.DBProxy resourceName := "aws_db_proxy.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) diff --git a/internal/service/rds/snapshot_data_source_test.go b/internal/service/rds/snapshot_data_source_test.go index b7f386d9f4d..5dfb58744ca 100644 --- a/internal/service/rds/snapshot_data_source_test.go +++ b/internal/service/rds/snapshot_data_source_test.go @@ -12,6 +12,10 @@ import ( ) func TestAccRDSSnapshotDataSource_basic(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + rInt := sdkacctest.RandInt() resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, diff --git a/internal/service/rds/snapshot_test.go b/internal/service/rds/snapshot_test.go index 7e88039110f..845ec5b94f0 100644 --- a/internal/service/rds/snapshot_test.go +++ b/internal/service/rds/snapshot_test.go @@ -16,6 +16,10 @@ import ( ) func TestAccRDSSnapshot_basic(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var v rds.DBSnapshot resourceName := "aws_db_snapshot.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -44,6 +48,10 @@ func TestAccRDSSnapshot_basic(t *testing.T) { } func TestAccRDSSnapshot_tags(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var v rds.DBSnapshot resourceName := "aws_db_snapshot.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -89,6 +97,10 @@ func TestAccRDSSnapshot_tags(t *testing.T) { } func TestAccRDSSnapshot_disappears(t *testing.T) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var v rds.DBSnapshot rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_db_snapshot.test" From 2c8e5da31b534852a2783a4eb2eea61e6a0116e9 Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Mon, 14 Mar 2022 14:28:34 -0400 Subject: [PATCH 31/32] rds_global_cluster: Allow better config timeout use --- internal/service/rds/global_cluster.go | 26 +++++++++++++------------- internal/service/rds/wait.go | 2 -- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/internal/service/rds/global_cluster.go b/internal/service/rds/global_cluster.go index fd45ed01482..8aa476a94a1 100644 --- a/internal/service/rds/global_cluster.go +++ b/internal/service/rds/global_cluster.go @@ -224,7 +224,7 @@ func resourceGlobalClusterUpdate(d *schema.ResourceData, meta interface{}) error } if d.HasChange("engine_version") { - if err := globalClusterUpgradeEngineVersion(d, meta); err != nil { + if err := globalClusterUpgradeEngineVersion(d, meta, d.Timeout(schema.TimeoutUpdate)); err != nil { return err } } @@ -518,7 +518,7 @@ func waitForGlobalClusterRemoval(conn *rds.RDS, dbClusterIdentifier string, time return nil } -func globalClusterUpgradeMajorEngineVersion(meta interface{}, clusterID string, engineVersion string) error { +func globalClusterUpgradeMajorEngineVersion(meta interface{}, clusterID string, engineVersion string, timeout time.Duration) error { conn := meta.(*conns.AWSClient).RDSConn input := &rds.ModifyGlobalClusterInput{ @@ -528,7 +528,7 @@ func globalClusterUpgradeMajorEngineVersion(meta interface{}, clusterID string, input.AllowMajorVersionUpgrade = aws.Bool(true) input.EngineVersion = aws.String(engineVersion) - err := resource.Retry(clusterInitiateUpgradeTimeout, func() *resource.RetryError { + err := resource.Retry(timeout, func() *resource.RetryError { _, err := conn.ModifyGlobalCluster(input) if err != nil { @@ -536,7 +536,7 @@ func globalClusterUpgradeMajorEngineVersion(meta interface{}, clusterID string, return resource.NonRetryableError(err) } - if tfawserr.ErrMessageContains(err, "InvalidParameterValue", "ModifyGlobalCluster only supports Major Version Upgrades. To patch the members of your global cluster to a newer minor version you need to call ModifyDbCluster in each one of them.") { + if tfawserr.ErrMessageContains(err, "InvalidParameterValue", "only supports Major Version Upgrades") { return resource.NonRetryableError(err) } @@ -583,7 +583,7 @@ func globalClusterUpgradeMajorEngineVersion(meta interface{}, clusterID string, useConn = rds.New(meta.(*conns.AWSClient).Session, aws.NewConfig().WithRegion(clusterRegion)) } - if err := waitForClusterUpdate(useConn, dbi, clusterInitiateUpgradeTimeout); err != nil { + if err := waitForClusterUpdate(useConn, dbi, timeout); err != nil { return fmt.Errorf("failed to update engine_version, waiting for RDS Global Cluster (%s) to update: %s", dbi, err) } } @@ -617,7 +617,7 @@ func ClusterIDRegionFromARN(arnID string) (string, string, error) { return dbi, parsedARN.Region, nil } -func globalClusterUpgradeMinorEngineVersion(meta interface{}, clusterMembers *schema.Set, clusterID, engineVersion string) error { +func globalClusterUpgradeMinorEngineVersion(meta interface{}, clusterMembers *schema.Set, clusterID, engineVersion string, timeout time.Duration) error { conn := meta.(*conns.AWSClient).RDSConn log.Printf("[INFO] Performing RDS Global Cluster (%s) minor version (%s) upgrade", clusterID, engineVersion) @@ -657,7 +657,7 @@ func globalClusterUpgradeMinorEngineVersion(meta interface{}, clusterMembers *sc log.Printf("[INFO] Performing RDS Global Cluster (%s) Cluster (%s) minor version (%s) upgrade", clusterID, dbi, engineVersion) - err = resource.Retry(clusterInitiateUpgradeTimeout, func() *resource.RetryError { + err = resource.Retry(timeout, func() *resource.RetryError { _, err := useConn.ModifyDBCluster(modInput) if err != nil { @@ -691,7 +691,7 @@ func globalClusterUpgradeMinorEngineVersion(meta interface{}, clusterMembers *sc } log.Printf("[INFO] Waiting for RDS Global Cluster (%s) Cluster (%s) minor version (%s) upgrade", clusterID, dbi, engineVersion) - if err := waitForClusterUpdate(useConn, dbi, clusterInitiateUpgradeTimeout); err != nil { + if err := waitForClusterUpdate(useConn, dbi, timeout); err != nil { return fmt.Errorf("failed to update engine_version, waiting for RDS Global Cluster Cluster (%s) to update: %s", dbi, err) } } @@ -712,19 +712,19 @@ func globalClusterUpgradeMinorEngineVersion(meta interface{}, clusterMembers *sc if aws.StringValue(globalCluster.EngineVersion) != engineVersion { log.Printf("[DEBUG] RDS Global Cluster (%s) upgrade did not take effect, trying again", clusterID) - return globalClusterUpgradeMinorEngineVersion(meta, clusterMembers, clusterID, engineVersion) + return globalClusterUpgradeMinorEngineVersion(meta, clusterMembers, clusterID, engineVersion, timeout) } return nil } -func globalClusterUpgradeEngineVersion(d *schema.ResourceData, meta interface{}) error { +func globalClusterUpgradeEngineVersion(d *schema.ResourceData, meta interface{}, timeout time.Duration) error { log.Printf("[DEBUG] Upgrading RDS Global Cluster (%s) engine version: %s", d.Id(), d.Get("engine_version")) - err := globalClusterUpgradeMajorEngineVersion(meta, d.Id(), d.Get("engine_version").(string)) + err := globalClusterUpgradeMajorEngineVersion(meta, d.Id(), d.Get("engine_version").(string), timeout) - if tfawserr.ErrMessageContains(err, "InvalidParameterValue", "ModifyGlobalCluster only supports Major Version Upgrades. To patch the members of your global cluster to a newer minor version you need to call ModifyDbCluster in each one of them.") { - err = globalClusterUpgradeMinorEngineVersion(meta, d.Get("global_cluster_members").(*schema.Set), d.Id(), d.Get("engine_version").(string)) + if tfawserr.ErrMessageContains(err, "InvalidParameterValue", "only supports Major Version Upgrades") { + err = globalClusterUpgradeMinorEngineVersion(meta, d.Get("global_cluster_members").(*schema.Set), d.Id(), d.Get("engine_version").(string), timeout) if err != nil { return fmt.Errorf("while upgrading minor version of RDS Global Cluster (%s): %w", d.Id(), err) diff --git a/internal/service/rds/wait.go b/internal/service/rds/wait.go index 2450b406f6a..6751a4d048d 100644 --- a/internal/service/rds/wait.go +++ b/internal/service/rds/wait.go @@ -8,8 +8,6 @@ import ( ) const ( - clusterInitiateUpgradeTimeout = 30 * time.Minute - dbClusterRoleAssociationCreatedTimeout = 5 * time.Minute dbClusterRoleAssociationDeletedTimeout = 5 * time.Minute ) From f539a8c1db7afa84e1c1c7f42e7e88ab7835b837 Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Mon, 14 Mar 2022 14:31:59 -0400 Subject: [PATCH 32/32] rds_global_cluster: Increase update default timeout --- internal/service/rds/global_cluster.go | 2 +- website/docs/r/rds_global_cluster.html.markdown | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/service/rds/global_cluster.go b/internal/service/rds/global_cluster.go index 8aa476a94a1..a2d98929268 100644 --- a/internal/service/rds/global_cluster.go +++ b/internal/service/rds/global_cluster.go @@ -21,7 +21,7 @@ import ( const ( GlobalClusterRemovalTimeout = 30 * time.Minute globalClusterCreateTimeout = 30 * time.Minute - globalClusterUpdateTimeout = 60 * time.Minute + globalClusterUpdateTimeout = 90 * time.Minute ) func ResourceGlobalCluster() *schema.Resource { diff --git a/website/docs/r/rds_global_cluster.html.markdown b/website/docs/r/rds_global_cluster.html.markdown index ccb51211999..bf2cfd3c6a8 100644 --- a/website/docs/r/rds_global_cluster.html.markdown +++ b/website/docs/r/rds_global_cluster.html.markdown @@ -230,7 +230,7 @@ In addition to all arguments above, the following attributes are exported: [Timeouts](https://www.terraform.io/docs/configuration/blocks/resources/syntax.html#operation-timeouts) configuration options: - `create` - (Default `30 minutes`) -- `update` - (Default `30 minutes`) +- `update` - (Default `90 minutes`) - `delete` - (Default `30 minutes`) ## Import