diff --git a/.changelog/23560.txt b/.changelog/23560.txt new file mode 100644 index 00000000000..5787a897152 --- /dev/null +++ b/.changelog/23560.txt @@ -0,0 +1,15 @@ +```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 ability to perform cluster version upgrades, including of clusters in distinct regions, such as previously got error: "Invalid database cluster identifier" +``` + +```release-note:enhancement +resource/aws_rds_global_cluster: Add configurable timeouts +``` 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/cluster.go b/internal/service/rds/cluster.go index 16cfd9d0736..32084974fe2 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, @@ -953,8 +953,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, @@ -990,7 +989,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) } @@ -1081,7 +1080,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 { @@ -1288,7 +1287,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) } @@ -1397,7 +1396,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") { @@ -1506,7 +1505,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"}, @@ -1515,6 +1514,7 @@ func waitForRDSClusterUpdate(conn *rds.RDS, id string, timeout time.Duration) er MinTimeout: 10 * time.Second, Delay: 30 * time.Second, // Wait 30 secs before starting } + _, err := stateConf.WaitForState() return err } @@ -1534,22 +1534,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) - } - - d.Set("engine_version_actual", newVersion) -} 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/cluster_endpoint_test.go b/internal/service/rds/cluster_endpoint_test.go index 02e74881f79..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" @@ -211,7 +219,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 +259,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 +277,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 +295,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 +314,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_instance_test.go b/internal/service/rds/cluster_instance_test.go index 649138ddf61..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) @@ -656,13 +728,17 @@ 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`), }, }, }) } 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) @@ -728,13 +808,17 @@ 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`), }, }, }) } 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) @@ -838,13 +930,17 @@ 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`), }, }, }) } 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 401660d83e7..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" @@ -91,8 +95,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) }, @@ -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" @@ -144,8 +152,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) }, @@ -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" @@ -183,8 +195,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) }, @@ -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 @@ -1242,7 +1298,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 +1308,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"), @@ -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) @@ -2595,7 +2719,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 +2790,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 +3306,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 +3533,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 +3565,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" { @@ -3599,7 +3733,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/enum.go b/internal/service/rds/consts.go similarity index 100% rename from internal/service/rds/enum.go rename to internal/service/rds/consts.go 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"` +) 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 8d5806da3da..a2d98929268 100644 --- a/internal/service/rds/global_cluster.go +++ b/internal/service/rds/global_cluster.go @@ -3,9 +3,12 @@ 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/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" @@ -16,7 +19,9 @@ import ( ) const ( - rdsGlobalClusterRemovalTimeout = 2 * time.Minute + GlobalClusterRemovalTimeout = 30 * time.Minute + globalClusterCreateTimeout = 30 * time.Minute + globalClusterUpdateTimeout = 90 * time.Minute ) func ResourceGlobalCluster() *schema.Resource { @@ -29,6 +34,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 +164,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 +224,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, meta, d.Timeout(schema.TimeoutUpdate)); err != nil { return err } } @@ -229,26 +240,13 @@ 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 { - 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 @@ -281,7 +279,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 +293,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 +319,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 +412,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 +432,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 +446,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 +461,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 +483,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,19 +518,25 @@ func waitForGlobalClusterRemoval(conn *rds.RDS, dbClusterIdentifier string) erro return nil } -func resourceGlobalClusterUpgradeMajorEngineVersion(clusterId string, engineVersion string, conn *rds.RDS) error { +func globalClusterUpgradeMajorEngineVersion(meta interface{}, clusterID string, engineVersion string, timeout time.Duration) error { + conn := meta.(*conns.AWSClient).RDSConn + input := &rds.ModifyGlobalClusterInput{ - GlobalClusterIdentifier: aws.String(clusterId), + GlobalClusterIdentifier: aws.String(clusterID), } + input.AllowMajorVersionUpgrade = aws.Bool(true) input.EngineVersion = aws.String(engineVersion) - err := resource.Retry(rdsClusterInitiateUpgradeTimeout, func() *resource.RetryError { + + err := resource.Retry(timeout, 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.") { + + if tfawserr.ErrMessageContains(err, "InvalidParameterValue", "only supports Major Version Upgrades") { return resource.NonRetryableError(err) } @@ -541,73 +545,197 @@ func resourceGlobalClusterUpgradeMajorEngineVersion(clusterId string, engineVers 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, timeout); err != nil { + return fmt.Errorf("failed to update engine_version, waiting for RDS Global Cluster (%s) to update: %s", dbi, err) + } + } + return err } -func resourceGlobalClusterUpgradeMinorEngineVersion(clusterMembers *schema.Set, engineVersion string, conn *rds.RDS) 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, timeout time.Duration) 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{}) - if clusterMemberArn, ok := clusterMember["db_cluster_arn"]; ok && clusterMemberArn.(string) != "" { - modInput := &rds.ModifyDBClusterInput{ - ApplyImmediately: aws.Bool(true), - DBClusterIdentifier: aws.String(clusterMemberArn.(string)), - EngineVersion: aws.String(engineVersion), - } - err := resource.Retry(rdsClusterInitiateUpgradeTimeout, 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, rds.ErrCodeInvalidDBClusterStateFault, "Cannot modify engine version without a primary instance in DB cluster") { - return resource.NonRetryableError(err) - } - - if tfawserr.ErrCodeEquals(err, rds.ErrCodeInvalidDBClusterStateFault) { - return resource.RetryableError(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 + } + + arnID := clusterMember["db_cluster_arn"].(string) + + 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 + + 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), + } + + log.Printf("[INFO] Performing RDS Global Cluster (%s) Cluster (%s) minor version (%s) upgrade", clusterID, dbi, engineVersion) + + err = resource.Retry(timeout, 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) + } + + 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 := conn.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 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) + } + + log.Printf("[INFO] Waiting for RDS Global Cluster (%s) Cluster (%s) minor version (%s) upgrade", clusterID, dbi, engineVersion) + 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) + } } + + 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, timeout) + } + return nil } -func resourceGlobalClusterUpgradeEngineVersion(d *schema.ResourceData, conn *rds.RDS) 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 := resourceGlobalClusterUpgradeMajorEngineVersion(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 := globalClusterUpgradeMajorEngineVersion(meta, d.Id(), d.Get("engine_version").(string), timeout) + + 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 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 := waitForRDSClusterUpdate(conn, resourceGlobalClusterGetIdByARN(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 893f88d74bd..dc2c4d15892 100644 --- a/internal/service/rds/global_cluster_test.go +++ b/internal/service/rds/global_cluster_test.go @@ -11,12 +11,84 @@ 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" 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", // lintignore:AWSAT003,AWSAT005 + ExpectedID: "tf-acc-test-1467354933239945971", + 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", // 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", // lintignore:AWSAT003 + ExpectedErr: false, + }, + { + TestName: "wrong service", + 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", // lintignore:AWSAT003,AWSAT005 + 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) @@ -183,10 +255,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"), ), }, { @@ -198,7 +270,11 @@ func TestAccRDSGlobalCluster_EngineVersion_aurora(t *testing.T) { }) } -func TestAccRDSGlobalCluster_engineVersionUpdateMinor(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" @@ -210,17 +286,19 @@ 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", "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", "5.6.mysql_aurora.1.23.2"), + Config: testAccGlobalClusterWithPrimaryEngineVersionConfig(rName, "aurora-postgresql", "13.5"), 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", "13.5"), ), }, { @@ -232,7 +310,11 @@ func TestAccRDSGlobalCluster_engineVersionUpdateMinor(t *testing.T) { }) } -func TestAccRDSGlobalCluster_engineVersionUpdateMajor(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" @@ -244,18 +326,17 @@ 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.6.mysql_aurora.1.23.4"), Check: resource.ComposeTestCheckFunc( testAccCheckGlobalClusterExists(resourceName, &globalCluster1), ), }, { - Config: testAccGlobalClusterWithPrimaryEngineVersionConfig(rName, "aurora", "5.7.mysql_aurora.2.07.2"), - 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", "5.7.mysql_aurora.2.07.2"), + resource.TestCheckResourceAttr(resourceName, "engine_version", "5.7.mysql_aurora.2.10.2"), ), }, { @@ -267,6 +348,78 @@ func TestAccRDSGlobalCluster_engineVersionUpdateMajor(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 + 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-mysql", "5.7.mysql_aurora.2.07.5"), + Check: resource.ComposeTestCheckFunc( + testAccCheckGlobalClusterExists(resourceName, &globalCluster1), + ), + }, + { + 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.7.mysql_aurora.2.07.7"), + ), + }, + }, + }) +} + +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 + 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"), + ), + }, + }, + }) +} + func TestAccRDSGlobalCluster_EngineVersion_auroraMySQL(t *testing.T) { var globalCluster1 rds.GlobalCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -279,10 +432,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"), ), }, { @@ -294,7 +447,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" @@ -306,10 +459,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"), ), }, { @@ -489,7 +642,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) } } @@ -532,7 +685,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 +693,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 +702,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,27 +711,37 @@ 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) } -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 = %q - engine_version = %q - global_cluster_identifier = %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 } @@ -586,11 +749,13 @@ resource "aws_rds_cluster" "test" { apply_immediately = true allow_major_version_upgrade = true cluster_identifier = %[3]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] @@ -600,8 +765,10 @@ resource "aws_rds_cluster" "test" { resource "aws_rds_cluster_instance" "test" { apply_immediately = true cluster_identifier = aws_rds_cluster.test.id + engine = data.aws_rds_orderable_db_instance.test.engine + engine_version = data.aws_rds_orderable_db_instance.test.engine_version identifier = %[3]q - instance_class = "db.r3.large" + instance_class = data.aws_rds_orderable_db_instance.test.instance_class lifecycle { ignore_changes = [engine_version] @@ -610,12 +777,123 @@ resource "aws_rds_cluster_instance" "test" { `, engine, engineVersion, rName) } +func testAccGlobalClusterEngineVersionUpgradeMultiRegionConfig(rNameGlobal, rNamePrimary, rNameSecondary, engine, engineVersion string) string { + return acctest.ConfigCompose( + 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" { + global_cluster_identifier = %[1]q + engine = %[2]q + engine_version = %[3]q +} + +resource "aws_rds_cluster" "primary" { + allow_major_version_upgrade = true + apply_immediately = true + 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.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 = %[4]q + instance_class = "db.r4.large" +} + +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 = %[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 = [ + replication_source_identifier, + engine_version, + ] + } + + depends_on = [aws_rds_cluster_instance.primary] +} + +resource "aws_rds_cluster_instance" "secondary" { + provider = "awsalternate" + apply_immediately = true + 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" +} +`, rNameGlobal, engine, engineVersion, rNamePrimary, rNameSecondary)) +} + 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 @@ -637,10 +915,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 @@ -664,8 +946,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.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_data_source_test.go b/internal/service/rds/instance_data_source_test.go index 59164d71ac2..254aac723e1 100644 --- a/internal/service/rds/instance_data_source_test.go +++ b/internal/service/rds/instance_data_source_test.go @@ -11,32 +11,38 @@ import ( ) func TestAccRDSInstanceDataSource_basic(t *testing.T) { - rInt := sdkacctest.RandInt() + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + dataSourceName := "data.aws_db_instance.test" + 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"), - 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"), ), }, }, @@ -44,7 +50,12 @@ func TestAccRDSInstanceDataSource_basic(t *testing.T) { } func TestAccRDSInstanceDataSource_ec2Classic(t *testing.T) { - rInt := sdkacctest.RandInt() + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + dataSourceName := "data.aws_db_instance.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t); acctest.PreCheckEC2Classic(t) }, @@ -52,34 +63,57 @@ 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", ""), + resource.TestCheckResourceAttr(dataSourceName, "db_subnet_group", ""), ), }, }, }) } -func testAccInstanceDataSourceConfig(rInt int) 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"] +func testAccInstanceDataSourceConfig(rName string) string { + 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 = "datasource-test-terraform-%d" +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", @@ -91,39 +125,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 } -`, rInt) +`, rName)) } -func testAccInstanceDataSourceConfig_ec2Classic(rInt int) string { +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 = "5.6.41" + 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" { - identifier = "foobarbaz-test-terraform-%[1]d" +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.mysql5.6" + 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 } -`, rInt)) +`, rName)) } 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 0b3f177b1d4..53c4aee5c0e 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" @@ -22,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) @@ -62,8 +67,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"), @@ -91,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) @@ -161,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" @@ -173,7 +186,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), @@ -194,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-" @@ -226,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" @@ -257,9 +278,14 @@ 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" + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -268,7 +294,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), @@ -292,8 +318,13 @@ 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.RandString(10) + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_db_instance.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -304,17 +335,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)), ), }, }, @@ -322,9 +351,14 @@ 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 := fmt.Sprintf("tf-option-test-%d", sdkacctest.RandInt()) + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_db_instance.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -335,10 +369,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), ), }, }, @@ -346,7 +379,12 @@ 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) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -355,7 +393,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), @@ -368,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) @@ -410,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 @@ -467,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 @@ -493,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) @@ -535,8 +589,12 @@ 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 - rInt := sdkacctest.RandInt() + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -547,7 +605,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), ), @@ -557,7 +615,12 @@ 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) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -566,7 +629,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), ), @@ -576,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) @@ -614,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) @@ -658,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) @@ -696,7 +771,11 @@ func TestAccRDSInstance_password(t *testing.T) { }) } -func TestAccRDSInstance_replicateSourceDB_basic(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) @@ -733,7 +812,11 @@ func TestAccRDSInstance_replicateSourceDB_basic(t *testing.T) { }) } -func TestAccRDSInstance_replicateSourceDB_namePrefix(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) @@ -766,7 +849,11 @@ func TestAccRDSInstance_replicateSourceDB_namePrefix(t *testing.T) { }) } -func TestAccRDSInstance_replicateSourceDB_nameGenerated(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) @@ -798,7 +885,11 @@ func TestAccRDSInstance_replicateSourceDB_nameGenerated(t *testing.T) { }) } -func TestAccRDSInstance_replicateSourceDB_addLater(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) @@ -830,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) @@ -856,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) @@ -882,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) @@ -909,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) @@ -935,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) @@ -961,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) @@ -986,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) @@ -1012,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) @@ -1038,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 @@ -1068,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 @@ -1100,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 @@ -1178,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) @@ -1204,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) @@ -1230,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) @@ -1256,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) @@ -1282,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) @@ -1307,7 +1462,11 @@ func TestAccRDSInstance_ReplicateSourceDB_multiAZ(t *testing.T) { }) } -func TestAccRDSInstance_ReplicateSourceDB_parameterGroupName_sameSetOnBoth(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) @@ -1336,7 +1495,11 @@ func TestAccRDSInstance_ReplicateSourceDB_parameterGroupName_sameSetOnBoth(t *te }) } -func TestAccRDSInstance_ReplicateSourceDB_parameterGroupName_differentSetOnBoth(t *testing.T) { +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) @@ -1365,7 +1528,11 @@ func TestAccRDSInstance_ReplicateSourceDB_parameterGroupName_differentSetOnBoth( }) } -func TestAccRDSInstance_ReplicateSourceDB_parameterGroupName_replicaCopiesValue(t *testing.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) @@ -1393,7 +1560,11 @@ func TestAccRDSInstance_ReplicateSourceDB_parameterGroupName_replicaCopiesValue( }) } -func TestAccRDSInstance_ReplicateSourceDB_parameterGroupName_setOnReplica(t *testing.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) @@ -1421,6 +1592,10 @@ func TestAccRDSInstance_ReplicateSourceDB_parameterGroupName_setOnReplica(t *tes } 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) @@ -1447,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) @@ -1473,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) @@ -1501,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) @@ -1532,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) @@ -1569,10 +1760,9 @@ 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 - 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 +1774,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", ""), ), }, @@ -1603,10 +1793,9 @@ 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 - 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 +1807,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", ""), ), }, @@ -1637,10 +1826,10 @@ 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-" - bucket := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) bucketPrefix := sdkacctest.RandString(5) const resourceName = "aws_db_instance.test" @@ -1652,7 +1841,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), @@ -1671,9 +1860,9 @@ 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 - bucket := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) bucketPrefix := sdkacctest.RandString(5) const resourceName = "aws_db_instance.test" @@ -1685,7 +1874,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"), @@ -1705,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 @@ -1744,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) @@ -1778,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) @@ -1811,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) @@ -1844,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 @@ -1872,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 @@ -1900,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 @@ -1928,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 @@ -1956,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 @@ -1982,7 +2207,11 @@ func TestAccRDSInstance_SnapshotIdentifier_availabilityZone(t *testing.T) { }) } -func TestAccRDSInstance_SnapshotIdentifier_backupRetentionPeriod_override(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 @@ -2010,7 +2239,11 @@ func TestAccRDSInstance_SnapshotIdentifier_backupRetentionPeriod_override(t *tes }) } -func TestAccRDSInstance_SnapshotIdentifier_backupRetentionPeriod_unset(t *testing.T) { +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 @@ -2039,6 +2272,10 @@ func TestAccRDSInstance_SnapshotIdentifier_backupRetentionPeriod_unset(t *testin } 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 @@ -2067,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 @@ -2097,7 +2338,11 @@ func TestAccRDSInstance_SnapshotIdentifier_dbSubnetGroupName(t *testing.T) { }) } -func TestAccRDSInstance_SnapshotIdentifier_DBSubnetGroupName_ramShared(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 @@ -2133,7 +2378,11 @@ func TestAccRDSInstance_SnapshotIdentifier_DBSubnetGroupName_ramShared(t *testin }) } -func TestAccRDSInstance_SnapshotIdentifier_DBSubnetGroupName_vpcSecurityGroupIDs(t *testing.T) { +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 @@ -2165,6 +2414,10 @@ func TestAccRDSInstance_SnapshotIdentifier_DBSubnetGroupName_vpcSecurityGroupIDs } 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 @@ -2203,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 @@ -2231,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 @@ -2259,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 @@ -2287,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 @@ -2315,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 @@ -2342,7 +2615,11 @@ func TestAccRDSInstance_SnapshotIdentifier_multiAZ(t *testing.T) { }) } -func TestAccRDSInstance_SnapshotIdentifier_multiAZ_sqlServer(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 @@ -2371,6 +2648,10 @@ func TestAccRDSInstance_SnapshotIdentifier_multiAZ_sqlServer(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 @@ -2400,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 @@ -2428,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 @@ -2456,7 +2745,7 @@ func TestAccRDSInstance_SnapshotIdentifier_tags(t *testing.T) { }) } -func TestAccRDSInstance_SnapshotIdentifier_Tags_Clear(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") // --- 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" @@ -2489,6 +2778,10 @@ func TestAccRDSInstance_SnapshotIdentifier_Tags_Clear(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 @@ -2519,7 +2812,11 @@ 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) { + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + var dbInstance, sourceDbInstance rds.DBInstance var dbSnapshot rds.DBSnapshot @@ -2549,6 +2846,10 @@ func TestAccRDSInstance_SnapshotIdentifier_vpcSecurityGroupIDs_tags(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) @@ -2603,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" @@ -2644,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" @@ -2684,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" @@ -2727,9 +3040,13 @@ 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.RandString(5) + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -2757,9 +3074,14 @@ 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.RandString(5) + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + resourceName := "aws_db_instance.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -2768,20 +3090,18 @@ 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( - "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"), ), }, }, @@ -2789,8 +3109,13 @@ 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 - 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 +3124,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"), ), }, }, @@ -2826,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) @@ -2863,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" @@ -2891,8 +3224,14 @@ 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 - rInt := sdkacctest.RandInt() + 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,12 +3240,13 @@ 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), - 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"), ), }, }, @@ -2914,7 +3254,12 @@ 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) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -2923,7 +3268,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 +3279,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 +3289,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), ), @@ -2954,9 +3299,13 @@ 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 - rInt := sdkacctest.RandInt() + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -2965,7 +3314,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), ), @@ -2987,9 +3336,13 @@ 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" - rInt := sdkacctest.RandInt() + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -2998,7 +3351,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 +3360,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 +3370,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 +3380,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"), @@ -3038,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) @@ -3072,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) @@ -3107,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) @@ -3142,9 +3507,13 @@ 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("tf-testacc-nodelautobak") + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_db_instance.test" resource.ParallelTest(t, resource.TestCase{ @@ -3335,12 +3704,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 @@ -3494,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" @@ -3533,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" @@ -3572,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" @@ -3622,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" @@ -3663,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) @@ -3692,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 @@ -3723,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" @@ -3746,9 +4143,14 @@ 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" + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -3757,7 +4159,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), @@ -3782,9 +4184,14 @@ 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" + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(t) }, @@ -3793,7 +4200,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), @@ -3818,7 +4225,11 @@ func TestAccRDSInstance_RestoreToPointInTime_sourceResourceID(t *testing.T) { } func TestAccRDSInstance_NationalCharacterSet_oracle(t *testing.T) { - var dbInstance rds.DBInstance + 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" @@ -3853,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) @@ -4056,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" @@ -4096,54 +4515,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 +4559,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 +4585,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 +4598,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 +4619,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 +4654,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 = < len(oldVersion) { + newVersionSubstr = string([]byte(newVersion)[0 : len(oldVersion)+1]) + } + + if oldVersion != newVersion && string(append([]byte(oldVersion), []byte(".")...)) != newVersionSubstr { + d.Set("engine_version", newVersion) + } + + d.Set("engine_version_actual", newVersion) +} diff --git a/internal/service/rds/wait.go b/internal/service/rds/wait.go index a3917df1d14..6751a4d048d 100644 --- a/internal/service/rds/wait.go +++ b/internal/service/rds/wait.go @@ -8,8 +8,6 @@ import ( ) const ( - rdsClusterInitiateUpgradeTimeout = 5 * time.Minute - dbClusterRoleAssociationCreatedTimeout = 5 * time.Minute dbClusterRoleAssociationDeletedTimeout = 5 * time.Minute ) @@ -54,12 +52,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() @@ -161,11 +160,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() diff --git a/website/docs/r/rds_global_cluster.html.markdown b/website/docs/r/rds_global_cluster.html.markdown index 48aa664fd2e..bf2cfd3c6a8 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 on the `aws_rds_cluster`. + +```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. @@ -187,6 +224,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 `90 minutes`) +- `delete` - (Default `30 minutes`) + ## Import `aws_rds_global_cluster` can be imported by using the RDS Global Cluster identifier, e.g.,