diff --git a/.changelog/35698.txt b/.changelog/35698.txt new file mode 100644 index 00000000000..47da0e702e9 --- /dev/null +++ b/.changelog/35698.txt @@ -0,0 +1,15 @@ +```release-note:enhancement +data-source/aws_rds_orderable_db_instance: Improve search functionality and options by adding `engine_latest_version` and `supports_clusters` arguments and converting `read_replica_capable`, `supported_engine_modes`, `supported_network_types`, and `supports_multi_az` to arguments for use as search criteria +``` + +```release-note:enhancement +data-source/aws_rds_engine_version: Improve search functionality and options by adding `latest`, `preferred_major_targets`, and `preferred_upgrade_targets`. Add `version_actual` attribute +``` + +```release-note:new-data-source +aws_db_parameter_group +``` + +```release-note:enhancement +data-source/aws_neptune_cluster_instance: Add `skip_final_snapshot` argument +``` \ No newline at end of file diff --git a/go.mod b/go.mod index b1b9c680746..97dc71c1210 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.20 require ( github.com/ProtonMail/go-crypto v0.0.0-20230923063757-afb1ddc0824c + github.com/YakDriver/go-version v0.1.0 github.com/YakDriver/regexache v0.23.0 github.com/aws/aws-sdk-go v1.50.12 github.com/aws/aws-sdk-go-v2 v1.24.1 diff --git a/go.sum b/go.sum index ebac835437b..36be52d35a5 100644 --- a/go.sum +++ b/go.sum @@ -9,6 +9,8 @@ github.com/Masterminds/sprig/v3 v3.2.3/go.mod h1:rXcFaZ2zZbLRJv/xSysmlgIM1u11eBa github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow= github.com/ProtonMail/go-crypto v0.0.0-20230923063757-afb1ddc0824c h1:kMFnB0vCcX7IL/m9Y5LO+KQYv+t1CQOiFe6+SV2J7bE= github.com/ProtonMail/go-crypto v0.0.0-20230923063757-afb1ddc0824c/go.mod h1:EjAoLdwvbIOoOQr3ihjnSoLZRtE8azugULFRteWMNc0= +github.com/YakDriver/go-version v0.1.0 h1:/x+Xg2+l89Mjtxl0VRf2+ue8cnHkw6jfYv49j6f7gZw= +github.com/YakDriver/go-version v0.1.0/go.mod h1:LXwFAp1E3KBhS7FHO/FE8r3XCmvKizs/VXXXFWfoSYY= github.com/YakDriver/regexache v0.23.0 h1:kv3j4XKhbx/vqUilSBgizXDUXHvvH1KdYekdmGwz4C4= github.com/YakDriver/regexache v0.23.0/go.mod h1:K4BZ3MYKAqSFbYWqmbsG+OzYUDyJjnMEr27DJEsVG3U= github.com/agext/levenshtein v1.2.3 h1:YB2fHEn0UJagG8T1rrWknE3ZQzWM06O8AMAatNn7lmo= diff --git a/internal/service/neptune/cluster_instance.go b/internal/service/neptune/cluster_instance.go index 352a129c885..120d6237ad1 100644 --- a/internal/service/neptune/cluster_instance.go +++ b/internal/service/neptune/cluster_instance.go @@ -166,6 +166,10 @@ func ResourceClusterInstance() *schema.Resource { Default: false, ForceNew: true, }, + "skip_final_snapshot": { + Type: schema.TypeBool, + Optional: true, + }, "storage_encrypted": { Type: schema.TypeBool, Computed: true, @@ -363,9 +367,15 @@ func resourceClusterInstanceDelete(ctx context.Context, d *schema.ResourceData, conn := meta.(*conns.AWSClient).NeptuneConn(ctx) log.Printf("[DEBUG] Deleting Neptune Cluster Instance: %s", d.Id()) - _, err := conn.DeleteDBInstanceWithContext(ctx, &neptune.DeleteDBInstanceInput{ + input := neptune.DeleteDBInstanceInput{ DBInstanceIdentifier: aws.String(d.Id()), - }) + } + + if d.Get("skip_final_snapshot").(bool) { + input.SkipFinalSnapshot = aws.Bool(true) + } + + _, err := conn.DeleteDBInstanceWithContext(ctx, &input) if tfawserr.ErrCodeEquals(err, neptune.ErrCodeDBInstanceNotFoundFault) { return diags diff --git a/internal/service/neptune/sweep.go b/internal/service/neptune/sweep.go index f4e7ce6977f..23fefe2cbea 100644 --- a/internal/service/neptune/sweep.go +++ b/internal/service/neptune/sweep.go @@ -304,6 +304,7 @@ func sweepClusterInstances(region string) error { d := r.Data(nil) d.SetId(id) d.Set("apply_immediately", true) + d.Set("skip_final_snapshot", true) sweepResources = append(sweepResources, sweep.NewSweepResource(r, d, client)) } diff --git a/internal/service/rds/cluster_test.go b/internal/service/rds/cluster_test.go index ab6c427f671..016b6db7e4d 100644 --- a/internal/service/rds/cluster_test.go +++ b/internal/service/rds/cluster_test.go @@ -36,6 +36,7 @@ func testAccClusterImportStep(n string) resource.TestStep { ImportStateVerifyIgnore: []string{ "allow_major_version_upgrade", "apply_immediately", + "cluster_members", "db_instance_parameter_group_name", "enable_global_write_forwarding", "manage_master_user_password", @@ -82,7 +83,7 @@ func TestAccRDSCluster_basic(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "db_system_id", ""), resource.TestCheckResourceAttr(resourceName, "delete_automated_backups", "true"), resource.TestCheckResourceAttr(resourceName, "enabled_cloudwatch_logs_exports.#", "0"), - resource.TestCheckResourceAttr(resourceName, "engine", "aurora-mysql"), + resource.TestCheckResourceAttr(resourceName, "engine", tfrds.ClusterEngineAuroraMySQL), resource.TestCheckResourceAttrSet(resourceName, "engine_version"), resource.TestCheckResourceAttr(resourceName, "global_cluster_identifier", ""), resource.TestCheckResourceAttrSet(resourceName, "hosted_zone_id"), @@ -221,12 +222,8 @@ func TestAccRDSCluster_allowMajorVersionUpgrade(t *testing.T) { var dbCluster1, dbCluster2 rds.DBCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_rds_cluster.test" - // If these hardcoded versions become a maintenance burden, use DescribeDBEngineVersions - // either by having a new data source created or implementing the testing similar - // to TestAccDMSReplicationInstance_engineVersion - engine := "aurora-postgresql" - engineVersion1 := "12.9" - engineVersion2 := "13.5" + dataSourceName := "data.aws_rds_engine_version.test" + dataSourceNameUpgrade := "data.aws_rds_engine_version.upgrade" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, @@ -235,22 +232,22 @@ func TestAccRDSCluster_allowMajorVersionUpgrade(t *testing.T) { CheckDestroy: testAccCheckClusterDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccClusterConfig_allowMajorVersionUpgrade(rName, true, engine, engineVersion1, true), + Config: testAccClusterConfig_allowMajorVersionUpgrade(rName, tfrds.ClusterEngineAuroraPostgreSQL, false, true), Check: resource.ComposeTestCheckFunc( testAccCheckClusterExists(ctx, resourceName, &dbCluster1), resource.TestCheckResourceAttr(resourceName, "allow_major_version_upgrade", "true"), - resource.TestCheckResourceAttr(resourceName, "engine", engine), - resource.TestCheckResourceAttr(resourceName, "engine_version", engineVersion1), + resource.TestCheckResourceAttr(resourceName, "engine", tfrds.ClusterEngineAuroraPostgreSQL), + resource.TestCheckResourceAttrPair(resourceName, "engine_version", dataSourceName, "version_actual"), ), }, testAccClusterImportStep(resourceName), { - Config: testAccClusterConfig_allowMajorVersionUpgrade(rName, true, engine, engineVersion2, true), + Config: testAccClusterConfig_allowMajorVersionUpgrade(rName, tfrds.ClusterEngineAuroraPostgreSQL, true, true), Check: resource.ComposeTestCheckFunc( testAccCheckClusterExists(ctx, resourceName, &dbCluster2), resource.TestCheckResourceAttr(resourceName, "allow_major_version_upgrade", "true"), - resource.TestCheckResourceAttr(resourceName, "engine", engine), - resource.TestCheckResourceAttr(resourceName, "engine_version", engineVersion2), + resource.TestCheckResourceAttr(resourceName, "engine", tfrds.ClusterEngineAuroraPostgreSQL), + resource.TestCheckResourceAttrPair(resourceName, "engine_version", dataSourceNameUpgrade, "version_actual"), ), }, }, @@ -266,12 +263,8 @@ func TestAccRDSCluster_allowMajorVersionUpgradeNoApplyImmediately(t *testing.T) var dbCluster1, dbCluster2 rds.DBCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_rds_cluster.test" - // If these hardcoded versions become a maintenance burden, use DescribeDBEngineVersions - // either by having a new data source created or implementing the testing similar - // to TestAccDMSReplicationInstance_engineVersion - engine := "aurora-postgresql" - engineVersion1 := "12.9" - engineVersion2 := "13.5" + dataSourceName := "data.aws_rds_engine_version.test" + dataSourceNameUpgrade := "data.aws_rds_engine_version.upgrade" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, @@ -280,22 +273,22 @@ func TestAccRDSCluster_allowMajorVersionUpgradeNoApplyImmediately(t *testing.T) CheckDestroy: testAccCheckClusterDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccClusterConfig_allowMajorVersionUpgrade(rName, true, engine, engineVersion1, false), + Config: testAccClusterConfig_allowMajorVersionUpgrade(rName, tfrds.ClusterEngineAuroraPostgreSQL, false, false), Check: resource.ComposeTestCheckFunc( testAccCheckClusterExists(ctx, resourceName, &dbCluster1), resource.TestCheckResourceAttr(resourceName, "allow_major_version_upgrade", "true"), - resource.TestCheckResourceAttr(resourceName, "engine", engine), - resource.TestCheckResourceAttr(resourceName, "engine_version", engineVersion1), + resource.TestCheckResourceAttr(resourceName, "engine", tfrds.ClusterEngineAuroraPostgreSQL), + resource.TestCheckResourceAttrPair(resourceName, "engine_version", dataSourceName, "version_actual"), ), }, testAccClusterImportStep(resourceName), { - Config: testAccClusterConfig_allowMajorVersionUpgrade(rName, true, engine, engineVersion2, false), + Config: testAccClusterConfig_allowMajorVersionUpgrade(rName, tfrds.ClusterEngineAuroraPostgreSQL, true, false), Check: resource.ComposeTestCheckFunc( testAccCheckClusterExists(ctx, resourceName, &dbCluster2), resource.TestCheckResourceAttr(resourceName, "allow_major_version_upgrade", "true"), - resource.TestCheckResourceAttr(resourceName, "engine", engine), - resource.TestCheckResourceAttr(resourceName, "engine_version", engineVersion2), + resource.TestCheckResourceAttr(resourceName, "engine", tfrds.ClusterEngineAuroraPostgreSQL), + resource.TestCheckResourceAttrPair(resourceName, "engine_version", dataSourceNameUpgrade, "version_actual"), ), }, }, @@ -311,12 +304,6 @@ func TestAccRDSCluster_allowMajorVersionUpgradeWithCustomParametersApplyImm(t *t var dbCluster1, dbCluster2 rds.DBCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_rds_cluster.test" - // If these hardcoded versions become a maintenance burden, use DescribeDBEngineVersions - // either by having a new data source created or implementing the testing similar - // to TestAccDMSReplicationInstance_engineVersion - engine := "aurora-postgresql" - engineVersion1 := "12.9" - engineVersion2 := "13.5" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, @@ -325,21 +312,21 @@ func TestAccRDSCluster_allowMajorVersionUpgradeWithCustomParametersApplyImm(t *t CheckDestroy: testAccCheckClusterDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccClusterConfig_allowMajorVersionUpgradeCustomParameters(rName, true, engine, engineVersion1, true), + Config: testAccClusterConfig_allowMajorVersionUpgradeCustomParameters(rName, false, tfrds.ClusterEngineAuroraPostgreSQL, true), Check: resource.ComposeTestCheckFunc( testAccCheckClusterExists(ctx, resourceName, &dbCluster1), resource.TestCheckResourceAttr(resourceName, "allow_major_version_upgrade", "true"), - resource.TestCheckResourceAttr(resourceName, "engine", engine), - resource.TestCheckResourceAttr(resourceName, "engine_version", engineVersion1), + resource.TestCheckResourceAttr(resourceName, "engine", tfrds.ClusterEngineAuroraPostgreSQL), + resource.TestCheckResourceAttrPair(resourceName, "engine_version", "data.aws_rds_engine_version.test", "version_actual"), ), }, { - Config: testAccClusterConfig_allowMajorVersionUpgradeCustomParameters(rName, true, engine, engineVersion2, true), + Config: testAccClusterConfig_allowMajorVersionUpgradeCustomParameters(rName, true, tfrds.ClusterEngineAuroraPostgreSQL, true), Check: resource.ComposeTestCheckFunc( testAccCheckClusterExists(ctx, resourceName, &dbCluster2), resource.TestCheckResourceAttr(resourceName, "allow_major_version_upgrade", "true"), - resource.TestCheckResourceAttr(resourceName, "engine", engine), - resource.TestCheckResourceAttr(resourceName, "engine_version", engineVersion2), + resource.TestCheckResourceAttr(resourceName, "engine", tfrds.ClusterEngineAuroraPostgreSQL), + resource.TestCheckResourceAttrPair(resourceName, "engine_version", "data.aws_rds_engine_version.upgrade", "version_actual"), ), }, }, @@ -355,12 +342,6 @@ func TestAccRDSCluster_allowMajorVersionUpgradeWithCustomParameters(t *testing.T var dbCluster1, dbCluster2 rds.DBCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_rds_cluster.test" - // If these hardcoded versions become a maintenance burden, use DescribeDBEngineVersions - // either by having a new data source created or implementing the testing similar - // to TestAccDMSReplicationInstance_engineVersion - engine := "aurora-postgresql" - engineVersion1 := "12.9" - engineVersion2 := "13.5" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, @@ -369,22 +350,22 @@ func TestAccRDSCluster_allowMajorVersionUpgradeWithCustomParameters(t *testing.T CheckDestroy: testAccCheckClusterDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccClusterConfig_allowMajorVersionUpgradeCustomParameters(rName, true, engine, engineVersion1, false), + Config: testAccClusterConfig_allowMajorVersionUpgradeCustomParameters(rName, false, tfrds.ClusterEngineAuroraPostgreSQL, false), Check: resource.ComposeTestCheckFunc( testAccCheckClusterExists(ctx, resourceName, &dbCluster1), resource.TestCheckResourceAttr(resourceName, "allow_major_version_upgrade", "true"), - resource.TestCheckResourceAttr(resourceName, "engine", engine), - resource.TestCheckResourceAttr(resourceName, "engine_version", engineVersion1), + resource.TestCheckResourceAttr(resourceName, "engine", tfrds.ClusterEngineAuroraPostgreSQL), + resource.TestCheckResourceAttrPair(resourceName, "engine_version", "data.aws_rds_engine_version.test", "version_actual"), ), }, testAccClusterImportStep(resourceName), { - Config: testAccClusterConfig_allowMajorVersionUpgradeCustomParameters(rName, true, engine, engineVersion2, false), + Config: testAccClusterConfig_allowMajorVersionUpgradeCustomParameters(rName, true, tfrds.ClusterEngineAuroraPostgreSQL, false), Check: resource.ComposeTestCheckFunc( testAccCheckClusterExists(ctx, resourceName, &dbCluster2), resource.TestCheckResourceAttr(resourceName, "allow_major_version_upgrade", "true"), - resource.TestCheckResourceAttr(resourceName, "engine", engine), - resource.TestCheckResourceAttr(resourceName, "engine_version", engineVersion2), + resource.TestCheckResourceAttr(resourceName, "engine", tfrds.ClusterEngineAuroraPostgreSQL), + resource.TestCheckResourceAttrPair(resourceName, "engine_version", "data.aws_rds_engine_version.upgrade", "version_actual"), ), }, }, @@ -400,11 +381,7 @@ func TestAccRDSCluster_onlyMajorVersion(t *testing.T) { var dbCluster1 rds.DBCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_rds_cluster.test" - // If these hardcoded versions become a maintenance burden, use DescribeDBEngineVersions - // either by having a new data source created or implementing the testing similar - // to TestAccDMSReplicationInstance_engineVersion - engine := "aurora-postgresql" - engineVersion1 := "11" + dataSourceName := "data.aws_rds_engine_version.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, @@ -413,11 +390,11 @@ func TestAccRDSCluster_onlyMajorVersion(t *testing.T) { CheckDestroy: testAccCheckClusterDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccClusterConfig_majorVersionOnly(rName, false, engine, engineVersion1), + Config: testAccClusterConfig_majorVersionOnly(rName, tfrds.ClusterEngineAuroraPostgreSQL, false), Check: resource.ComposeTestCheckFunc( testAccCheckClusterExists(ctx, resourceName, &dbCluster1), - resource.TestCheckResourceAttr(resourceName, "engine", engine), - resource.TestCheckResourceAttr(resourceName, "engine_version", engineVersion1), + resource.TestCheckResourceAttr(resourceName, "engine", tfrds.ClusterEngineAuroraPostgreSQL), + resource.TestCheckResourceAttrPair(resourceName, "engine_version", dataSourceName, "version_actual"), ), }, { @@ -428,6 +405,7 @@ func TestAccRDSCluster_onlyMajorVersion(t *testing.T) { "allow_major_version_upgrade", "apply_immediately", "cluster_identifier_prefix", + "cluster_members", "db_instance_parameter_group_name", "enable_global_write_forwarding", "engine_version", @@ -449,12 +427,6 @@ func TestAccRDSCluster_minorVersion(t *testing.T) { var dbCluster1, dbCluster2 rds.DBCluster rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_rds_cluster.test" - // If these hardcoded versions become a maintenance burden, use DescribeDBEngineVersions - // either by having a new data source created or implementing the testing similar - // to TestAccDMSReplicationInstance_engineVersion - engine := "aurora-postgresql" - engineVersion1 := "14.6" - engineVersion2 := "14.7" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, @@ -463,19 +435,19 @@ func TestAccRDSCluster_minorVersion(t *testing.T) { CheckDestroy: testAccCheckClusterDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccClusterConfig_minorVersion(rName, engine, engineVersion1, "aurora-postgresql14"), + Config: testAccClusterConfig_minorVersion(rName, tfrds.ClusterEngineAuroraPostgreSQL, false), Check: resource.ComposeTestCheckFunc( testAccCheckClusterExists(ctx, resourceName, &dbCluster1), - resource.TestCheckResourceAttr(resourceName, "engine", engine), - resource.TestCheckResourceAttr(resourceName, "engine_version", engineVersion1), + resource.TestCheckResourceAttr(resourceName, "engine", tfrds.ClusterEngineAuroraPostgreSQL), + resource.TestCheckResourceAttrPair(resourceName, "engine_version", "data.aws_rds_engine_version.test", "version_actual"), ), }, { - Config: testAccClusterConfig_minorVersion(rName, engine, engineVersion2, "aurora-postgresql14"), + Config: testAccClusterConfig_minorVersion(rName, tfrds.ClusterEngineAuroraPostgreSQL, true), Check: resource.ComposeTestCheckFunc( testAccCheckClusterExists(ctx, resourceName, &dbCluster2), - resource.TestCheckResourceAttr(resourceName, "engine", engine), - resource.TestCheckResourceAttr(resourceName, "engine_version", engineVersion2), + resource.TestCheckResourceAttr(resourceName, "engine", tfrds.ClusterEngineAuroraPostgreSQL), + resource.TestCheckResourceAttrPair(resourceName, "engine_version", "data.aws_rds_engine_version.upgrade", "version_actual"), ), }, }, @@ -736,17 +708,17 @@ func TestAccRDSCluster_dbClusterInstanceClass(t *testing.T) { CheckDestroy: testAccCheckClusterDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccClusterConfig_dbClusterInstanceClass(rName, "db.m5d.large"), + Config: testAccClusterConfig_dbClusterInstanceClass(rName, true), Check: resource.ComposeTestCheckFunc( testAccCheckClusterExists(ctx, resourceName, &dbCluster), - resource.TestCheckResourceAttr(resourceName, "db_cluster_instance_class", "db.m5d.large"), + resource.TestCheckResourceAttrSet(resourceName, "db_cluster_instance_class"), ), }, { - Config: testAccClusterConfig_dbClusterInstanceClass(rName, "db.r6gd.large"), + Config: testAccClusterConfig_dbClusterInstanceClass(rName, false), // guaranteed to be a different instance class because the intersection of instance class lists is empty Check: resource.ComposeTestCheckFunc( testAccCheckClusterExists(ctx, resourceName, &dbCluster), - resource.TestCheckResourceAttr(resourceName, "db_cluster_instance_class", "db.r6gd.large"), + resource.TestCheckResourceAttrSet(resourceName, "db_cluster_instance_class"), ), }, }, @@ -1326,7 +1298,7 @@ func TestAccRDSCluster_engineVersion(t *testing.T) { Config: testAccClusterConfig_engineVersion(rName, false), Check: resource.ComposeTestCheckFunc( testAccCheckClusterExists(ctx, resourceName, &dbCluster), - resource.TestCheckResourceAttr(resourceName, "engine", "aurora-postgresql"), + resource.TestCheckResourceAttr(resourceName, "engine", tfrds.ClusterEngineAuroraPostgreSQL), resource.TestCheckResourceAttrPair(resourceName, "engine_version", dataSourceName, "version"), ), }, @@ -1646,7 +1618,7 @@ func TestAccRDSCluster_ManagedMasterPassword_managed(t *testing.T) { testAccCheckClusterExists(ctx, resourceName, &dbCluster), acctest.CheckResourceAttrRegionalARN(resourceName, "arn", "rds", fmt.Sprintf("cluster:%s", rName)), resource.TestCheckResourceAttrSet(resourceName, "cluster_resource_id"), - resource.TestCheckResourceAttr(resourceName, "engine", "aurora-mysql"), + resource.TestCheckResourceAttr(resourceName, "engine", tfrds.ClusterEngineAuroraMySQL), resource.TestCheckResourceAttrSet(resourceName, "engine_version"), resource.TestCheckResourceAttr(resourceName, "manage_master_user_password", "true"), resource.TestCheckResourceAttr(resourceName, "master_user_secret.#", "1"), @@ -1678,7 +1650,7 @@ func TestAccRDSCluster_ManagedMasterPassword_managedSpecificKMSKey(t *testing.T) testAccCheckClusterExists(ctx, resourceName, &dbCluster), acctest.CheckResourceAttrRegionalARN(resourceName, "arn", "rds", fmt.Sprintf("cluster:%s", rName)), resource.TestCheckResourceAttrSet(resourceName, "cluster_resource_id"), - resource.TestCheckResourceAttr(resourceName, "engine", "aurora-mysql"), + resource.TestCheckResourceAttr(resourceName, "engine", tfrds.ClusterEngineAuroraMySQL), resource.TestCheckResourceAttrSet(resourceName, "engine_version"), resource.TestCheckResourceAttr(resourceName, "manage_master_user_password", "true"), resource.TestCheckResourceAttr(resourceName, "master_user_secret.#", "1"), @@ -2681,12 +2653,12 @@ func testAccClusterConfig_basic(rName string) string { resource "aws_rds_cluster" "test" { cluster_identifier = %[1]q database_name = "test" - engine = "aurora-mysql" + engine = %[2]q master_username = "tfacctest" master_password = "avoid-plaintext-passwords" skip_final_snapshot = true } -`, rName) +`, rName, tfrds.ClusterEngineAuroraMySQL) } func testAccClusterConfig_tags1(rName, tagKey1, tagValue1 string) string { @@ -2696,14 +2668,14 @@ resource "aws_rds_cluster" "test" { database_name = "test" master_username = "tfacctest" master_password = "avoid-plaintext-passwords" - engine = "aurora-mysql" + engine = %[2]q skip_final_snapshot = true tags = { - %[2]q = %[3]q + %[3]q = %[4]q } } -`, rName, tagKey1, tagValue1) +`, rName, tfrds.ClusterEngineAuroraMySQL, tagKey1, tagValue1) } func testAccClusterConfig_tags2(rName, tagKey1, tagValue1, tagKey2, tagValue2 string) string { @@ -2713,38 +2685,38 @@ resource "aws_rds_cluster" "test" { database_name = "test" master_username = "tfacctest" master_password = "avoid-plaintext-passwords" - engine = "aurora-mysql" + engine = %[2]q skip_final_snapshot = true tags = { - %[2]q = %[3]q - %[4]q = %[5]q + %[3]q = %[4]q + %[5]q = %[6]q } } -`, rName, tagKey1, tagValue1, tagKey2, tagValue2) +`, rName, tfrds.ClusterEngineAuroraMySQL, tagKey1, tagValue1, tagKey2, tagValue2) } func testAccClusterConfig_identifierGenerated() string { - return ` + return fmt.Sprintf(` resource "aws_rds_cluster" "test" { - engine = "aurora-mysql" + engine = %[1]q master_username = "tfacctest" master_password = "avoid-plaintext-passwords" skip_final_snapshot = true } -` +`, tfrds.ClusterEngineAuroraMySQL) } func testAccClusterConfig_identifierPrefix(identifierPrefix string) string { return fmt.Sprintf(` resource "aws_rds_cluster" "test" { cluster_identifier_prefix = %[1]q - engine = "aurora-mysql" + engine = %[2]q master_username = "tfacctest" master_password = "avoid-plaintext-passwords" skip_final_snapshot = true } -`, identifierPrefix) +`, identifierPrefix, tfrds.ClusterEngineAuroraMySQL) } func testAccClusterConfig_managedMasterPassword(rName string) string { @@ -2754,10 +2726,10 @@ resource "aws_rds_cluster" "test" { database_name = "test" manage_master_user_password = true master_username = "tfacctest" - engine = "aurora-mysql" + engine = %[2]q skip_final_snapshot = true } -`, rName) +`, rName, tfrds.ClusterEngineAuroraMySQL) } func testAccClusterConfig_managedMasterPasswordKMSKey(rName string) string { @@ -2791,71 +2763,100 @@ resource "aws_kms_key" "example" { resource "aws_rds_cluster" "test" { cluster_identifier = %[1]q database_name = "test" - engine = "aurora-mysql" + engine = %[2]q manage_master_user_password = true master_username = "tfacctest" master_user_secret_kms_key_id = aws_kms_key.example.arn skip_final_snapshot = true } -`, rName) +`, rName, tfrds.ClusterEngineAuroraMySQL) } -func testAccClusterConfig_allowMajorVersionUpgrade(rName string, allowMajorVersionUpgrade bool, engine string, engineVersion string, applyImmediately bool) string { +func testAccClusterConfig_allowMajorVersionUpgrade(rName string, engine string, upgrade, applyImmediately bool) string { return fmt.Sprintf(` +data "aws_rds_engine_version" "test" { + engine = data.aws_rds_engine_version.upgrade.engine + latest = true + preferred_major_targets = [data.aws_rds_engine_version.upgrade.version_actual] +} + +data "aws_rds_engine_version" "upgrade" { + engine = %[1]q +} + +locals { + engine_version = %[2]t ? data.aws_rds_engine_version.upgrade.version_actual : data.aws_rds_engine_version.test.version_actual +} + +data "aws_rds_orderable_db_instance" "test" { + engine = data.aws_rds_engine_version.test.engine + engine_version = local.engine_version + preferred_instance_classes = [%[3]s] +} + resource "aws_rds_cluster" "test" { - allow_major_version_upgrade = %[1]t - apply_immediately = %[5]t - cluster_identifier = %[2]q - engine = %[3]q - engine_version = %[4]q + allow_major_version_upgrade = true + apply_immediately = %[4]t + cluster_identifier = %[5]q + engine = data.aws_rds_engine_version.test.engine + engine_version = local.engine_version master_password = "avoid-plaintext-passwords" master_username = "tfacctest" skip_final_snapshot = true } -data "aws_rds_orderable_db_instance" "test" { - engine = aws_rds_cluster.test.engine - engine_version = aws_rds_cluster.test.engine_version - preferred_instance_classes = ["db.t3.medium", "db.r5.large", "db.r4.large"] -} - # Upgrading requires a healthy primary instance resource "aws_rds_cluster_instance" "test" { - apply_immediately = %[5]t + apply_immediately = %[4]t cluster_identifier = aws_rds_cluster.test.id - engine = data.aws_rds_orderable_db_instance.test.engine + engine = data.aws_rds_engine_version.test.engine engine_version = data.aws_rds_orderable_db_instance.test.engine_version - identifier = %[2]q + identifier = %[5]q instance_class = data.aws_rds_orderable_db_instance.test.instance_class lifecycle { ignore_changes = [engine_version] } } -`, allowMajorVersionUpgrade, rName, engine, engineVersion, applyImmediately) +`, engine, upgrade, mainInstanceClasses, applyImmediately, rName) } -func testAccClusterConfig_allowMajorVersionUpgradeCustomParameters(rName string, allowMajorVersionUpgrade bool, engine string, engineVersion string, applyImmediate bool) string { +func testAccClusterConfig_allowMajorVersionUpgradeCustomParameters(rName string, upgrade bool, engine string, applyImmediate bool) string { return fmt.Sprintf(` +data "aws_rds_engine_version" "test" { + engine = data.aws_rds_engine_version.upgrade.engine + latest = true + preferred_major_targets = [data.aws_rds_engine_version.upgrade.version_actual] +} + +data "aws_rds_engine_version" "upgrade" { + engine = %[1]q +} + +locals { + parameter_group_family = %[2]t ? data.aws_rds_engine_version.upgrade.parameter_group_family : data.aws_rds_engine_version.test.parameter_group_family + engine_version = %[2]t ? data.aws_rds_engine_version.upgrade.version_actual : data.aws_rds_engine_version.test.version_actual +} + +data "aws_rds_orderable_db_instance" "test" { + engine = data.aws_rds_engine_version.test.engine + engine_version = local.engine_version + preferred_instance_classes = [%[3]s] +} + resource "aws_rds_cluster" "test" { - allow_major_version_upgrade = %[1]t + allow_major_version_upgrade = true apply_immediately = true - cluster_identifier = %[2]q + cluster_identifier = %[4]q db_cluster_parameter_group_name = aws_rds_cluster_parameter_group.test.name db_instance_parameter_group_name = aws_db_parameter_group.test.name - engine = %[3]q - engine_version = %[4]q + engine = data.aws_rds_engine_version.test.engine + engine_version = local.engine_version master_password = "mustbeeightcharaters" master_username = "test" skip_final_snapshot = true } -data "aws_rds_orderable_db_instance" "test" { - engine = aws_rds_cluster.test.engine - engine_version = aws_rds_cluster.test.engine_version - preferred_instance_classes = ["db.t3.medium", "db.r5.large", "db.r6g.large"] -} - # Upgrading requires a healthy primary instance resource "aws_rds_cluster_instance" "test" { apply_immediately = %[5]t @@ -2863,7 +2864,7 @@ resource "aws_rds_cluster_instance" "test" { db_parameter_group_name = aws_db_parameter_group.test.name engine = data.aws_rds_orderable_db_instance.test.engine engine_version = data.aws_rds_orderable_db_instance.test.engine_version - identifier = %[2]q + identifier = %[4]q instance_class = data.aws_rds_orderable_db_instance.test.instance_class lifecycle { @@ -2872,8 +2873,8 @@ resource "aws_rds_cluster_instance" "test" { } resource "aws_rds_cluster_parameter_group" "test" { - name_prefix = %[2]q - family = %[6]q + name_prefix = %[4]q + family = local.parameter_group_family lifecycle { create_before_destroy = true @@ -2881,24 +2882,40 @@ resource "aws_rds_cluster_parameter_group" "test" { } resource "aws_db_parameter_group" "test" { - name_prefix = %[2]q - family = %[6]q + name_prefix = %[4]q + family = local.parameter_group_family lifecycle { create_before_destroy = true } } -`, allowMajorVersionUpgrade, rName, engine, engineVersion, applyImmediate, engine+strings.Split(engineVersion, ".")[0]) +`, engine, upgrade, mainInstanceClasses, rName, applyImmediate) } -func testAccClusterConfig_majorVersionOnly(rName string, allowMajorVersionUpgrade bool, engine string, engineVersion string) string { +func testAccClusterConfig_majorVersionOnly(rName string, engine string, allowMajorVersionUpgrade bool) string { return fmt.Sprintf(` +data "aws_rds_engine_version" "test" { + engine = data.aws_rds_engine_version.upgrade.engine + latest = true + preferred_major_targets = [data.aws_rds_engine_version.upgrade.version_actual] +} + +data "aws_rds_engine_version" "upgrade" { + engine = %[1]q +} + +data "aws_rds_orderable_db_instance" "test" { + engine = data.aws_rds_engine_version.test.engine + engine_version = data.aws_rds_engine_version.test.version_actual + preferred_instance_classes = [%[2]s] +} + resource "aws_rds_cluster" "test" { - allow_major_version_upgrade = %[1]t + allow_major_version_upgrade = %[3]t apply_immediately = true - cluster_identifier = %[2]q - engine = %[3]q - engine_version = %[4]q + cluster_identifier = %[4]q + engine = data.aws_rds_engine_version.test.engine + engine_version = data.aws_rds_engine_version.test.version_actual master_password = "mustbeeightcharaters" master_username = "test" skip_final_snapshot = true @@ -2909,55 +2926,60 @@ resource "aws_rds_cluster_instance" "test" { cluster_identifier = aws_rds_cluster.test.id engine = aws_rds_cluster.test.engine engine_version = aws_rds_cluster.test.engine_version - identifier = %[2]q - instance_class = "db.r4.large" + identifier = %[4]q + instance_class = data.aws_rds_orderable_db_instance.test.instance_class } -`, allowMajorVersionUpgrade, rName, engine, engineVersion) +`, engine, mainInstanceClasses, allowMajorVersionUpgrade, rName) } -func testAccClusterConfig_minorVersion(rName, engine, engineVersion, family string) string { +func testAccClusterConfig_minorVersion(rName, engine string, upgrade bool) string { return fmt.Sprintf(` -resource "aws_db_parameter_group" "test" { - name = %[1]q - family = %[4]q +data "aws_rds_engine_version" "test" { + engine = %[1]q + latest = true + preferred_upgrade_targets = [data.aws_rds_engine_version.upgrade.version_actual] +} - parameter { - name = "application_name" - value = %[1]q - } +data "aws_rds_engine_version" "upgrade" { + engine = %[1]q } -resource "aws_rds_cluster" "test" { - cluster_identifier = %[1]q - engine = %[2]q - engine_version = %[3]q - db_instance_parameter_group_name = aws_db_parameter_group.test.id - master_username = "tfacctest" - master_password = %[1]q - skip_final_snapshot = true +locals { + parameter_group_name = %[2]t ? data.aws_rds_engine_version.upgrade.parameter_group_family : data.aws_rds_engine_version.test.parameter_group_family + engine_version = %[2]t ? data.aws_rds_engine_version.upgrade.version_actual : data.aws_rds_engine_version.test.version_actual } data "aws_rds_orderable_db_instance" "test" { - engine = aws_rds_cluster.test.engine - engine_version = aws_rds_cluster.test.engine_version - preferred_instance_classes = ["db.t3.medium", "db.r5.large", "db.r6g.large"] + engine = data.aws_rds_engine_version.test.engine + engine_version = local.engine_version + preferred_instance_classes = [%[3]s] +} + +resource "aws_rds_cluster" "test" { + cluster_identifier = %[4]q + engine = data.aws_rds_engine_version.test.engine + engine_version = local.engine_version + db_instance_parameter_group_name = "default.${local.parameter_group_name}" + master_username = "tfacctest" + master_password = %[4]q + skip_final_snapshot = true } # Upgrading requires a healthy primary instance resource "aws_rds_cluster_instance" "test" { apply_immediately = true cluster_identifier = aws_rds_cluster.test.id - db_parameter_group_name = aws_db_parameter_group.test.name + db_parameter_group_name = aws_rds_cluster.test.db_instance_parameter_group_name engine = data.aws_rds_orderable_db_instance.test.engine engine_version = data.aws_rds_orderable_db_instance.test.engine_version - identifier = %[1]q + identifier = %[4]q instance_class = data.aws_rds_orderable_db_instance.test.instance_class lifecycle { ignore_changes = [engine_version] } } -`, rName, engine, engineVersion, family) +`, engine, upgrade, mainInstanceClasses, rName) } func testAccClusterConfig_availabilityZones(rName string) string { @@ -2966,84 +2988,133 @@ resource "aws_rds_cluster" "test" { apply_immediately = true availability_zones = [data.aws_availability_zones.available.names[0], data.aws_availability_zones.available.names[1], data.aws_availability_zones.available.names[2]] cluster_identifier = %[1]q - engine = "aurora-mysql" + engine = %[2]q master_password = "avoid-plaintext-passwords" master_username = "tfacctest" skip_final_snapshot = true } -`, rName)) +`, rName, tfrds.ClusterEngineAuroraMySQL)) } func testAccClusterConfig_storageTypeIo1(rName string) string { return acctest.ConfigCompose( testAccConfig_ClusterSubnetGroup(rName), fmt.Sprintf(` +data "aws_rds_orderable_db_instance" "test" { + engine = %[1]q + engine_latest_version = true + preferred_instance_classes = [%[2]s] + storage_type = "io1" + supports_iops = true + supports_clusters = true +} + resource "aws_rds_cluster" "test" { apply_immediately = true - cluster_identifier = %[1]q - db_cluster_instance_class = "db.r6gd.xlarge" + cluster_identifier = %[3]q + db_cluster_instance_class = data.aws_rds_orderable_db_instance.test.instance_class db_subnet_group_name = aws_db_subnet_group.test.name - engine = "mysql" - storage_type = "io1" + engine = data.aws_rds_orderable_db_instance.test.engine + engine_version = data.aws_rds_orderable_db_instance.test.engine_version + storage_type = data.aws_rds_orderable_db_instance.test.storage_type allocated_storage = 100 iops = 1000 master_password = "mustbeeightcharaters" master_username = "test" skip_final_snapshot = true } -`, rName)) +`, tfrds.ClusterEngineMySQL, mainInstanceClasses, rName)) } func testAccClusterConfig_allocatedStorage(rName string) string { return acctest.ConfigCompose( testAccConfig_ClusterSubnetGroup(rName), fmt.Sprintf(` +data "aws_rds_orderable_db_instance" "test" { + engine = %[1]q + engine_latest_version = true + preferred_instance_classes = [%[2]s] + storage_type = "io1" + supports_iops = true + supports_clusters = true +} + resource "aws_rds_cluster" "test" { apply_immediately = true - cluster_identifier = %[1]q - db_cluster_instance_class = "db.r6gd.xlarge" + cluster_identifier = %[3]q + db_cluster_instance_class = data.aws_rds_orderable_db_instance.test.instance_class db_subnet_group_name = aws_db_subnet_group.test.name - engine = "mysql" - storage_type = "io1" + engine = data.aws_rds_orderable_db_instance.test.engine + engine_version = data.aws_rds_orderable_db_instance.test.engine_version + storage_type = data.aws_rds_orderable_db_instance.test.storage_type allocated_storage = 100 iops = 1000 master_password = "mustbeeightcharaters" master_username = "test" skip_final_snapshot = true } -`, rName)) +`, tfrds.ClusterEngineMySQL, mainInstanceClasses, rName)) } func testAccClusterConfig_iops(rName string) string { return acctest.ConfigCompose( testAccConfig_ClusterSubnetGroup(rName), fmt.Sprintf(` +data "aws_rds_orderable_db_instance" "test" { + engine = %[1]q + engine_latest_version = true + preferred_instance_classes = [%[2]s] + storage_type = "io1" + supports_iops = true + supports_clusters = true +} + resource "aws_rds_cluster" "test" { apply_immediately = true - cluster_identifier = %[1]q - db_cluster_instance_class = "db.r6gd.xlarge" + cluster_identifier = %[3]q + db_cluster_instance_class = data.aws_rds_orderable_db_instance.test.instance_class db_subnet_group_name = aws_db_subnet_group.test.name - engine = "mysql" - storage_type = "io1" + engine = data.aws_rds_orderable_db_instance.test.engine + engine_version = data.aws_rds_orderable_db_instance.test.engine_version + storage_type = data.aws_rds_orderable_db_instance.test.storage_type allocated_storage = 100 iops = 1000 master_password = "mustbeeightcharaters" master_username = "test" skip_final_snapshot = true } -`, rName)) +`, tfrds.ClusterEngineMySQL, mainInstanceClasses, rName)) } -func testAccClusterConfig_dbClusterInstanceClass(rName, instanceClass string) string { +func testAccClusterConfig_dbClusterInstanceClass(rName string, oddClasses bool) string { + var halfClasses []string + start := 0 + if oddClasses { + start = 1 + } + for i := start; i < len(instanceClassesSlice); i += 2 { + halfClasses = append(halfClasses, instanceClassesSlice[i]) + } + halfPreferredClasses := strings.Join(halfClasses, ", ") return acctest.ConfigCompose( testAccConfig_ClusterSubnetGroup(rName), fmt.Sprintf(` +data "aws_rds_orderable_db_instance" "test" { + engine = %[1]q + engine_latest_version = true + preferred_instance_classes = [%[2]s] + storage_type = "io1" + supports_iops = true + supports_clusters = true +} + +# this test is about updating the instance class. not sure how to dynamically make it give a different value? resource "aws_rds_cluster" "test" { apply_immediately = true - cluster_identifier = %[1]q - db_cluster_instance_class = %[2]q + cluster_identifier = %[3]q + db_cluster_instance_class = data.aws_rds_orderable_db_instance.test.instance_class db_subnet_group_name = aws_db_subnet_group.test.name - engine = "mysql" + engine = %[1]q storage_type = "io1" allocated_storage = 100 iops = 1000 @@ -3051,21 +3122,21 @@ resource "aws_rds_cluster" "test" { master_username = "test" skip_final_snapshot = true } -`, rName, instanceClass)) +`, tfrds.ClusterEngineMySQL, halfPreferredClasses, rName)) } func testAccClusterConfig_backtrackWindow(backtrackWindow int) string { return fmt.Sprintf(` resource "aws_rds_cluster" "test" { apply_immediately = true - backtrack_window = %d + backtrack_window = %[1]d cluster_identifier_prefix = "tf-acc-test-" - engine = "aurora-mysql" + engine = %[2]q master_password = "mustbeeightcharaters" master_username = "test" skip_final_snapshot = true } -`, backtrackWindow) +`, backtrackWindow, tfrds.ClusterEngineAuroraMySQL) } func testAccClusterConfig_subnetGroupName(rName string) string { @@ -3074,13 +3145,13 @@ func testAccClusterConfig_subnetGroupName(rName string) string { fmt.Sprintf(` resource "aws_rds_cluster" "test" { cluster_identifier = %[1]q - engine = "aurora-mysql" + engine = %[2]q master_username = "tfacctest" master_password = "avoid-plaintext-passwords" db_subnet_group_name = aws_db_subnet_group.test.name skip_final_snapshot = true } -`, rName)) +`, rName, tfrds.ClusterEngineAuroraMySQL)) } func testAccClusterConfig_finalSnapshot(rName string) string { @@ -3088,23 +3159,23 @@ func testAccClusterConfig_finalSnapshot(rName string) string { resource "aws_rds_cluster" "test" { cluster_identifier = %[1]q database_name = "test" - engine = "aurora-mysql" + engine = %[2]q master_username = "tfacctest" master_password = "avoid-plaintext-passwords" final_snapshot_identifier = %[1]q } -`, rName) +`, rName, tfrds.ClusterEngineAuroraMySQL) } func testAccClusterConfig_withoutUserNameAndPassword(n int) string { return fmt.Sprintf(` resource "aws_rds_cluster" "default" { - cluster_identifier = "tf-aurora-cluster-%d" - engine = "aurora-mysql" + cluster_identifier = "tf-aurora-cluster-%[1]d" + engine = %[2]q database_name = "mydb" skip_final_snapshot = true } -`, n) +`, n, tfrds.ClusterEngineAuroraMySQL) } func testAccClusterConfig_baseForPITR(rName string) string { @@ -3117,9 +3188,9 @@ resource "aws_rds_cluster" "test" { master_password = "avoid-plaintext-passwords" db_subnet_group_name = aws_db_subnet_group.test.name skip_final_snapshot = true - engine = "aurora-mysql" + engine = %[2]q } -`, rName)) +`, rName, tfrds.ClusterEngineAuroraMySQL)) } func testAccClusterConfig_pointInTimeRestoreSource(rName string) string { @@ -3158,71 +3229,89 @@ resource "aws_rds_cluster" "restore" { func testAccClusterConfig_enabledCloudWatchLogsExports1(rName, enabledCloudwatchLogExports1 string) string { return fmt.Sprintf(` resource "aws_rds_cluster" "test" { - cluster_identifier = %q - enabled_cloudwatch_logs_exports = [%q] - engine = "aurora-mysql" + cluster_identifier = %[1]q + enabled_cloudwatch_logs_exports = [%[2]q] + engine = %[3]q master_username = "foo" master_password = "mustbeeightcharaters" skip_final_snapshot = true } -`, rName, enabledCloudwatchLogExports1) +`, rName, enabledCloudwatchLogExports1, tfrds.ClusterEngineAuroraMySQL) } func testAccClusterConfig_enabledCloudWatchLogsExports2(rName, enabledCloudwatchLogExports1, enabledCloudwatchLogExports2 string) string { return fmt.Sprintf(` resource "aws_rds_cluster" "test" { - cluster_identifier = %q - enabled_cloudwatch_logs_exports = [%q, %q] - engine = "aurora-mysql" + cluster_identifier = %[1]q + enabled_cloudwatch_logs_exports = [%[2]q, %[3]q] + engine = %[4]q master_username = "foo" master_password = "mustbeeightcharaters" skip_final_snapshot = true } -`, rName, enabledCloudwatchLogExports1, enabledCloudwatchLogExports2) +`, rName, enabledCloudwatchLogExports1, enabledCloudwatchLogExports2, tfrds.ClusterEngineAuroraMySQL) } func testAccClusterConfig_enabledCloudWatchLogsExportsPostgreSQL1(rName, enabledCloudwatchLogExports1 string) string { return acctest.ConfigCompose( testAccConfig_ClusterSubnetGroup(rName), fmt.Sprintf(` +data "aws_rds_orderable_db_instance" "test" { + engine = %[1]q + engine_latest_version = true + preferred_instance_classes = [%[2]s] + storage_type = "io1" + supports_iops = true + supports_clusters = true +} + resource "aws_rds_cluster" "test" { - cluster_identifier = %[1]q - enabled_cloudwatch_logs_exports = [%[2]q] + cluster_identifier = %[3]q + enabled_cloudwatch_logs_exports = [%[4]q] master_username = "tfacctest" master_password = "avoid-plaintext-passwords" skip_final_snapshot = true allocated_storage = 100 - storage_type = "io1" + storage_type = data.aws_rds_orderable_db_instance.test.storage_type iops = 1000 - db_cluster_instance_class = "db.m5d.large" + db_cluster_instance_class = data.aws_rds_orderable_db_instance.test.instance_class db_subnet_group_name = aws_db_subnet_group.test.name - engine = "postgres" + engine = data.aws_rds_orderable_db_instance.test.engine engine_mode = "provisioned" - engine_version = "13.12" + engine_version = data.aws_rds_orderable_db_instance.test.engine_version } -`, rName, enabledCloudwatchLogExports1)) +`, tfrds.ClusterEnginePostgres, mainInstanceClasses, rName, enabledCloudwatchLogExports1)) } func testAccClusterConfig_enabledCloudWatchLogsExportsPostgreSQL2(rName, enabledCloudwatchLogExports1, enabledCloudwatchLogExports2 string) string { return acctest.ConfigCompose( testAccConfig_ClusterSubnetGroup(rName), fmt.Sprintf(` +data "aws_rds_orderable_db_instance" "test" { + engine = %[1]q + engine_latest_version = true + preferred_instance_classes = [%[2]s] + storage_type = "io1" + supports_iops = true + supports_clusters = true +} + resource "aws_rds_cluster" "test" { - cluster_identifier = %[1]q - enabled_cloudwatch_logs_exports = [%[2]q, %[3]q] + cluster_identifier = %[3]q + enabled_cloudwatch_logs_exports = [%[4]q, %[5]q] master_username = "tfacctest" master_password = "avoid-plaintext-passwords" skip_final_snapshot = true allocated_storage = 100 - storage_type = "io1" + storage_type = data.aws_rds_orderable_db_instance.test.storage_type iops = 1000 - db_cluster_instance_class = "db.m5d.large" + db_cluster_instance_class = data.aws_rds_orderable_db_instance.test.instance_class db_subnet_group_name = aws_db_subnet_group.test.name - engine = "postgres" + engine = data.aws_rds_orderable_db_instance.test.engine engine_mode = "provisioned" - engine_version = "13.12" + engine_version = data.aws_rds_orderable_db_instance.test.engine_version } -`, rName, enabledCloudwatchLogExports1, enabledCloudwatchLogExports2)) +`, tfrds.ClusterEnginePostgres, mainInstanceClasses, rName, enabledCloudwatchLogExports1, enabledCloudwatchLogExports2)) } func testAccClusterConfig_kmsKey(n int) string { @@ -3256,14 +3345,14 @@ resource "aws_kms_key" "foo" { resource "aws_rds_cluster" "test" { cluster_identifier = "tf-aurora-cluster-%[1]d" database_name = "mydb" - engine = "aurora-mysql" + engine = %[2]q master_username = "foo" master_password = "mustbeeightcharaters" storage_encrypted = true kms_key_id = aws_kms_key.foo.arn skip_final_snapshot = true } -`, n) +`, n, tfrds.ClusterEngineAuroraMySQL) } func testAccClusterConfig_encrypted(n int) string { @@ -3271,21 +3360,21 @@ func testAccClusterConfig_encrypted(n int) string { resource "aws_rds_cluster" "test" { cluster_identifier = "tf-aurora-cluster-%d" database_name = "mydb" - engine = "aurora-mysql" + engine = %[2]q master_username = "foo" master_password = "mustbeeightcharaters" storage_encrypted = true skip_final_snapshot = true } -`, n) +`, n, tfrds.ClusterEngineAuroraMySQL) } func testAccClusterConfig_backups(n int) string { return fmt.Sprintf(` resource "aws_rds_cluster" "test" { - cluster_identifier = "tf-aurora-cluster-%d" + cluster_identifier = "tf-aurora-cluster-%[1]d" database_name = "mydb" - engine = "aurora-mysql" + engine = %[2]q master_username = "foo" master_password = "mustbeeightcharaters" backup_retention_period = 5 @@ -3293,15 +3382,15 @@ resource "aws_rds_cluster" "test" { preferred_maintenance_window = "tue:04:00-tue:04:30" skip_final_snapshot = true } -`, n) +`, n, tfrds.ClusterEngineAuroraMySQL) } func testAccClusterConfig_backupsUpdate(n int) string { return fmt.Sprintf(` resource "aws_rds_cluster" "test" { - cluster_identifier = "tf-aurora-cluster-%d" + cluster_identifier = "tf-aurora-cluster-%[1]d" database_name = "mydb" - engine = "aurora-mysql" + engine = %[2]q master_username = "foo" master_password = "mustbeeightcharaters" backup_retention_period = 10 @@ -3310,33 +3399,33 @@ resource "aws_rds_cluster" "test" { apply_immediately = true skip_final_snapshot = true } -`, n) +`, n, tfrds.ClusterEngineAuroraMySQL) } func testAccClusterConfig_iamAuth(n int) string { return fmt.Sprintf(` resource "aws_rds_cluster" "test" { - cluster_identifier = "tf-aurora-cluster-%d" + cluster_identifier = "tf-aurora-cluster-%[1]d" database_name = "mydb" - engine = "aurora-mysql" + engine = %[2]q master_username = "foo" master_password = "mustbeeightcharaters" iam_database_authentication_enabled = true skip_final_snapshot = true } -`, n) +`, n, tfrds.ClusterEngineAuroraMySQL) } func testAccClusterConfig_engineVersion(rName string, upgrade bool) string { return fmt.Sprintf(` data "aws_rds_engine_version" "test" { - engine = "aurora-postgresql" - preferred_versions = ["11.6", "11.7", "11.9"] + engine = %[1]q + latest = true + preferred_upgrade_targets = [data.aws_rds_engine_version.upgrade.version_actual] } data "aws_rds_engine_version" "upgrade" { - engine = data.aws_rds_engine_version.test.engine - preferred_versions = data.aws_rds_engine_version.test.valid_upgrade_targets + engine = %[1]q } locals { @@ -3345,7 +3434,7 @@ locals { } resource "aws_rds_cluster" "test" { - cluster_identifier = %[1]q + cluster_identifier = %[3]q database_name = "test" db_cluster_parameter_group_name = "default.${local.parameter_group_name}" engine = data.aws_rds_engine_version.test.engine @@ -3355,19 +3444,19 @@ resource "aws_rds_cluster" "test" { skip_final_snapshot = true apply_immediately = true } -`, rName, upgrade) +`, tfrds.ClusterEngineAuroraPostgreSQL, upgrade, rName) } func testAccClusterConfig_engineVersionPrimaryInstance(rName string, upgrade bool) string { return fmt.Sprintf(` data "aws_rds_engine_version" "test" { - engine = "aurora-postgresql" - preferred_versions = ["10.17", "11.13", "12.8"] + engine = %[1]q + latest = true + preferred_upgrade_targets = [data.aws_rds_engine_version.upgrade.version_actual] } data "aws_rds_engine_version" "upgrade" { - engine = data.aws_rds_engine_version.test.engine - preferred_versions = data.aws_rds_engine_version.test.valid_upgrade_targets + engine = %[1]q } locals { @@ -3376,7 +3465,7 @@ locals { } resource "aws_rds_cluster" "test" { - cluster_identifier = %[1]q + cluster_identifier = %[3]q database_name = "test" db_cluster_parameter_group_name = "default.${local.parameter_group_name}" engine = data.aws_rds_engine_version.test.engine @@ -3390,31 +3479,30 @@ resource "aws_rds_cluster" "test" { data "aws_rds_orderable_db_instance" "test" { engine = data.aws_rds_engine_version.test.engine engine_version = data.aws_rds_engine_version.test.version - preferred_instance_classes = ["db.t2.small", "db.t3.medium", "db.r4.large"] + preferred_instance_classes = [%[4]s] } resource "aws_rds_cluster_instance" "test" { - identifier = %[1]q + identifier = %[3]q cluster_identifier = aws_rds_cluster.test.cluster_identifier engine = aws_rds_cluster.test.engine instance_class = data.aws_rds_orderable_db_instance.test.instance_class } -`, rName, upgrade) +`, tfrds.ClusterEngineAuroraPostgreSQL, upgrade, rName, mainInstanceClasses) } func testAccClusterConfig_port(rName string, port int) string { return fmt.Sprintf(` resource "aws_rds_cluster" "test" { - cluster_identifier = %[1]q - database_name = "mydb" - db_cluster_parameter_group_name = "default.aurora-postgresql14" - engine = "aurora-postgresql" - master_password = "mustbeeightcharaters" - master_username = "foo" - port = %[2]d - skip_final_snapshot = true + cluster_identifier = %[1]q + database_name = "mydb" + engine = %[2]q + master_password = "mustbeeightcharaters" + master_username = "foo" + port = %[3]d + skip_final_snapshot = true } -`, rName, port) +`, rName, tfrds.ClusterEngineAuroraPostgreSQL, port) } func testAccClusterConfig_includingIAMRoles(n int) string { @@ -3496,7 +3584,7 @@ EOF resource "aws_rds_cluster" "test" { cluster_identifier = "tf-aurora-cluster-%[1]d" database_name = "mydb" - engine = "aurora-mysql" + engine = %[2]q master_username = "foo" master_password = "mustbeeightcharaters" skip_final_snapshot = true @@ -3507,7 +3595,7 @@ resource "aws_rds_cluster" "test" { depends_on = [aws_iam_role.another_rds_sample_role, aws_iam_role.rds_sample_role] } -`, n) +`, n, tfrds.ClusterEngineAuroraMySQL) } func testAccClusterConfig_addIAMRoles(n int) string { @@ -3589,7 +3677,7 @@ EOF resource "aws_rds_cluster" "test" { cluster_identifier = "tf-aurora-cluster-%[1]d" database_name = "mydb" - engine = "aurora-mysql" + engine = %[2]q master_username = "foo" master_password = "mustbeeightcharaters" skip_final_snapshot = true @@ -3601,7 +3689,7 @@ resource "aws_rds_cluster" "test" { depends_on = [aws_iam_role.another_rds_sample_role, aws_iam_role.rds_sample_role] } -`, n) +`, n, tfrds.ClusterEngineAuroraMySQL) } func testAccClusterConfig_removeIAMRoles(n int) string { @@ -3646,7 +3734,7 @@ EOF resource "aws_rds_cluster" "test" { cluster_identifier = "tf-aurora-cluster-%[1]d" database_name = "mydb" - engine = "aurora-mysql" + engine = %[2]q master_username = "foo" master_password = "mustbeeightcharaters" skip_final_snapshot = true @@ -3658,7 +3746,7 @@ resource "aws_rds_cluster" "test" { depends_on = [aws_iam_role.another_rds_sample_role] } -`, n) +`, n, tfrds.ClusterEngineAuroraMySQL) } func testAccClusterConfig_replicationSourceIDKMSKeyID(rName string) string { @@ -3679,17 +3767,17 @@ data "aws_partition" "current" {} data "aws_region" "current" {} data "aws_rds_engine_version" "default" { - engine = "aurora-mysql" + engine = %[1]q } data "aws_rds_orderable_db_instance" "test" { engine = data.aws_rds_engine_version.default.engine engine_version = data.aws_rds_engine_version.default.version - preferred_instance_classes = ["db.t3.small", "db.t3.medium", "db.t3.large"] + preferred_instance_classes = [%[2]s] } resource "aws_rds_cluster_parameter_group" "test" { - name = %[1]q + name = %[3]q family = data.aws_rds_engine_version.default.parameter_group_family description = "RDS default cluster parameter group" @@ -3701,7 +3789,7 @@ resource "aws_rds_cluster_parameter_group" "test" { } resource "aws_rds_cluster" "test" { - cluster_identifier = "%[1]s-primary" + cluster_identifier = "%[3]s-primary" db_cluster_parameter_group_name = aws_rds_cluster_parameter_group.test.name database_name = "test" engine = data.aws_rds_engine_version.default.engine @@ -3712,7 +3800,7 @@ resource "aws_rds_cluster" "test" { } resource "aws_rds_cluster_instance" "test" { - identifier = "%[1]s-primary" + identifier = "%[3]s-primary" cluster_identifier = aws_rds_cluster.test.id instance_class = data.aws_rds_orderable_db_instance.test.instance_class engine = aws_rds_cluster.test.engine @@ -3722,7 +3810,7 @@ resource "aws_rds_cluster_instance" "test" { resource "aws_kms_key" "test" { provider = "awsalternate" - description = %[1]q + description = %[3]q policy = < 0 { + var preferredVersions []*rds.DBEngineVersion + for _, elem := range l { preferredVersion, ok := elem.(string) @@ -213,27 +259,98 @@ func dataSourceEngineVersionRead(ctx context.Context, d *schema.ResourceData, me for _, engineVersion := range engineVersions { if preferredVersion == aws.StringValue(engineVersion.EngineVersion) { - found = engineVersion - break + preferredVersions = append(preferredVersions, engineVersion) } } + } - if found != nil { - break + if len(preferredVersions) == 0 { + return sdkdiag.AppendErrorf(diags, "no RDS engine versions match the criteria and preferred versions: %v\n%v", input, l) + } + + prefSearch = true + engineVersions = preferredVersions + } + + // preferred upgrade targets + if l := d.Get("preferred_upgrade_targets").([]interface{}); len(l) > 0 { + var prefUTs []*rds.DBEngineVersion + + engineVersionsLoop: + for _, engineVersion := range engineVersions { + for _, upgradeTarget := range engineVersion.ValidUpgradeTarget { + for _, elem := range l { + prefUT, ok := elem.(string) + if !ok { + continue + } + + if prefUT == aws.StringValue(upgradeTarget.EngineVersion) { + prefUTs = append(prefUTs, engineVersion) + continue engineVersionsLoop + } + } } } + + if len(prefUTs) == 0 { + return sdkdiag.AppendErrorf(diags, "no RDS engine versions match the criteria and preferred upgrade targets: %+v\n%v", input, l) + } + + prefSearch = true + engineVersions = prefUTs } - if found == nil && len(engineVersions) > 1 { - return sdkdiag.AppendErrorf(diags, "multiple RDS engine versions (%v) match the criteria", engineVersions) + // preferred major targets + if l := d.Get("preferred_major_targets").([]interface{}); len(l) > 0 { + var prefMTs []*rds.DBEngineVersion + + majorsLoop: + for _, engineVersion := range engineVersions { + for _, upgradeTarget := range engineVersion.ValidUpgradeTarget { + for _, elem := range l { + prefMT, ok := elem.(string) + if !ok { + continue + } + + if prefMT == aws.StringValue(upgradeTarget.EngineVersion) && aws.BoolValue(upgradeTarget.IsMajorVersionUpgrade) { + prefMTs = append(prefMTs, engineVersion) + continue majorsLoop + } + } + } + } + + if len(prefMTs) == 0 { + return sdkdiag.AppendErrorf(diags, "no RDS engine versions match the criteria and preferred major targets: %+v\n%v", input, l) + } + + prefSearch = true + engineVersions = prefMTs + } + + var found *rds.DBEngineVersion + + if v, ok := d.GetOk("latest"); ok && v.(bool) { + sortEngineVersions(engineVersions) + found = engineVersions[len(engineVersions)-1] } if found == nil && len(engineVersions) == 1 { found = engineVersions[0] } + if found == nil && len(engineVersions) > 0 && prefSearch { + found = engineVersions[0] + } + + if found == nil && len(engineVersions) > 1 { + return sdkdiag.AppendErrorf(diags, "multiple RDS engine versions (%v) match the criteria: %+v", engineVersions, input) + } + if found == nil { - return sdkdiag.AppendErrorf(diags, "no RDS engine versions match the criteria") + return sdkdiag.AppendErrorf(diags, "no RDS engine versions match the criteria: %+v", input) } d.SetId(aws.StringValue(found.EngineVersion)) @@ -275,7 +392,18 @@ func dataSourceEngineVersionRead(ctx context.Context, d *schema.ResourceData, me d.Set("valid_upgrade_targets", upgradeTargets) d.Set("version", found.EngineVersion) + d.Set("version_actual", found.EngineVersion) d.Set("version_description", found.DBEngineVersionDescription) return diags } + +func sortEngineVersions(engineVersions []*rds.DBEngineVersion) { + if len(engineVersions) < 2 { + return + } + + sort.Slice(engineVersions, func(i, j int) bool { + return version.LessThanWithTime(engineVersions[i].CreateTime, engineVersions[j].CreateTime, aws.StringValue(engineVersions[i].EngineVersion), aws.StringValue(engineVersions[j].EngineVersion)) + }) +} diff --git a/internal/service/rds/engine_version_data_source_test.go b/internal/service/rds/engine_version_data_source_test.go index b8c410f892c..681bb02c33a 100644 --- a/internal/service/rds/engine_version_data_source_test.go +++ b/internal/service/rds/engine_version_data_source_test.go @@ -14,12 +14,13 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "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 TestAccRDSEngineVersionDataSource_basic(t *testing.T) { ctx := acctest.Context(t) dataSourceName := "data.aws_rds_engine_version.test" - engine := "oracle-ee" + engine := tfrds.InstanceEngineOracleEnterprise version := "19.0.0.0.ru-2020-07.rur-2020-07.r1" paramGroup := "oracle-ee-19" @@ -34,8 +35,8 @@ func TestAccRDSEngineVersionDataSource_basic(t *testing.T) { Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(dataSourceName, "engine", engine), resource.TestCheckResourceAttr(dataSourceName, "version", version), + resource.TestCheckResourceAttr(dataSourceName, "version_actual", version), resource.TestCheckResourceAttr(dataSourceName, "parameter_group_family", paramGroup), - resource.TestCheckResourceAttrSet(dataSourceName, "default_character_set"), resource.TestCheckResourceAttrSet(dataSourceName, "engine_description"), resource.TestMatchResourceAttr(dataSourceName, "exportable_log_types.#", regexache.MustCompile(`^[1-9][0-9]*`)), @@ -69,6 +70,7 @@ func TestAccRDSEngineVersionDataSource_upgradeTargets(t *testing.T) { Config: testAccEngineVersionDataSourceConfig_upgradeTargets(), Check: resource.ComposeTestCheckFunc( resource.TestMatchResourceAttr(dataSourceName, "valid_upgrade_targets.#", regexache.MustCompile(`^[1-9][0-9]*`)), + resource.TestCheckResourceAttrSet(dataSourceName, "version_actual"), ), }, }, @@ -89,6 +91,87 @@ func TestAccRDSEngineVersionDataSource_preferred(t *testing.T) { Config: testAccEngineVersionDataSourceConfig_preferred(), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(dataSourceName, "version", "8.0.32"), + resource.TestCheckResourceAttr(dataSourceName, "version_actual", "8.0.32"), + ), + }, + { + Config: testAccEngineVersionDataSourceConfig_preferred2(), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(dataSourceName, "version", "8.0.32"), + resource.TestCheckResourceAttr(dataSourceName, "version_actual", "8.0.32"), + ), + }, + }, + }) +} + +func TestAccRDSEngineVersionDataSource_preferredVersionsPreferredUpgradeTargets(t *testing.T) { + ctx := acctest.Context(t) + dataSourceName := "data.aws_rds_engine_version.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t); testAccEngineVersionPreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, rds.EndpointsID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: nil, + Steps: []resource.TestStep{ + { + Config: testAccEngineVersionDataSourceConfig_preferredVersionsPreferredUpgrades(tfrds.InstanceEngineMySQL, `"5.7.37", "5.7.38", "5.7.39"`, `"8.0.34"`), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(dataSourceName, "version", "5.7.39"), + ), + }, + { + Config: testAccEngineVersionDataSourceConfig_preferredVersionsPreferredUpgrades(tfrds.InstanceEngineMySQL, `"5.7.44", "5.7.38", "5.7.39"`, `"8.0.32","8.0.33"`), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(dataSourceName, "version", "5.7.44"), + ), + }, + }, + }) +} + +func TestAccRDSEngineVersionDataSource_preferredUpgradeTargetsVersion(t *testing.T) { + ctx := acctest.Context(t) + dataSourceName := "data.aws_rds_engine_version.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t); testAccEngineVersionPreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, rds.EndpointsID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: nil, + Steps: []resource.TestStep{ + { + Config: testAccEngineVersionDataSourceConfig_preferredUpgradeTargetsVersion(tfrds.InstanceEngineMySQL, "5.7", `"8.0.44", "8.0.35", "8.0.34"`), + Check: resource.ComposeTestCheckFunc( + resource.TestMatchResourceAttr(dataSourceName, "version", regexache.MustCompile(`^5\.7`)), + resource.TestMatchResourceAttr(dataSourceName, "version_actual", regexache.MustCompile(`^5\.7\.`)), + ), + }, + }, + }) +} + +func TestAccRDSEngineVersionDataSource_preferredMajorTargets(t *testing.T) { + ctx := acctest.Context(t) + dataSourceName := "data.aws_rds_engine_version.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t); testAccEngineVersionPreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, rds.EndpointsID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: nil, + Steps: []resource.TestStep{ + { + Config: testAccEngineVersionDataSourceConfig_preferredMajorTarget(tfrds.InstanceEngineMySQL), + Check: resource.ComposeTestCheckFunc( + resource.TestMatchResourceAttr(dataSourceName, "version", regexache.MustCompile(`^5\.7\.`)), + ), + }, + { + Config: testAccEngineVersionDataSourceConfig_preferredMajorTarget(tfrds.InstanceEngineAuroraPostgreSQL), + Check: resource.ComposeTestCheckFunc( + resource.TestMatchResourceAttr(dataSourceName, "version", regexache.MustCompile(`^15\.`)), ), }, }, @@ -128,7 +211,8 @@ func TestAccRDSEngineVersionDataSource_defaultOnlyExplicit(t *testing.T) { { Config: testAccEngineVersionDataSourceConfig_defaultOnlyExplicit(), Check: resource.ComposeTestCheckFunc( - resource.TestMatchResourceAttr(dataSourceName, "version", regexache.MustCompile(`^8\.0\.`)), + resource.TestMatchResourceAttr(dataSourceName, "version", regexache.MustCompile(`^8\.0`)), + resource.TestMatchResourceAttr(dataSourceName, "version_actual", regexache.MustCompile(`^8\.0\.`)), ), }, }, @@ -149,6 +233,7 @@ func TestAccRDSEngineVersionDataSource_includeAll(t *testing.T) { Config: testAccEngineVersionDataSourceConfig_includeAll(), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(dataSourceName, "version", "8.0.20"), + resource.TestCheckResourceAttr(dataSourceName, "version_actual", "8.0.20"), ), }, }, @@ -166,12 +251,59 @@ func TestAccRDSEngineVersionDataSource_filter(t *testing.T) { CheckDestroy: nil, Steps: []resource.TestStep{ { - Config: testAccEngineVersionDataSourceConfig_filter(), + Config: testAccEngineVersionDataSourceConfig_filter(tfrds.ClusterEngineAuroraPostgreSQL, "serverless"), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "version", "13.9"), + resource.TestCheckResourceAttrSet(dataSourceName, "version"), resource.TestCheckResourceAttr(dataSourceName, "supported_modes.0", "serverless"), ), }, + { + Config: testAccEngineVersionDataSourceConfig_filter(tfrds.ClusterEngineAuroraPostgreSQL, "global"), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet(dataSourceName, "version"), + resource.TestCheckResourceAttr(dataSourceName, "supported_modes.0", "global"), + ), + }, + }, + }) +} + +func TestAccRDSEngineVersionDataSource_latest(t *testing.T) { + ctx := acctest.Context(t) + dataSourceName := "data.aws_rds_engine_version.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t); testAccEngineVersionPreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, rds.EndpointsID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: nil, + Steps: []resource.TestStep{ + { + Config: testAccEngineVersionDataSourceConfig_latest(true, `"13.9", "12.7", "11.12", "15.4", "10.17", "9.6.22"`), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(dataSourceName, "version", "15.4"), + ), + }, + { + Config: testAccEngineVersionDataSourceConfig_latest(false, `"13.9", "12.7", "11.12", "15.4", "10.17", "9.6.22"`), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(dataSourceName, "version", "13.9"), + ), + }, + { + Config: testAccEngineVersionDataSourceConfig_latest2(tfrds.InstanceEngineAuroraPostgreSQL, "15"), + Check: resource.ComposeTestCheckFunc( + resource.TestMatchResourceAttr(dataSourceName, "version", regexache.MustCompile(`^15`)), + resource.TestMatchResourceAttr(dataSourceName, "version_actual", regexache.MustCompile(`^15\.[0-9]`)), + ), + }, + { + Config: testAccEngineVersionDataSourceConfig_latest2(tfrds.InstanceEngineMySQL, "8.0"), + Check: resource.ComposeTestCheckFunc( + resource.TestMatchResourceAttr(dataSourceName, "version", regexache.MustCompile(`^8\.0`)), + resource.TestMatchResourceAttr(dataSourceName, "version_actual", regexache.MustCompile(`^8\.0\.[0-9]+$`)), + ), + }, }, }) } @@ -180,7 +312,7 @@ func testAccEngineVersionPreCheck(ctx context.Context, t *testing.T) { conn := acctest.Provider.Meta().(*conns.AWSClient).RDSConn(ctx) input := &rds.DescribeDBEngineVersionsInput{ - Engine: aws.String("mysql"), + Engine: aws.String(tfrds.InstanceEngineMySQL), DefaultOnly: aws.Bool(true), } @@ -206,62 +338,128 @@ data "aws_rds_engine_version" "test" { } func testAccEngineVersionDataSourceConfig_upgradeTargets() string { - return ` + return fmt.Sprintf(` data "aws_rds_engine_version" "test" { - engine = "mysql" + engine = %[1]q version = "8.0.32" } -` +`, tfrds.InstanceEngineMySQL) } func testAccEngineVersionDataSourceConfig_preferred() string { - return ` + return fmt.Sprintf(` +data "aws_rds_engine_version" "test" { + engine = %[1]q + preferred_versions = ["85.9.12", "8.0.32", "8.0.31"] +} +`, tfrds.InstanceEngineMySQL) +} + +func testAccEngineVersionDataSourceConfig_preferred2() string { + return fmt.Sprintf(` data "aws_rds_engine_version" "test" { - engine = "mysql" + engine = %[1]q + version = "8.0" preferred_versions = ["85.9.12", "8.0.32", "8.0.31"] } -` +`, tfrds.InstanceEngineMySQL) +} + +func testAccEngineVersionDataSourceConfig_preferredVersionsPreferredUpgrades(engine, preferredVersions, preferredUpgrades string) string { + return fmt.Sprintf(` +data "aws_rds_engine_version" "test" { + engine = %[1]q + latest = true + preferred_versions = [%[2]s] + preferred_upgrade_targets = [%[3]s] +} +`, engine, preferredVersions, preferredUpgrades) +} + +func testAccEngineVersionDataSourceConfig_preferredUpgradeTargetsVersion(engine, version, preferredUpgrades string) string { + return fmt.Sprintf(` +data "aws_rds_engine_version" "test" { + engine = %[1]q + version = %[2]q + preferred_upgrade_targets = [%[3]s] +} +`, engine, version, preferredUpgrades) +} + +func testAccEngineVersionDataSourceConfig_preferredMajorTarget(engine string) string { + return fmt.Sprintf(` +data "aws_rds_engine_version" "latest" { + engine = %[1]q + latest = true +} + +data "aws_rds_engine_version" "test" { + engine = %[1]q + latest = true + preferred_major_targets = [data.aws_rds_engine_version.latest.version] +} +`, engine) } func testAccEngineVersionDataSourceConfig_defaultOnlyImplicit() string { - return ` + return fmt.Sprintf(` data "aws_rds_engine_version" "test" { - engine = "mysql" + engine = %[1]q } -` +`, tfrds.InstanceEngineMySQL) } func testAccEngineVersionDataSourceConfig_defaultOnlyExplicit() string { - return ` + return fmt.Sprintf(` data "aws_rds_engine_version" "test" { - engine = "mysql" + engine = %[1]q version = "8.0" default_only = true } -` +`, tfrds.InstanceEngineMySQL) } func testAccEngineVersionDataSourceConfig_includeAll() string { - return ` + return fmt.Sprintf(` data "aws_rds_engine_version" "test" { - engine = "mysql" + engine = %[1]q version = "8.0.20" include_all = true } -` +`, tfrds.InstanceEngineMySQL) } -func testAccEngineVersionDataSourceConfig_filter() string { - return ` +func testAccEngineVersionDataSourceConfig_filter(engine, engineMode string) string { + return fmt.Sprintf(` data "aws_rds_engine_version" "test" { - engine = "aurora-postgresql" - version = "13.9" + engine = %[1]q + latest = true include_all = true filter { name = "engine-mode" - values = ["serverless"] + values = [%[2]q] } } -` +`, engine, engineMode) +} + +func testAccEngineVersionDataSourceConfig_latest(latest bool, preferredVersions string) string { + return fmt.Sprintf(` +data "aws_rds_engine_version" "test" { + engine = %[1]q + latest = %[2]t + preferred_versions = [%[3]s] +} +`, tfrds.InstanceEngineAuroraPostgreSQL, latest, preferredVersions) +} + +func testAccEngineVersionDataSourceConfig_latest2(engine, majorVersion string) string { + return fmt.Sprintf(` +data "aws_rds_engine_version" "test" { + engine = %[1]q + version = %[2]q + latest = true +} +`, engine, majorVersion) } diff --git a/internal/service/rds/instance_automated_backups_replication_test.go b/internal/service/rds/instance_automated_backups_replication_test.go index 39ed1f943d4..75c2145f943 100644 --- a/internal/service/rds/instance_automated_backups_replication_test.go +++ b/internal/service/rds/instance_automated_backups_replication_test.go @@ -274,7 +274,7 @@ resource "aws_db_instance" "test" { provider = "awsalternate" } -`, rName, storageEncrypted, postgresPreferredInstanceClasses)) +`, rName, storageEncrypted, mainInstanceClasses)) } func testAccInstanceAutomatedBackupsReplicationConfig_basic(rName string) string { diff --git a/internal/service/rds/instance_test.go b/internal/service/rds/instance_test.go index 94cd5f3542c..f807f0e8b24 100644 --- a/internal/service/rds/instance_test.go +++ b/internal/service/rds/instance_test.go @@ -66,7 +66,7 @@ func TestAccRDSInstance_basic(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "deletion_protection", "false"), resource.TestCheckResourceAttr(resourceName, "enabled_cloudwatch_logs_exports.#", "0"), resource.TestCheckResourceAttrSet(resourceName, "endpoint"), - resource.TestCheckResourceAttr(resourceName, "engine", "mysql"), + resource.TestCheckResourceAttr(resourceName, "engine", tfrds.InstanceEngineMySQL), resource.TestCheckResourceAttrSet(resourceName, "engine_version"), resource.TestCheckResourceAttrSet(resourceName, "hosted_zone_id"), resource.TestCheckResourceAttr(resourceName, "iam_database_authentication_enabled", "false"), @@ -110,84 +110,6 @@ func TestAccRDSInstance_basic(t *testing.T) { }) } -func TestAccRDSInstance_manage_password(t *testing.T) { - ctx := acctest.Context(t) - if testing.Short() { - t.Skip("skipping long-running test in short mode") - } - - var v rds.DBInstance - rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) - resourceName := "aws_db_instance.test" - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, rds.EndpointsID), - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - CheckDestroy: testAccCheckInstanceDestroy(ctx), - Steps: []resource.TestStep{ - { - Config: testAccInstanceConfig_manage_password(rName), - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckInstanceExists(ctx, resourceName, &v), - testAccCheckInstanceAttributes(&v), - resource.TestCheckResourceAttr(resourceName, "allocated_storage", "10"), - resource.TestCheckNoResourceAttr(resourceName, "allow_major_version_upgrade"), - acctest.MatchResourceAttrRegionalARN(resourceName, "arn", "rds", regexache.MustCompile(`db:.+`)), - resource.TestCheckResourceAttr(resourceName, "auto_minor_version_upgrade", "true"), - resource.TestCheckResourceAttrSet(resourceName, "availability_zone"), - resource.TestCheckResourceAttr(resourceName, "backup_retention_period", "0"), - resource.TestCheckResourceAttr(resourceName, "backup_target", "region"), - resource.TestCheckResourceAttrSet(resourceName, "backup_window"), - resource.TestCheckResourceAttrSet(resourceName, "ca_cert_identifier"), - resource.TestCheckResourceAttr(resourceName, "copy_tags_to_snapshot", "false"), - resource.TestCheckResourceAttr(resourceName, "db_name", "test"), - resource.TestCheckResourceAttr(resourceName, "db_subnet_group_name", "default"), - resource.TestCheckResourceAttr(resourceName, "deletion_protection", "false"), - resource.TestCheckResourceAttr(resourceName, "enabled_cloudwatch_logs_exports.#", "0"), - resource.TestCheckResourceAttrSet(resourceName, "endpoint"), - resource.TestCheckResourceAttr(resourceName, "engine", "mysql"), - resource.TestCheckResourceAttrSet(resourceName, "engine_version"), - resource.TestCheckResourceAttrSet(resourceName, "hosted_zone_id"), - resource.TestCheckResourceAttr(resourceName, "iam_database_authentication_enabled", "false"), - resource.TestCheckResourceAttr(resourceName, "identifier", rName), - resource.TestCheckResourceAttr(resourceName, "identifier_prefix", ""), - resource.TestCheckResourceAttrPair(resourceName, "instance_class", "data.aws_rds_orderable_db_instance.test", "instance_class"), - resource.TestCheckResourceAttr(resourceName, "iops", "0"), - resource.TestCheckResourceAttr(resourceName, "license_model", "general-public-license"), - resource.TestCheckResourceAttrSet(resourceName, "maintenance_window"), - resource.TestCheckResourceAttr(resourceName, "master_user_secret.#", "1"), - resource.TestCheckResourceAttr(resourceName, "max_allocated_storage", "0"), - resource.TestMatchResourceAttr(resourceName, "option_group_name", regexache.MustCompile(`^default:mysql-\d`)), - resource.TestMatchResourceAttr(resourceName, "parameter_group_name", regexache.MustCompile(`^default\.mysql\d`)), - resource.TestCheckResourceAttr(resourceName, "port", "3306"), - resource.TestCheckResourceAttr(resourceName, "publicly_accessible", "false"), - resource.TestCheckResourceAttrSet(resourceName, "resource_id"), - resource.TestCheckResourceAttr(resourceName, "status", "available"), - resource.TestCheckResourceAttr(resourceName, "storage_encrypted", "false"), - resource.TestCheckResourceAttr(resourceName, "storage_throughput", "0"), - resource.TestCheckResourceAttr(resourceName, "storage_type", "gp2"), - resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), - resource.TestCheckResourceAttr(resourceName, "username", "tfacctest"), - ), - }, - { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{ - "apply_immediately", - "final_snapshot_identifier", - "password", - "manage_master_user_password", - "skip_final_snapshot", - "delete_automated_backups", - }, - }, - }, - }) -} - func TestAccRDSInstance_identifierPrefix(t *testing.T) { ctx := acctest.Context(t) if testing.Short() { @@ -345,7 +267,7 @@ func TestAccRDSInstance_tags(t *testing.T) { }) } -func TestAccRDSInstance_onlyMajorVersion(t *testing.T) { +func TestAccRDSInstance_Versions_onlyMajor(t *testing.T) { ctx := acctest.Context(t) if testing.Short() { t.Skip("skipping long-running test in short mode") @@ -365,7 +287,7 @@ func TestAccRDSInstance_onlyMajorVersion(t *testing.T) { Config: testAccInstanceConfig_majorVersionOnly(rName), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(ctx, resourceName, &v), - resource.TestCheckResourceAttr(resourceName, "engine", "mysql"), + resource.TestCheckResourceAttr(resourceName, "engine", tfrds.InstanceEngineMySQL), resource.TestCheckResourceAttr(resourceName, "engine_version", "8.0"), ), }, @@ -454,14 +376,18 @@ func TestAccRDSInstance_customIAMInstanceProfile(t *testing.T) { }) } -func TestAccRDSInstance_subnetGroup(t *testing.T) { +func TestAccRDSInstance_DBSubnetGroupName_basic(t *testing.T) { ctx := acctest.Context(t) if testing.Short() { t.Skip("skipping long-running test in short mode") } - var v rds.DBInstance + var dbInstance rds.DBInstance + var dbSubnetGroup rds.DBSubnetGroup + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + dbSubnetGroupResourceName := "aws_db_subnet_group.test" + dbSubnetGroupResourceName2 := "aws_db_subnet_group.test2" resourceName := "aws_db_instance.test" resource.ParallelTest(t, resource.TestCase{ @@ -471,16 +397,19 @@ func TestAccRDSInstance_subnetGroup(t *testing.T) { CheckDestroy: testAccCheckInstanceDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_subnetGroup(rName), + Config: testAccInstanceConfig_DBSubnetGroupName_basic(rName), Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckInstanceExists(ctx, resourceName, &v), - resource.TestCheckResourceAttr(resourceName, "db_subnet_group_name", rName), + testAccCheckInstanceExists(ctx, resourceName, &dbInstance), + testAccCheckSubnetGroupExists(ctx, dbSubnetGroupResourceName, &dbSubnetGroup), + resource.TestCheckResourceAttrPair(resourceName, "db_subnet_group_name", dbSubnetGroupResourceName, "name"), ), }, { - Config: testAccInstanceConfig_subnetGroupUpdated(rName), + Config: testAccInstanceConfig_DBSubnetGroupName_update(rName), Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckInstanceExists(ctx, resourceName, &v), + testAccCheckInstanceExists(ctx, resourceName, &dbInstance), + testAccCheckSubnetGroupExists(ctx, dbSubnetGroupResourceName2, &dbSubnetGroup), + resource.TestCheckResourceAttrPair(resourceName, "db_subnet_group_name", dbSubnetGroupResourceName2, "name"), resource.TestCheckResourceAttr(resourceName, "db_subnet_group_name", fmt.Sprintf("%s-2", rName)), ), }, @@ -578,7 +507,7 @@ func TestAccRDSInstance_iamAuth(t *testing.T) { }) } -func TestAccRDSInstance_allowMajorVersionUpgrade(t *testing.T) { +func TestAccRDSInstance_Versions_allowMajor(t *testing.T) { ctx := acctest.Context(t) if testing.Short() { t.Skip("skipping long-running test in short mode") @@ -596,7 +525,7 @@ func TestAccRDSInstance_allowMajorVersionUpgrade(t *testing.T) { CheckDestroy: testAccCheckInstanceDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_allowMajorVersionUpgrade(rName, true), + Config: testAccInstanceConfig_Versions_allowMajor(rName, true), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(ctx, resourceName, &dbInstance1), resource.TestCheckResourceAttr(resourceName, "allow_major_version_upgrade", "true"), @@ -615,7 +544,7 @@ func TestAccRDSInstance_allowMajorVersionUpgrade(t *testing.T) { }, }, { - Config: testAccInstanceConfig_allowMajorVersionUpgrade(rName, false), + Config: testAccInstanceConfig_Versions_allowMajor(rName, false), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(ctx, resourceName, &dbInstance1), resource.TestCheckResourceAttr(resourceName, "allow_major_version_upgrade", "false"), @@ -625,7 +554,7 @@ func TestAccRDSInstance_allowMajorVersionUpgrade(t *testing.T) { }) } -func TestAccRDSInstance_DB2_basic(t *testing.T) { +func TestAccRDSInstance_db2(t *testing.T) { ctx := acctest.Context(t) if testing.Short() { t.Skip("skipping long-running test in short mode") @@ -656,37 +585,6 @@ func TestAccRDSInstance_DB2_basic(t *testing.T) { }) } -func TestAccRDSInstance_dbSubnetGroupName(t *testing.T) { - ctx := acctest.Context(t) - if testing.Short() { - t.Skip("skipping long-running test in short mode") - } - - var dbInstance rds.DBInstance - var dbSubnetGroup rds.DBSubnetGroup - - rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) - dbSubnetGroupResourceName := "aws_db_subnet_group.test" - resourceName := "aws_db_instance.test" - - resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t) }, - ErrorCheck: acctest.ErrorCheck(t, rds.EndpointsID), - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, - CheckDestroy: testAccCheckInstanceDestroy(ctx), - Steps: []resource.TestStep{ - { - Config: testAccInstanceConfig_dbSubnetGroupName(rName), - Check: resource.ComposeAggregateTestCheckFunc( - testAccCheckInstanceExists(ctx, resourceName, &dbInstance), - testAccCheckSubnetGroupExists(ctx, dbSubnetGroupResourceName, &dbSubnetGroup), - resource.TestCheckResourceAttrPair(resourceName, "db_subnet_group_name", dbSubnetGroupResourceName, "name"), - ), - }, - }, - }) -} - func TestAccRDSInstance_DBSubnetGroupName_ramShared(t *testing.T) { ctx := acctest.Context(t) var dbInstance rds.DBInstance @@ -796,7 +694,7 @@ func TestAccRDSInstance_deletionProtection(t *testing.T) { }) } -func TestAccRDSInstance_finalSnapshotIdentifier(t *testing.T) { +func TestAccRDSInstance_FinalSnapshotIdentifier_basic(t *testing.T) { ctx := acctest.Context(t) if testing.Short() { t.Skip("skipping long-running test in short mode") @@ -902,7 +800,7 @@ func TestAccRDSInstance_isAlreadyBeingDeleted(t *testing.T) { }) } -func TestAccRDSInstance_maxAllocatedStorage(t *testing.T) { +func TestAccRDSInstance_Storage_maxAllocated(t *testing.T) { ctx := acctest.Context(t) if testing.Short() { t.Skip("skipping long-running test in short mode") @@ -920,28 +818,28 @@ func TestAccRDSInstance_maxAllocatedStorage(t *testing.T) { CheckDestroy: testAccCheckInstanceDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_maxAllocatedStorage(rName, 10), + Config: testAccInstanceConfig_Storage_maxAllocated(rName, 10), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(ctx, resourceName, &dbInstance), resource.TestCheckResourceAttr(resourceName, "max_allocated_storage", "10"), ), }, { - Config: testAccInstanceConfig_maxAllocatedStorage(rName, 5), + Config: testAccInstanceConfig_Storage_maxAllocated(rName, 5), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(ctx, resourceName, &dbInstance), resource.TestCheckResourceAttr(resourceName, "max_allocated_storage", "0"), ), }, { - Config: testAccInstanceConfig_maxAllocatedStorage(rName, 15), + Config: testAccInstanceConfig_Storage_maxAllocated(rName, 15), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(ctx, resourceName, &dbInstance), resource.TestCheckResourceAttr(resourceName, "max_allocated_storage", "15"), ), }, { - Config: testAccInstanceConfig_maxAllocatedStorage(rName, 0), + Config: testAccInstanceConfig_Storage_maxAllocated(rName, 0), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(ctx, resourceName, &dbInstance), resource.TestCheckResourceAttr(resourceName, "max_allocated_storage", "0"), @@ -1002,7 +900,7 @@ func TestAccRDSInstance_password(t *testing.T) { }) } -func TestAccRDSInstance_ManagedMasterPassword_managed(t *testing.T) { +func TestAccRDSInstance_ManageMasterPassword_basic(t *testing.T) { ctx := acctest.Context(t) var v rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -1015,7 +913,7 @@ func TestAccRDSInstance_ManagedMasterPassword_managed(t *testing.T) { CheckDestroy: testAccCheckInstanceDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_managedMasterPassword(rName), + Config: testAccInstanceConfig_manageMasterPassword(rName), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(ctx, resourceName, &v), resource.TestCheckResourceAttr(resourceName, "manage_master_user_password", "true"), @@ -1040,7 +938,7 @@ func TestAccRDSInstance_ManagedMasterPassword_managed(t *testing.T) { }) } -func TestAccRDSInstance_ManagedMasterPassword_managedSpecificKMSKey(t *testing.T) { +func TestAccRDSInstance_ManageMasterPassword_kmsKey(t *testing.T) { ctx := acctest.Context(t) var v rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -1053,7 +951,7 @@ func TestAccRDSInstance_ManagedMasterPassword_managedSpecificKMSKey(t *testing.T CheckDestroy: testAccCheckInstanceDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_managedMasterPasswordKMSKey(rName), + Config: testAccInstanceConfig_manageMasterPasswordKMSKey(rName), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(ctx, resourceName, &v), resource.TestCheckResourceAttr(resourceName, "manage_master_user_password", "true"), @@ -1079,7 +977,7 @@ func TestAccRDSInstance_ManagedMasterPassword_managedSpecificKMSKey(t *testing.T }) } -func TestAccRDSInstance_ManagedMasterPassword_convertToManaged(t *testing.T) { +func TestAccRDSInstance_ManageMasterPassword_convertToManaged(t *testing.T) { ctx := acctest.Context(t) if testing.Short() { t.Skip("skipping long-running test in short mode") @@ -1114,7 +1012,7 @@ func TestAccRDSInstance_ManagedMasterPassword_convertToManaged(t *testing.T) { }, }, { - Config: testAccInstanceConfig_managedMasterPassword(rName), + Config: testAccInstanceConfig_manageMasterPassword(rName), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(ctx, resourceName, &dbCluster2), resource.TestCheckResourceAttrSet(resourceName, "manage_master_user_password"), @@ -1591,7 +1489,7 @@ func TestAccRDSInstance_ReplicateSourceDB_dbSubnetGroupName(t *testing.T) { }) } -func TestAccRDSInstance_ReplicateSourceDBDBSubnetGroupName_ramShared(t *testing.T) { +func TestAccRDSInstance_ReplicateSourceDB_dbSubnetGroupNameRAMShared(t *testing.T) { ctx := acctest.Context(t) if testing.Short() { t.Skip("skipping long-running test in short mode") @@ -1627,7 +1525,7 @@ func TestAccRDSInstance_ReplicateSourceDBDBSubnetGroupName_ramShared(t *testing. }) } -func TestAccRDSInstance_ReplicateSourceDBDBSubnetGroupName_vpcSecurityGroupIDs(t *testing.T) { +func TestAccRDSInstance_ReplicateSourceDB_dbSubnetGroupNameVPCSecurityGroupIDs(t *testing.T) { ctx := acctest.Context(t) if testing.Short() { t.Skip("skipping long-running test in short mode") @@ -2265,7 +2163,7 @@ func TestAccRDSInstance_ReplicateSourceDB_parameterGroupTwoStep(t *testing.T) { }) } -func TestAccRDSInstance_S3Import_basic(t *testing.T) { +func TestAccRDSInstance_s3Import(t *testing.T) { acctest.Skip(t, "RestoreDBInstanceFromS3 cannot restore from MySQL version 5.6") ctx := acctest.Context(t) @@ -2281,7 +2179,7 @@ func TestAccRDSInstance_S3Import_basic(t *testing.T) { CheckDestroy: testAccCheckInstanceDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_S3Import_basic(rName), + Config: testAccInstanceConfig_s3Import(rName), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(ctx, resourceName, &v), resource.TestCheckResourceAttr(resourceName, "identifier", rName), @@ -2345,7 +2243,7 @@ func TestAccRDSInstance_SnapshotIdentifier_basic(t *testing.T) { }) } -func TestAccRDSInstance_SnapshotIdentifier_ManagedMasterPasswordKMSKey(t *testing.T) { +func TestAccRDSInstance_SnapshotIdentifier_ManageMasterPasswordKMSKey(t *testing.T) { ctx := acctest.Context(t) if testing.Short() { t.Skip("skipping long-running test in short mode") @@ -2366,7 +2264,7 @@ func TestAccRDSInstance_SnapshotIdentifier_ManagedMasterPasswordKMSKey(t *testin CheckDestroy: testAccCheckInstanceDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_snapshotID_ManagedMasterPasswordKMSKey(rName), + Config: testAccInstanceConfig_snapshotID_ManageMasterPasswordKMSKey(rName), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(ctx, sourceDbResourceName, &sourceDbInstance), testAccCheckDBSnapshotExists(ctx, snapshotResourceName, &dbSnapshot), @@ -3550,7 +3448,7 @@ func TestAccRDSInstance_MonitoringRoleARN_removedToEnabled(t *testing.T) { // Regression test for https://github.com/hashicorp/terraform/issues/3760 . // 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) { +func TestAccRDSInstance_Storage_separateIOPSUpdate(t *testing.T) { ctx := acctest.Context(t) if testing.Short() { t.Skip("skipping long-running test in short mode") @@ -3643,7 +3541,7 @@ func TestAccRDSInstance_MSSQL_tz(t *testing.T) { testAccCheckInstanceExists(ctx, resourceName, &v), testAccCheckInstanceAttributes_MSSQL(&v, ""), resource.TestCheckResourceAttr(resourceName, "allocated_storage", "20"), - resource.TestCheckResourceAttr(resourceName, "engine", "sqlserver-ex"), + resource.TestCheckResourceAttr(resourceName, "engine", tfrds.InstanceEngineSQLServerExpress), ), }, @@ -3653,7 +3551,7 @@ func TestAccRDSInstance_MSSQL_tz(t *testing.T) { testAccCheckInstanceExists(ctx, resourceName, &v), testAccCheckInstanceAttributes_MSSQL(&v, "Alaskan Standard Time"), resource.TestCheckResourceAttr(resourceName, "allocated_storage", "20"), - resource.TestCheckResourceAttr(resourceName, "engine", "sqlserver-ex"), + resource.TestCheckResourceAttr(resourceName, "engine", tfrds.InstanceEngineSQLServerExpress), ), }, }, @@ -3844,7 +3742,7 @@ func TestAccRDSInstance_MySQL_snapshotRestoreWithEngineVersion(t *testing.T) { }) } -func TestAccRDSInstance_minorVersion(t *testing.T) { +func TestAccRDSInstance_Versions_minor(t *testing.T) { ctx := acctest.Context(t) if testing.Short() { t.Skip("skipping long-running test in short mode") @@ -3869,7 +3767,7 @@ func TestAccRDSInstance_minorVersion(t *testing.T) { }) } -func TestAccRDSInstance_cloudWatchLogsExport(t *testing.T) { +func TestAccRDSInstance_CloudWatchLogsExport_basic(t *testing.T) { ctx := acctest.Context(t) if testing.Short() { t.Skip("skipping long-running test in short mode") @@ -3886,7 +3784,7 @@ func TestAccRDSInstance_cloudWatchLogsExport(t *testing.T) { CheckDestroy: testAccCheckInstanceDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_cloudWatchLogsExportConfiguration(rName), + Config: testAccInstanceConfig_cloudWatchLogsExport(rName), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(ctx, resourceName, &v), resource.TestCheckResourceAttr(resourceName, "enabled_cloudwatch_logs_exports.#", "2"), @@ -3910,7 +3808,7 @@ func TestAccRDSInstance_cloudWatchLogsExport(t *testing.T) { }) } -func TestAccRDSInstance_EnabledCloudWatchLogsExports_db2(t *testing.T) { +func TestAccRDSInstance_CloudWatchLogsExport_db2(t *testing.T) { ctx := acctest.Context(t) if testing.Short() { t.Skip("skipping long-running test in short mode") @@ -3931,7 +3829,7 @@ func TestAccRDSInstance_EnabledCloudWatchLogsExports_db2(t *testing.T) { CheckDestroy: testAccCheckInstanceDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_EnabledCloudWatchLogsExports_db2(rName, customerID, siteID), + Config: testAccInstanceConfig_CloudWatchLogsExport_db2(rName, customerID, siteID), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(ctx, resourceName, &v), resource.TestCheckResourceAttr(resourceName, "enabled_cloudwatch_logs_exports.#", "2"), @@ -3952,7 +3850,7 @@ func TestAccRDSInstance_EnabledCloudWatchLogsExports_db2(t *testing.T) { }) } -func TestAccRDSInstance_EnabledCloudWatchLogsExports_mySQL(t *testing.T) { +func TestAccRDSInstance_CloudWatchLogsExport_mySQL(t *testing.T) { ctx := acctest.Context(t) if testing.Short() { t.Skip("skipping long-running test in short mode") @@ -3969,7 +3867,7 @@ func TestAccRDSInstance_EnabledCloudWatchLogsExports_mySQL(t *testing.T) { CheckDestroy: testAccCheckInstanceDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_cloudWatchLogsExportConfiguration(rName), + Config: testAccInstanceConfig_cloudWatchLogsExport(rName), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(ctx, resourceName, &v), resource.TestCheckResourceAttr(resourceName, "enabled_cloudwatch_logs_exports.#", "2"), @@ -3978,7 +3876,7 @@ func TestAccRDSInstance_EnabledCloudWatchLogsExports_mySQL(t *testing.T) { ), }, { - Config: testAccInstanceConfig_cloudWatchLogsExportConfigurationAdd(rName), + Config: testAccInstanceConfig_cloudWatchLogsExportAdd(rName), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(ctx, resourceName, &v), resource.TestCheckResourceAttr(resourceName, "enabled_cloudwatch_logs_exports.#", "3"), @@ -3988,7 +3886,7 @@ func TestAccRDSInstance_EnabledCloudWatchLogsExports_mySQL(t *testing.T) { ), }, { - Config: testAccInstanceConfig_cloudWatchLogsExportConfigurationModify(rName), + Config: testAccInstanceConfig_cloudWatchLogsExportModify(rName), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(ctx, resourceName, &v), resource.TestCheckResourceAttr(resourceName, "enabled_cloudwatch_logs_exports.#", "3"), @@ -3998,7 +3896,7 @@ func TestAccRDSInstance_EnabledCloudWatchLogsExports_mySQL(t *testing.T) { ), }, { - Config: testAccInstanceConfig_cloudWatchLogsExportConfigurationDelete(rName), + Config: testAccInstanceConfig_cloudWatchLogsExportDelete(rName), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(ctx, resourceName, &v), resource.TestCheckResourceAttr(resourceName, "enabled_cloudwatch_logs_exports.#", "0"), @@ -4008,7 +3906,7 @@ func TestAccRDSInstance_EnabledCloudWatchLogsExports_mySQL(t *testing.T) { }) } -func TestAccRDSInstance_EnabledCloudWatchLogsExports_msSQL(t *testing.T) { +func TestAccRDSInstance_CloudWatchLogsExport_msSQL(t *testing.T) { ctx := acctest.Context(t) if testing.Short() { t.Skip("skipping long-running test in short mode") @@ -4025,7 +3923,7 @@ func TestAccRDSInstance_EnabledCloudWatchLogsExports_msSQL(t *testing.T) { CheckDestroy: testAccCheckInstanceDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_EnabledCloudWatchLogsExports_mssql(rName), + Config: testAccInstanceConfig_CloudWatchLogsExport_mssql(rName), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(ctx, resourceName, &v), resource.TestCheckResourceAttr(resourceName, "enabled_cloudwatch_logs_exports.#", "2"), @@ -4046,7 +3944,7 @@ func TestAccRDSInstance_EnabledCloudWatchLogsExports_msSQL(t *testing.T) { }) } -func TestAccRDSInstance_EnabledCloudWatchLogsExports_oracle(t *testing.T) { +func TestAccRDSInstance_CloudWatchLogsExport_oracle(t *testing.T) { ctx := acctest.Context(t) if testing.Short() { t.Skip("skipping long-running test in short mode") @@ -4063,7 +3961,7 @@ func TestAccRDSInstance_EnabledCloudWatchLogsExports_oracle(t *testing.T) { CheckDestroy: testAccCheckInstanceDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_EnabledCloudWatchLogsExports_oracle(rName), + Config: testAccInstanceConfig_CloudWatchLogsExport_oracle(rName), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(ctx, resourceName, &dbInstance), resource.TestCheckResourceAttr(resourceName, "enabled_cloudwatch_logs_exports.#", "3"), @@ -4085,7 +3983,7 @@ func TestAccRDSInstance_EnabledCloudWatchLogsExports_oracle(t *testing.T) { }) } -func TestAccRDSInstance_EnabledCloudWatchLogsExports_postgresql(t *testing.T) { +func TestAccRDSInstance_CloudWatchLogsExport_postgresql(t *testing.T) { ctx := acctest.Context(t) if testing.Short() { t.Skip("skipping long-running test in short mode") @@ -4102,7 +4000,7 @@ func TestAccRDSInstance_EnabledCloudWatchLogsExports_postgresql(t *testing.T) { CheckDestroy: testAccCheckInstanceDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_EnabledCloudWatchLogsExports_postgreSQL(rName), + Config: testAccInstanceConfig_CloudWatchLogsExport_postgreSQL(rName), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(ctx, resourceName, &dbInstance), resource.TestCheckResourceAttr(resourceName, "enabled_cloudwatch_logs_exports.#", "2"), @@ -4152,7 +4050,7 @@ func TestAccRDSInstance_noDeleteAutomatedBackups(t *testing.T) { } // Reference: https://github.com/hashicorp/terraform-provider-aws/issues/8792 -func TestAccRDSInstance_PerformanceInsightsEnabled_disabledToEnabled(t *testing.T) { +func TestAccRDSInstance_PerformanceInsights_disabledToEnabled(t *testing.T) { ctx := acctest.Context(t) if testing.Short() { t.Skip("skipping long-running test in short mode") @@ -4163,7 +4061,10 @@ func TestAccRDSInstance_PerformanceInsightsEnabled_disabledToEnabled(t *testing. resourceName := "aws_db_instance.test" resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t); testAccPerformanceInsightsDefaultVersionPreCheck(ctx, t, "mysql") }, + PreCheck: func() { + acctest.PreCheck(ctx, t) + testAccPerformanceInsightsDefaultVersionPreCheck(ctx, t, tfrds.InstanceEngineMySQL) + }, ErrorCheck: acctest.ErrorCheck(t, rds.EndpointsID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckClusterDestroy(ctx), @@ -4197,7 +4098,7 @@ func TestAccRDSInstance_PerformanceInsightsEnabled_disabledToEnabled(t *testing. }) } -func TestAccRDSInstance_PerformanceInsightsEnabled_enabledToDisabled(t *testing.T) { +func TestAccRDSInstance_PerformanceInsights_enabledToDisabled(t *testing.T) { ctx := acctest.Context(t) if testing.Short() { t.Skip("skipping long-running test in short mode") @@ -4208,7 +4109,10 @@ func TestAccRDSInstance_PerformanceInsightsEnabled_enabledToDisabled(t *testing. resourceName := "aws_db_instance.test" resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t); testAccPerformanceInsightsDefaultVersionPreCheck(ctx, t, "mysql") }, + PreCheck: func() { + acctest.PreCheck(ctx, t) + testAccPerformanceInsightsDefaultVersionPreCheck(ctx, t, tfrds.InstanceEngineMySQL) + }, ErrorCheck: acctest.ErrorCheck(t, rds.EndpointsID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckClusterDestroy(ctx), @@ -4242,7 +4146,7 @@ func TestAccRDSInstance_PerformanceInsightsEnabled_enabledToDisabled(t *testing. }) } -func TestAccRDSInstance_performanceInsightsKMSKeyID(t *testing.T) { +func TestAccRDSInstance_PerformanceInsights_kmsKeyID(t *testing.T) { ctx := acctest.Context(t) if testing.Short() { t.Skip("skipping long-running test in short mode") @@ -4254,7 +4158,10 @@ func TestAccRDSInstance_performanceInsightsKMSKeyID(t *testing.T) { resourceName := "aws_db_instance.test" resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t); testAccPerformanceInsightsDefaultVersionPreCheck(ctx, t, "mysql") }, + PreCheck: func() { + acctest.PreCheck(ctx, t) + testAccPerformanceInsightsDefaultVersionPreCheck(ctx, t, tfrds.InstanceEngineMySQL) + }, ErrorCheck: acctest.ErrorCheck(t, rds.EndpointsID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckClusterDestroy(ctx), @@ -4298,7 +4205,7 @@ func TestAccRDSInstance_performanceInsightsKMSKeyID(t *testing.T) { }) } -func TestAccRDSInstance_performanceInsightsRetentionPeriod(t *testing.T) { +func TestAccRDSInstance_PerformanceInsights_retentionPeriod(t *testing.T) { ctx := acctest.Context(t) if testing.Short() { t.Skip("skipping long-running test in short mode") @@ -4309,7 +4216,10 @@ func TestAccRDSInstance_performanceInsightsRetentionPeriod(t *testing.T) { resourceName := "aws_db_instance.test" resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t); testAccPerformanceInsightsDefaultVersionPreCheck(ctx, t, "mysql") }, + PreCheck: func() { + acctest.PreCheck(ctx, t) + testAccPerformanceInsightsDefaultVersionPreCheck(ctx, t, tfrds.InstanceEngineMySQL) + }, ErrorCheck: acctest.ErrorCheck(t, rds.EndpointsID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckClusterDestroy(ctx), @@ -4367,7 +4277,10 @@ func TestAccRDSInstance_ReplicateSourceDB_performanceInsightsEnabled(t *testing. resourceName := "aws_db_instance.test" resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t); testAccPerformanceInsightsDefaultVersionPreCheck(ctx, t, "mysql") }, + PreCheck: func() { + acctest.PreCheck(ctx, t) + testAccPerformanceInsightsDefaultVersionPreCheck(ctx, t, tfrds.InstanceEngineMySQL) + }, ErrorCheck: acctest.ErrorCheck(t, rds.EndpointsID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckInstanceDestroy(ctx), @@ -4403,7 +4316,10 @@ func TestAccRDSInstance_SnapshotIdentifier_performanceInsightsEnabled(t *testing resourceName := "aws_db_instance.test" resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t); testAccPerformanceInsightsDefaultVersionPreCheck(ctx, t, "mysql") }, + PreCheck: func() { + acctest.PreCheck(ctx, t) + testAccPerformanceInsightsDefaultVersionPreCheck(ctx, t, tfrds.InstanceEngineMySQL) + }, ErrorCheck: acctest.ErrorCheck(t, rds.EndpointsID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckInstanceDestroy(ctx), @@ -4564,7 +4480,7 @@ func TestAccRDSInstance_RestoreToPointInTime_monitoring(t *testing.T) { }) } -func TestAccRDSInstance_RestoreToPointInTime_ManagedMasterPassword(t *testing.T) { +func TestAccRDSInstance_RestoreToPointInTime_manageMasterPassword(t *testing.T) { ctx := acctest.Context(t) if testing.Short() { t.Skip("skipping long-running test in short mode") @@ -4612,7 +4528,7 @@ func TestAccRDSInstance_RestoreToPointInTime_ManagedMasterPassword(t *testing.T) }) } -func TestAccRDSInstance_NationalCharacterSet_oracle(t *testing.T) { +func TestAccRDSInstance_Oracle_nationalCharacterSet(t *testing.T) { ctx := acctest.Context(t) if testing.Short() { t.Skip("skipping long-running test in short mode") @@ -4630,7 +4546,7 @@ func TestAccRDSInstance_NationalCharacterSet_oracle(t *testing.T) { CheckDestroy: testAccCheckInstanceDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_NationalCharacterSet_oracle(rName), + Config: testAccInstanceConfig_Oracle_nationalCharacterSet(rName), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(ctx, resourceName, &dbInstance), resource.TestCheckResourceAttr(resourceName, "nchar_character_set_name", "UTF8"), @@ -4652,7 +4568,7 @@ func TestAccRDSInstance_NationalCharacterSet_oracle(t *testing.T) { }) } -func TestAccRDSInstance_NoNationalCharacterSet_oracle(t *testing.T) { +func TestAccRDSInstance_Oracle_noNationalCharacterSet(t *testing.T) { ctx := acctest.Context(t) if testing.Short() { t.Skip("skipping long-running test in short mode") @@ -4670,7 +4586,7 @@ func TestAccRDSInstance_NoNationalCharacterSet_oracle(t *testing.T) { CheckDestroy: testAccCheckInstanceDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_NoNationalCharacterSet_oracle(rName), + Config: testAccInstanceConfig_Oracle_noNationalCharacterSet(rName), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(ctx, resourceName, &dbInstance), resource.TestCheckResourceAttr(resourceName, "nchar_character_set_name", "AL16UTF16"), @@ -4692,7 +4608,7 @@ func TestAccRDSInstance_NoNationalCharacterSet_oracle(t *testing.T) { }) } -func TestAccRDSInstance_CoIPEnabled(t *testing.T) { +func TestAccRDSInstance_Outposts_coIPEnabled(t *testing.T) { ctx := acctest.Context(t) var v rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -4717,7 +4633,7 @@ func TestAccRDSInstance_CoIPEnabled(t *testing.T) { }) } -func TestAccRDSInstance_CoIPEnabled_disabledToEnabled(t *testing.T) { +func TestAccRDSInstance_Outposts_coIPDisabledToEnabled(t *testing.T) { ctx := acctest.Context(t) var dbInstance rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -4758,7 +4674,7 @@ func TestAccRDSInstance_CoIPEnabled_disabledToEnabled(t *testing.T) { }) } -func TestAccRDSInstance_CoIPEnabled_enabledToDisabled(t *testing.T) { +func TestAccRDSInstance_Outposts_coIPEnabledToDisabled(t *testing.T) { ctx := acctest.Context(t) var dbInstance rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -4799,7 +4715,7 @@ func TestAccRDSInstance_CoIPEnabled_enabledToDisabled(t *testing.T) { }) } -func TestAccRDSInstance_CoIPEnabled_restoreToPointInTime(t *testing.T) { +func TestAccRDSInstance_Outposts_coIPRestoreToPointInTime(t *testing.T) { ctx := acctest.Context(t) var dbInstance, sourceDbInstance rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -4813,7 +4729,7 @@ func TestAccRDSInstance_CoIPEnabled_restoreToPointInTime(t *testing.T) { CheckDestroy: testAccCheckInstanceDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_CoIPEnabled_restorePointInTime(rName, false, true), + Config: testAccInstanceConfig_Outposts_coIPRestorePointInTime(rName, false, true), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(ctx, sourceName, &sourceDbInstance), testAccCheckInstanceExists(ctx, resourceName, &dbInstance), @@ -4838,7 +4754,7 @@ func TestAccRDSInstance_CoIPEnabled_restoreToPointInTime(t *testing.T) { }) } -func TestAccRDSInstance_CoIPEnabled_snapshotIdentifier(t *testing.T) { +func TestAccRDSInstance_Outposts_coIPSnapshotIdentifier(t *testing.T) { ctx := acctest.Context(t) var dbInstance, sourceDbInstance rds.DBInstance var dbSnapshot rds.DBSnapshot @@ -4855,7 +4771,7 @@ func TestAccRDSInstance_CoIPEnabled_snapshotIdentifier(t *testing.T) { CheckDestroy: testAccCheckInstanceDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_CoIPEnabled_snapshotID(rName, false, true), + Config: testAccInstanceConfig_Outposts_coIPSnapshotID(rName, false, true), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(ctx, sourceDbResourceName, &sourceDbInstance), testAccCheckDBSnapshotExists(ctx, snapshotResourceName, &dbSnapshot), @@ -4867,7 +4783,7 @@ func TestAccRDSInstance_CoIPEnabled_snapshotIdentifier(t *testing.T) { }) } -func TestAccRDSInstance_BackupTarget(t *testing.T) { +func TestAccRDSInstance_Outposts_backupTarget(t *testing.T) { ctx := acctest.Context(t) if testing.Short() { t.Skip("skipping long-running test in short mode") @@ -4884,7 +4800,7 @@ func TestAccRDSInstance_BackupTarget(t *testing.T) { CheckDestroy: testAccCheckInstanceDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_Outpost_BackupTarget(rName, "outposts", 0), + Config: testAccInstanceConfig_Outposts_backupTarget(rName, "outposts", 0), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(ctx, resourceName, &v), testAccCheckInstanceAttributes(&v), @@ -4970,7 +4886,7 @@ func TestAccRDSInstance_BlueGreenDeployment_updateEngineVersion(t *testing.T) { Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(ctx, resourceName, &v2), testAccCheckDBInstanceRecreated(&v1, &v2), - resource.TestCheckResourceAttrPair(resourceName, "engine_version", "data.aws_rds_engine_version.updated", "version"), + resource.TestCheckResourceAttrPair(resourceName, "engine_version", "data.aws_rds_engine_version.update", "version"), resource.TestCheckResourceAttr(resourceName, "blue_green_update.0.enabled", "true"), ), }, @@ -5002,6 +4918,7 @@ func TestAccRDSInstance_BlueGreenDeployment_updateParameterGroup(t *testing.T) { rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_db_instance.test" parameterGroupResourceName := "aws_db_parameter_group.test" + parameterGroupDataSource := "data.aws_db_parameter_group.test" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, @@ -5014,9 +4931,7 @@ func TestAccRDSInstance_BlueGreenDeployment_updateParameterGroup(t *testing.T) { Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(ctx, resourceName, &v1), resource.TestCheckResourceAttr(resourceName, "backup_retention_period", "1"), - // TODO: This should be a TestCheckResourceAttrPair against a parameter group data source. - // https://github.com/hashicorp/terraform-provider-aws/pull/13718 - resource.TestMatchResourceAttr(resourceName, "parameter_group_name", regexache.MustCompile(`^default\.mysql`)), + resource.TestCheckResourceAttrPair(resourceName, "parameter_group_name", parameterGroupDataSource, "name"), ), }, { @@ -5115,7 +5030,7 @@ func TestAccRDSInstance_BlueGreenDeployment_updateInstanceClass(t *testing.T) { CheckDestroy: testAccCheckInstanceDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_BlueGreenDeployment_basic(rName), + Config: testAccInstanceConfig_BlueGreenDeployment_updateableInstanceClass(rName, false), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(ctx, resourceName, &v1), resource.TestCheckResourceAttrPair(resourceName, "instance_class", "data.aws_rds_orderable_db_instance.test", "instance_class"), @@ -5123,11 +5038,11 @@ func TestAccRDSInstance_BlueGreenDeployment_updateInstanceClass(t *testing.T) { ), }, { - Config: testAccInstanceConfig_BlueGreenDeployment_updateInstanceClass(rName), + Config: testAccInstanceConfig_BlueGreenDeployment_updateableInstanceClass(rName, true), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(ctx, resourceName, &v2), testAccCheckDBInstanceRecreated(&v1, &v2), - resource.TestCheckResourceAttrPair(resourceName, "instance_class", "data.aws_rds_orderable_db_instance.updated", "instance_class"), + resource.TestCheckResourceAttrPair(resourceName, "instance_class", "data.aws_rds_orderable_db_instance.test", "instance_class"), resource.TestCheckResourceAttr(resourceName, "blue_green_update.0.enabled", "true"), ), }, @@ -5167,7 +5082,7 @@ func TestAccRDSInstance_BlueGreenDeployment_updateAndPromoteReplica(t *testing.T CheckDestroy: testAccCheckInstanceDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_ReplicateSourceDB_backupRetentionPeriod(rName, 1), + Config: testAccInstanceConfig_BlueGreenDeployment_prePromote(rName), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(ctx, resourceName, &v1), resource.TestCheckResourceAttrPair(resourceName, "replicate_source_db", sourceResourceName, "identifier"), @@ -5180,7 +5095,7 @@ func TestAccRDSInstance_BlueGreenDeployment_updateAndPromoteReplica(t *testing.T Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(ctx, resourceName, &v2), testAccCheckDBInstanceRecreated(&v1, &v2), - resource.TestCheckResourceAttrPair(resourceName, "instance_class", "data.aws_rds_orderable_db_instance.updated", "instance_class"), + resource.TestCheckResourceAttrPair(resourceName, "instance_class", "data.aws_rds_orderable_db_instance.update", "instance_class"), resource.TestCheckResourceAttr(resourceName, "blue_green_update.0.enabled", "true"), ), }, @@ -5219,7 +5134,7 @@ func TestAccRDSInstance_BlueGreenDeployment_updateAndEnableBackups(t *testing.T) CheckDestroy: testAccCheckInstanceDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_basic(rName), + Config: testAccInstanceConfig_BlueGreenDeployment_pre(rName, false), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(ctx, resourceName, &v1), resource.TestCheckResourceAttrPair(resourceName, "instance_class", "data.aws_rds_orderable_db_instance.test", "instance_class"), @@ -5227,11 +5142,11 @@ func TestAccRDSInstance_BlueGreenDeployment_updateAndEnableBackups(t *testing.T) ), }, { - Config: testAccInstanceConfig_BlueGreenDeployment_updateInstanceClass(rName), + Config: testAccInstanceConfig_BlueGreenDeployment_updateableInstanceClass(rName, true), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(ctx, resourceName, &v2), testAccCheckDBInstanceRecreated(&v1, &v2), - resource.TestCheckResourceAttrPair(resourceName, "instance_class", "data.aws_rds_orderable_db_instance.updated", "instance_class"), + resource.TestCheckResourceAttrPair(resourceName, "instance_class", "data.aws_rds_orderable_db_instance.test", "instance_class"), resource.TestCheckResourceAttr(resourceName, "backup_retention_period", "1"), resource.TestCheckResourceAttr(resourceName, "blue_green_update.0.enabled", "true"), ), @@ -5271,7 +5186,7 @@ func TestAccRDSInstance_BlueGreenDeployment_deletionProtectionBypassesBlueGreen( CheckDestroy: testAccCheckInstanceDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_BlueGreenDeployment_deletionProtection(rName, true), + Config: testAccInstanceConfig_BlueGreenDeployment_deletionProtection(rName, true, false), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(ctx, resourceName, &v1), resource.TestCheckResourceAttr(resourceName, "deletion_protection", "true"), @@ -5293,7 +5208,7 @@ func TestAccRDSInstance_BlueGreenDeployment_deletionProtectionBypassesBlueGreen( }, }, { - Config: testAccInstanceConfig_BlueGreenDeployment_deletionProtection(rName, false), + Config: testAccInstanceConfig_BlueGreenDeployment_deletionProtection(rName, false, false), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(ctx, resourceName, &v2), testAccCheckDBInstanceNotRecreated(&v1, &v2), @@ -5371,7 +5286,7 @@ func TestAccRDSInstance_BlueGreenDeployment_updateWithDeletionProtection(t *test CheckDestroy: testAccCheckInstanceDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_BlueGreenDeployment_deletionProtection(rName, true), + Config: testAccInstanceConfig_BlueGreenDeployment_deletionProtection(rName, true, false), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(ctx, resourceName, &v1), resource.TestCheckResourceAttr(resourceName, "deletion_protection", "true"), @@ -5394,12 +5309,12 @@ func TestAccRDSInstance_BlueGreenDeployment_updateWithDeletionProtection(t *test }, }, { - Config: testAccInstanceConfig_BlueGreenDeployment_updateInstanceClassWithDeletionProtection(rName, true), + Config: testAccInstanceConfig_BlueGreenDeployment_deletionProtection(rName, true, true), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(ctx, resourceName, &v2), testAccCheckDBInstanceRecreated(&v1, &v2), resource.TestCheckResourceAttr(resourceName, "deletion_protection", "true"), - resource.TestCheckResourceAttrPair(resourceName, "instance_class", "data.aws_rds_orderable_db_instance.updated", "instance_class"), + resource.TestCheckResourceAttrPair(resourceName, "instance_class", "data.aws_rds_orderable_db_instance.test", "instance_class"), resource.TestCheckResourceAttr(resourceName, "blue_green_update.0.enabled", "true"), ), }, @@ -5418,7 +5333,7 @@ func TestAccRDSInstance_BlueGreenDeployment_updateWithDeletionProtection(t *test }, }, { - Config: testAccInstanceConfig_BlueGreenDeployment_updateInstanceClassWithDeletionProtection(rName, false), + Config: testAccInstanceConfig_BlueGreenDeployment_deletionProtection(rName, false, true), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(ctx, resourceName, &v3), testAccCheckDBInstanceNotRecreated(&v2, &v3), @@ -5439,7 +5354,7 @@ func TestAccRDSInstance_BlueGreenDeployment_outOfBand(t *testing.T) { var v1, v2 rds.DBInstance rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_db_instance.test" - var updatedVersion string + var updateVersion string resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t) }, @@ -5455,7 +5370,7 @@ func TestAccRDSInstance_BlueGreenDeployment_outOfBand(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "identifier", rName), resource.TestCheckResourceAttrSet(resourceName, "resource_id"), resource.TestCheckResourceAttrPair(resourceName, "id", resourceName, "resource_id"), - testAccCheckRetrieveValue("data.aws_rds_engine_version.updated", "version", &updatedVersion), + testAccCheckRetrieveValue("data.aws_rds_engine_version.update", "version", &updateVersion), ), }, { @@ -5470,7 +5385,7 @@ func TestAccRDSInstance_BlueGreenDeployment_outOfBand(t *testing.T) { input := &rds_sdkv2.CreateBlueGreenDeploymentInput{ BlueGreenDeploymentName: aws.String(rName), Source: v1.DBInstanceArn, - TargetEngineVersion: aws.String(updatedVersion), + TargetEngineVersion: aws.String(updateVersion), } dep, err := orchestrator.CreateDeployment(ctx, input) @@ -5588,7 +5503,7 @@ func TestAccRDSInstance_BlueGreenDeployment_outOfBand(t *testing.T) { }) } -func TestAccRDSInstance_gp3MySQL(t *testing.T) { +func TestAccRDSInstance_Storage_gp3MySQL(t *testing.T) { ctx := acctest.Context(t) if testing.Short() { t.Skip("skipping long-running test in short mode") @@ -5605,7 +5520,7 @@ func TestAccRDSInstance_gp3MySQL(t *testing.T) { CheckDestroy: testAccCheckInstanceDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_gp3(rName, testAccInstanceConfig_orderableClassMySQLGP3, 200), + Config: testAccInstanceConfig_Storage_gp3(rName, testAccInstanceConfig_orderableClassMySQLGP3, 200), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(ctx, resourceName, &v), resource.TestCheckResourceAttr(resourceName, "allocated_storage", "200"), @@ -5628,7 +5543,7 @@ func TestAccRDSInstance_gp3MySQL(t *testing.T) { }, }, { - Config: testAccInstanceConfig_gp3(rName, testAccInstanceConfig_orderableClassMySQLGP3, 300), + Config: testAccInstanceConfig_Storage_gp3(rName, testAccInstanceConfig_orderableClassMySQLGP3, 300), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(ctx, resourceName, &v), resource.TestCheckResourceAttr(resourceName, "allocated_storage", "300"), @@ -5641,7 +5556,7 @@ func TestAccRDSInstance_gp3MySQL(t *testing.T) { }) } -func TestAccRDSInstance_gp3Postgres(t *testing.T) { +func TestAccRDSInstance_Storage_gp3Postgres(t *testing.T) { ctx := acctest.Context(t) if testing.Short() { t.Skip("skipping long-running test in short mode") @@ -5658,7 +5573,7 @@ func TestAccRDSInstance_gp3Postgres(t *testing.T) { CheckDestroy: testAccCheckInstanceDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_gp3(rName, testAccInstanceConfig_orderableClassPostgresGP3, 200), + Config: testAccInstanceConfig_Storage_gp3(rName, testAccInstanceConfig_orderableClassPostgresGP3, 200), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(ctx, resourceName, &v), resource.TestCheckResourceAttr(resourceName, "allocated_storage", "200"), @@ -5681,7 +5596,7 @@ func TestAccRDSInstance_gp3Postgres(t *testing.T) { }, }, { - Config: testAccInstanceConfig_gp3(rName, testAccInstanceConfig_orderableClassPostgresGP3, 300), + Config: testAccInstanceConfig_Storage_gp3(rName, testAccInstanceConfig_orderableClassPostgresGP3, 300), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(ctx, resourceName, &v), resource.TestCheckResourceAttr(resourceName, "allocated_storage", "300"), @@ -5694,7 +5609,7 @@ func TestAccRDSInstance_gp3Postgres(t *testing.T) { }) } -func TestAccRDSInstance_gp3SQLServer(t *testing.T) { +func TestAccRDSInstance_Storage_gp3SQLServer(t *testing.T) { ctx := acctest.Context(t) if testing.Short() { t.Skip("skipping long-running test in short mode") @@ -5711,7 +5626,7 @@ func TestAccRDSInstance_gp3SQLServer(t *testing.T) { CheckDestroy: testAccCheckInstanceDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_gp3(rName, testAccInstanceConfig_orderableClassSQLServerExGP3, 200), + Config: testAccInstanceConfig_Storage_gp3(rName, testAccInstanceConfig_orderableClassSQLServerExGP3, 200), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(ctx, resourceName, &v), resource.TestCheckResourceAttr(resourceName, "allocated_storage", "200"), @@ -5734,7 +5649,7 @@ func TestAccRDSInstance_gp3SQLServer(t *testing.T) { }, }, { - Config: testAccInstanceConfig_gp3(rName, testAccInstanceConfig_orderableClassSQLServerExGP3, 300), + Config: testAccInstanceConfig_Storage_gp3(rName, testAccInstanceConfig_orderableClassSQLServerExGP3, 300), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(ctx, resourceName, &v), resource.TestCheckResourceAttr(resourceName, "allocated_storage", "300"), @@ -5748,7 +5663,7 @@ func TestAccRDSInstance_gp3SQLServer(t *testing.T) { } // // https://github.com/hashicorp/terraform-provider-aws/issues/33512 -func TestAccRDSInstance_storageChangeThroughput(t *testing.T) { +func TestAccRDSInstance_Storage_changeThroughput(t *testing.T) { ctx := acctest.Context(t) if testing.Short() { t.Skip("skipping long-running test in short mode") @@ -5765,7 +5680,7 @@ func TestAccRDSInstance_storageChangeThroughput(t *testing.T) { CheckDestroy: testAccCheckInstanceDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_storageThroughput(rName, 12000, 500), + Config: testAccInstanceConfig_Storage_throughput(rName, 12000, 500), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(ctx, resourceName, &v), resource.TestCheckResourceAttr(resourceName, "iops", "12000"), @@ -5774,7 +5689,7 @@ func TestAccRDSInstance_storageChangeThroughput(t *testing.T) { ), }, { - Config: testAccInstanceConfig_storageThroughput(rName, 12000, 600), + Config: testAccInstanceConfig_Storage_throughput(rName, 12000, 600), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(ctx, resourceName, &v), resource.TestCheckResourceAttr(resourceName, "iops", "12000"), @@ -5787,7 +5702,7 @@ func TestAccRDSInstance_storageChangeThroughput(t *testing.T) { } // https://github.com/hashicorp/terraform-provider-aws/issues/33512 -func TestAccRDSInstance_storageChangeIOPSThroughput(t *testing.T) { +func TestAccRDSInstance_Storage_changeIOPSThroughput(t *testing.T) { ctx := acctest.Context(t) if testing.Short() { t.Skip("skipping long-running test in short mode") @@ -5804,7 +5719,7 @@ func TestAccRDSInstance_storageChangeIOPSThroughput(t *testing.T) { CheckDestroy: testAccCheckInstanceDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_storageThroughput(rName, 12000, 500), + Config: testAccInstanceConfig_Storage_throughput(rName, 12000, 500), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(ctx, resourceName, &v), resource.TestCheckResourceAttr(resourceName, "iops", "12000"), @@ -5813,7 +5728,7 @@ func TestAccRDSInstance_storageChangeIOPSThroughput(t *testing.T) { ), }, { - Config: testAccInstanceConfig_storageThroughput(rName, 13000, 600), + Config: testAccInstanceConfig_Storage_throughput(rName, 13000, 600), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(ctx, resourceName, &v), resource.TestCheckResourceAttr(resourceName, "iops", "13000"), @@ -5826,7 +5741,7 @@ func TestAccRDSInstance_storageChangeIOPSThroughput(t *testing.T) { } // https://github.com/hashicorp/terraform-provider-aws/issues/33512 -func TestAccRDSInstance_storageChangeIOPS(t *testing.T) { +func TestAccRDSInstance_Storage_changeIOPS(t *testing.T) { ctx := acctest.Context(t) if testing.Short() { t.Skip("skipping long-running test in short mode") @@ -5843,7 +5758,7 @@ func TestAccRDSInstance_storageChangeIOPS(t *testing.T) { CheckDestroy: testAccCheckInstanceDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_storageThroughput(rName, 12000, 500), + Config: testAccInstanceConfig_Storage_throughput(rName, 12000, 500), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(ctx, resourceName, &v), resource.TestCheckResourceAttr(resourceName, "iops", "12000"), @@ -5852,7 +5767,7 @@ func TestAccRDSInstance_storageChangeIOPS(t *testing.T) { ), }, { - Config: testAccInstanceConfig_storageThroughput(rName, 13000, 500), + Config: testAccInstanceConfig_Storage_throughput(rName, 13000, 500), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(ctx, resourceName, &v), resource.TestCheckResourceAttr(resourceName, "iops", "13000"), @@ -5865,7 +5780,7 @@ func TestAccRDSInstance_storageChangeIOPS(t *testing.T) { } // https://github.com/hashicorp/terraform-provider-aws/issues/33512 -func TestAccRDSInstance_storageThroughputSSE(t *testing.T) { +func TestAccRDSInstance_Storage_throughputSSE(t *testing.T) { ctx := acctest.Context(t) if testing.Short() { t.Skip("skipping long-running test in short mode") @@ -5882,7 +5797,7 @@ func TestAccRDSInstance_storageThroughputSSE(t *testing.T) { CheckDestroy: testAccCheckInstanceDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_storageThroughputSSE(rName, 4201, 125), + Config: testAccInstanceConfig_Storage_throughputSSE(rName, 4201, 125), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(ctx, resourceName, &v), resource.TestCheckResourceAttr(resourceName, "iops", "4201"), @@ -5891,7 +5806,7 @@ func TestAccRDSInstance_storageThroughputSSE(t *testing.T) { ), }, { - Config: testAccInstanceConfig_storageThroughputSSE(rName, 4201, 126), + Config: testAccInstanceConfig_Storage_throughputSSE(rName, 4201, 126), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(ctx, resourceName, &v), resource.TestCheckResourceAttr(resourceName, "iops", "4201"), @@ -5903,7 +5818,7 @@ func TestAccRDSInstance_storageThroughputSSE(t *testing.T) { }) } -func TestAccRDSInstance_storageTypePostgres(t *testing.T) { +func TestAccRDSInstance_Storage_typePostgres(t *testing.T) { ctx := acctest.Context(t) if testing.Short() { t.Skip("skipping long-running test in short mode") @@ -5920,7 +5835,7 @@ func TestAccRDSInstance_storageTypePostgres(t *testing.T) { CheckDestroy: testAccCheckInstanceDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccInstanceConfig_storageTypePostgres(rName, "gp2", 200), + Config: testAccInstanceConfig_Storage_typePostgres(rName, "gp2", 200), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(ctx, resourceName, &v), resource.TestCheckResourceAttr(resourceName, "allocated_storage", "200"), @@ -5943,7 +5858,7 @@ func TestAccRDSInstance_storageTypePostgres(t *testing.T) { }, }, { - Config: testAccInstanceConfig_storageTypePostgres(rName, "gp3", 300), + Config: testAccInstanceConfig_Storage_typePostgres(rName, "gp3", 300), Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(ctx, resourceName, &v), resource.TestCheckResourceAttr(resourceName, "allocated_storage", "300"), @@ -6121,7 +6036,7 @@ func testAccCheckRetrieveValue(name, key string, v *string) resource.TestCheckFu func testAccCheckInstanceAttributes(v *rds.DBInstance) resource.TestCheckFunc { return func(s *terraform.State) error { - if *v.Engine != "mysql" { + if *v.Engine != tfrds.InstanceEngineMySQL { return fmt.Errorf("bad engine: %#v", *v.Engine) } @@ -6139,7 +6054,7 @@ func testAccCheckInstanceAttributes(v *rds.DBInstance) resource.TestCheckFunc { func testAccCheckInstanceAttributes_MSSQL(v *rds.DBInstance, tz string) resource.TestCheckFunc { return func(s *terraform.State) error { - if *v.Engine != "sqlserver-ex" { + if *v.Engine != tfrds.InstanceEngineSQLServerExpress { return fmt.Errorf("bad engine: %#v", *v.Engine) } @@ -6339,7 +6254,7 @@ func testAccCheckInstanceExists(ctx context.Context, n string, v *rds.DBInstance } } -func testAccInstanceConfig_orderableClass(engine, license, storage, classes string) string { +func testAccInstanceConfig_orderableClass(engine, license, storage string) string { return fmt.Sprintf(` data "aws_rds_engine_version" "default" { engine = %[1]q @@ -6353,47 +6268,47 @@ data "aws_rds_orderable_db_instance" "test" { preferred_instance_classes = [%[4]s] } -`, engine, license, storage, classes) +`, engine, license, storage, mainInstanceClasses) } func testAccInstanceConfig_orderableClassDB2() string { - return testAccInstanceConfig_orderableClass("db2-se", "bring-your-own-license", "gp3", db2PreferredInstanceClasses) + return testAccInstanceConfig_orderableClass(tfrds.InstanceEngineDB2Standard, "bring-your-own-license", "gp3") } func testAccInstanceConfig_orderableClassMySQL() string { - return testAccInstanceConfig_orderableClass("mysql", "general-public-license", "standard", mySQLPreferredInstanceClasses) + return testAccInstanceConfig_orderableClass(tfrds.InstanceEngineMySQL, "general-public-license", "standard") } func testAccInstanceConfig_orderableClassMySQLGP3() string { - return testAccInstanceConfig_orderableClass("mysql", "general-public-license", "gp3", mySQLPreferredInstanceClasses) + return testAccInstanceConfig_orderableClass(tfrds.InstanceEngineMySQL, "general-public-license", "gp3") } func testAccInstanceConfig_orderableClassPostgres() string { - return testAccInstanceConfig_orderableClass("postgres", "postgresql-license", "standard", postgresPreferredInstanceClasses) + return testAccInstanceConfig_orderableClass(tfrds.InstanceEnginePostgres, "postgresql-license", "standard") } func testAccInstanceConfig_orderableClassPostgresGP3() string { - return testAccInstanceConfig_orderableClass("postgres", "postgresql-license", "gp3", postgresPreferredInstanceClasses) + return testAccInstanceConfig_orderableClass(tfrds.InstanceEnginePostgres, "postgresql-license", "gp3") } func testAccInstanceConfig_orderableClassMariadb() string { - return testAccInstanceConfig_orderableClass("mariadb", "general-public-license", "standard", mariaDBPreferredInstanceClasses) + return testAccInstanceConfig_orderableClass(tfrds.InstanceEngineMariaDB, "general-public-license", "standard") } func testAccInstanceConfig_orderableClassSQLServerEx() string { - return testAccInstanceConfig_orderableClass("sqlserver-ex", "license-included", "standard", sqlServerPreferredInstanceClasses) + return testAccInstanceConfig_orderableClass(tfrds.InstanceEngineSQLServerExpress, "license-included", "standard") } func testAccInstanceConfig_orderableClassSQLServerExGP3() string { - return testAccInstanceConfig_orderableClass("sqlserver-ex", "license-included", "gp3", sqlServerPreferredInstanceClasses) + return testAccInstanceConfig_orderableClass(tfrds.InstanceEngineSQLServerExpress, "license-included", "gp3") } func testAccInstanceConfig_orderableClassSQLServerSe() string { - return testAccInstanceConfig_orderableClass("sqlserver-se", "license-included", "standard", sqlServerSEPreferredInstanceClasses) + return testAccInstanceConfig_orderableClass(tfrds.InstanceEngineSQLServerStandard, "license-included", "standard") } func testAccInstanceConfig_orderableClassCustomSQLServerWeb() string { - return testAccInstanceConfig_orderableClass("custom-sqlserver-web", "", "gp2", sqlServerCustomPreferredInstanceClasses) + return testAccInstanceConfig_orderableClass("custom-sqlserver-web", "", "gp2") } func testAccInstanceConfig_basic(rName string) string { @@ -6482,31 +6397,6 @@ resource "aws_db_instance" "test" { `, rName, customerId, siteId)) } -func testAccInstanceConfig_manage_password(rName string) string { - return acctest.ConfigCompose( - testAccInstanceConfig_orderableClassMySQL(), - fmt.Sprintf(` -resource "aws_db_instance" "test" { - identifier = %[1]q - allocated_storage = 10 - backup_retention_period = 0 - 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 - db_name = "test" - parameter_group_name = "default.${data.aws_rds_engine_version.default.parameter_group_family}" - skip_final_snapshot = true - username = "tfacctest" - manage_master_user_password = true - - # Maintenance Window is stored in lower case in the API, though not strictly - # documented. Terraform will downcase this to match (as opposed to throw a - # validation error). - maintenance_window = "Fri:09:00-Fri:09:30" -} -`, rName)) -} - func testAccInstanceConfig_identifierPrefix(identifierPrefix string) string { return acctest.ConfigCompose( testAccInstanceConfig_orderableClassMySQL(), @@ -6670,10 +6560,10 @@ resource "aws_db_instance" "test" { # validation error). maintenance_window = "Fri:09:00-Fri:09:30" } -`, rName, mySQLPreferredInstanceClasses)) +`, rName)) } -func testAccInstanceConfig_subnetGroup(rName string) string { +func testAccInstanceConfig_DBSubnetGroupName_basic(rName string) string { return acctest.ConfigCompose( testAccInstanceConfig_orderableClassMySQL(), acctest.ConfigVPCWithSubnets(rName, 2), @@ -6703,7 +6593,7 @@ resource "aws_db_instance" "test" { `, rName)) } -func testAccInstanceConfig_subnetGroupUpdated(rName string) string { +func testAccInstanceConfig_DBSubnetGroupName_update(rName string) string { return acctest.ConfigCompose( testAccInstanceConfig_orderableClassMySQL(), acctest.ConfigVPCWithSubnets(rName, 2), @@ -6836,7 +6726,7 @@ resource "aws_db_instance" "test" { func testAccInstanceConfig_iamAuth(rName string) string { return fmt.Sprintf(` data "aws_rds_engine_version" "default" { - engine = "mysql" + engine = %[1]q } data "aws_rds_orderable_db_instance" "test" { @@ -6844,13 +6734,13 @@ data "aws_rds_orderable_db_instance" "test" { engine_version = data.aws_rds_engine_version.default.version license_model = "general-public-license" storage_type = "standard" - preferred_instance_classes = [%[1]s] + preferred_instance_classes = [%[2]s] supports_iam_database_authentication = true } resource "aws_db_instance" "test" { - identifier = %[2]q + identifier = %[3]q allocated_storage = 10 engine = data.aws_rds_engine_version.default.engine engine_version = data.aws_rds_engine_version.default.version @@ -6863,7 +6753,7 @@ resource "aws_db_instance" "test" { parameter_group_name = "default.${data.aws_rds_engine_version.default.parameter_group_family}" iam_database_authentication_enabled = true } -`, mySQLPreferredInstanceClasses, rName) +`, tfrds.InstanceEngineMySQL, mainInstanceClasses, rName) } func testAccInstanceConfig_FinalSnapshotID_skipFinalSnapshot(rName string) string { @@ -6958,7 +6848,7 @@ resource "aws_iam_policy_attachment" "test" { } data "aws_rds_engine_version" "default" { - engine = "mysql" + engine = %[2]q } data "aws_rds_orderable_db_instance" "test" { @@ -6967,13 +6857,13 @@ data "aws_rds_orderable_db_instance" "test" { license_model = "general-public-license" storage_type = "standard" - # instance class db.t2.micro is not supported for restoring from S3 + # instance class db.t2.micro is not supported for restoring from S3 # TODO: can we search for instances restorable from s3? preferred_instance_classes = ["db.t3.small", "db.t2.small", "db.t2.medium", "db.t3.medium"] } -`, rName)) +`, rName, tfrds.InstanceEngineMySQL)) } -func testAccInstanceConfig_S3Import_basic(rName string) string { +func testAccInstanceConfig_s3Import(rName string) string { return acctest.ConfigCompose( testAccInstanceConfig_baseS3Import(rName), fmt.Sprintf(` @@ -7063,7 +6953,7 @@ resource "aws_iam_role_policy_attachment" "test" { } data "aws_rds_engine_version" "default" { - engine = "mysql" + engine = %[2]q } data "aws_rds_orderable_db_instance" "test" { @@ -7071,7 +6961,7 @@ data "aws_rds_orderable_db_instance" "test" { engine_version = data.aws_rds_engine_version.default.version license_model = "general-public-license" storage_type = "standard" - preferred_instance_classes = ["db.t3.small", "db.t2.small", "db.t2.medium"] + preferred_instance_classes = [%[3]s] supports_enhanced_monitoring = true } @@ -7084,20 +6974,20 @@ resource "aws_db_instance" "test" { engine_version = data.aws_rds_engine_version.default.version identifier = %[1]q instance_class = data.aws_rds_orderable_db_instance.test.instance_class - monitoring_interval = %[2]d + monitoring_interval = %[4]d monitoring_role_arn = aws_iam_role.test.arn db_name = "baz" password = "barbarbarbar" skip_final_snapshot = true username = "foo" } -`, rName, monitoringInterval) +`, rName, tfrds.InstanceEngineMySQL, mainInstanceClasses, monitoringInterval) } func testAccInstanceConfig_monitoringRoleARNRemoved(rName string) string { return fmt.Sprintf(` data "aws_rds_engine_version" "default" { - engine = "mysql" + engine = %[1]q } data "aws_rds_orderable_db_instance" "test" { @@ -7105,7 +6995,7 @@ data "aws_rds_orderable_db_instance" "test" { engine_version = data.aws_rds_engine_version.default.version license_model = "general-public-license" storage_type = "standard" - preferred_instance_classes = ["db.t3.small", "db.t2.small", "db.t2.medium"] + preferred_instance_classes = [%[2]s] supports_enhanced_monitoring = true } @@ -7114,14 +7004,14 @@ resource "aws_db_instance" "test" { allocated_storage = 5 engine = data.aws_rds_engine_version.default.engine engine_version = data.aws_rds_engine_version.default.version - identifier = %[1]q + identifier = %[3]q instance_class = data.aws_rds_orderable_db_instance.test.instance_class db_name = "baz" password = "barbarbarbar" skip_final_snapshot = true username = "foo" } -`, rName) +`, tfrds.InstanceEngineMySQL, mainInstanceClasses, rName) } func testAccInstanceConfig_monitoringRoleARN(rName string) string { @@ -7154,7 +7044,7 @@ resource "aws_iam_role_policy_attachment" "test" { } data "aws_rds_engine_version" "default" { - engine = "mysql" + engine = %[2]q } data "aws_rds_orderable_db_instance" "test" { @@ -7162,7 +7052,7 @@ data "aws_rds_orderable_db_instance" "test" { engine_version = data.aws_rds_engine_version.default.version license_model = "general-public-license" storage_type = "standard" - preferred_instance_classes = ["db.t3.small", "db.t2.small", "db.t2.medium"] + preferred_instance_classes = [%[3]s] supports_enhanced_monitoring = true } @@ -7182,7 +7072,7 @@ resource "aws_db_instance" "test" { skip_final_snapshot = true username = "foo" } -`, rName) +`, rName, tfrds.InstanceEngineMySQL, mainInstanceClasses) } func testAccInstanceConfig_baseForPITR(rName string) string { @@ -7278,21 +7168,21 @@ resource "aws_db_instance" "restore" { func testAccInstanceConfig_iopsUpdate(rName string, iops int) string { return fmt.Sprintf(` data "aws_rds_engine_version" "default" { - engine = "mysql" + engine = %[1]q } data "aws_rds_orderable_db_instance" "test" { engine = data.aws_rds_engine_version.default.engine engine_version = data.aws_rds_engine_version.default.version license_model = "general-public-license" - preferred_instance_classes = ["db.t3.micro", "db.t2.micro", "db.t2.medium"] + preferred_instance_classes = [%[2]s] storage_type = "io1" supports_iops = true } resource "aws_db_instance" "test" { - identifier = %[1]q + identifier = %[3]q engine = data.aws_rds_engine_version.default.engine engine_version = data.aws_rds_engine_version.default.version instance_class = data.aws_rds_orderable_db_instance.test.instance_class @@ -7306,9 +7196,9 @@ resource "aws_db_instance" "test" { storage_type = data.aws_rds_orderable_db_instance.test.storage_type allocated_storage = 200 - iops = %[2]d + iops = %[4]d } -`, rName, iops) +`, tfrds.InstanceEngineMySQL, mainInstanceClasses, rName, iops) } func testAccInstanceConfig_mySQLPort(rName string) string { @@ -7909,7 +7799,7 @@ resource "aws_security_group_rule" "test" { `, rName)) } -func testAccInstanceConfig_allowMajorVersionUpgrade(rName string, allowMajorVersionUpgrade bool) string { +func testAccInstanceConfig_Versions_allowMajor(rName string, allowMajorVersionUpgrade bool) string { return acctest.ConfigCompose(testAccInstanceConfig_orderableClassMySQL(), fmt.Sprintf(` resource "aws_db_instance" "test" { allocated_storage = 10 @@ -7944,7 +7834,7 @@ resource "aws_db_instance" "bar" { `, rName)) } -func testAccInstanceConfig_cloudWatchLogsExportConfiguration(rName string) string { +func testAccInstanceConfig_cloudWatchLogsExport(rName string) string { return acctest.ConfigCompose( testAccInstanceConfig_orderableClassMySQL(), testAccInstanceConfig_baseVPC(rName), @@ -7969,7 +7859,7 @@ resource "aws_db_instance" "test" { `, rName)) } -func testAccInstanceConfig_cloudWatchLogsExportConfigurationAdd(rName string) string { +func testAccInstanceConfig_cloudWatchLogsExportAdd(rName string) string { return acctest.ConfigCompose( testAccInstanceConfig_orderableClassMySQL(), testAccInstanceConfig_baseVPC(rName), @@ -7997,7 +7887,7 @@ resource "aws_db_instance" "test" { `, rName)) } -func testAccInstanceConfig_cloudWatchLogsExportConfigurationModify(rName string) string { +func testAccInstanceConfig_cloudWatchLogsExportModify(rName string) string { return acctest.ConfigCompose( testAccInstanceConfig_orderableClassMySQL(), testAccInstanceConfig_baseVPC(rName), @@ -8025,7 +7915,7 @@ resource "aws_db_instance" "test" { `, rName)) } -func testAccInstanceConfig_cloudWatchLogsExportConfigurationDelete(rName string) string { +func testAccInstanceConfig_cloudWatchLogsExportDelete(rName string) string { return acctest.ConfigCompose( testAccInstanceConfig_orderableClassMySQL(), testAccInstanceConfig_baseVPC(rName), @@ -8061,24 +7951,6 @@ resource "aws_db_instance" "test" { `, rName)) } -func testAccInstanceConfig_dbSubnetGroupName(rName string) string { - return acctest.ConfigCompose( - testAccInstanceConfig_orderableClassMySQL(), - testAccInstanceConfig_baseVPC(rName), - fmt.Sprintf(` -resource "aws_db_instance" "test" { - allocated_storage = 5 - db_subnet_group_name = aws_db_subnet_group.test.name - engine = data.aws_rds_orderable_db_instance.test.engine - identifier = %[1]q - instance_class = data.aws_rds_orderable_db_instance.test.instance_class - password = "avoid-plaintext-passwords" - username = "tfacctest" - skip_final_snapshot = true -} -`, rName)) -} - func testAccInstanceConfig_DBSubnetGroupName_ramShared(rName string) string { return acctest.ConfigCompose( testAccInstanceConfig_orderableClassMySQL(), @@ -8214,7 +8086,7 @@ resource "aws_db_instance" "test" { `, deletionProtection, rName)) } -func testAccInstanceConfig_EnabledCloudWatchLogsExports_db2(rName, customerId, siteId string) string { +func testAccInstanceConfig_CloudWatchLogsExport_db2(rName, customerId, siteId string) string { return acctest.ConfigCompose( testAccInstanceConfig_orderableClassDB2(), fmt.Sprintf(` @@ -8250,44 +8122,44 @@ resource "aws_db_instance" "test" { `, rName, customerId, siteId)) } -func testAccInstanceConfig_EnabledCloudWatchLogsExports_oracle(rName string) string { +func testAccInstanceConfig_CloudWatchLogsExport_oracle(rName string) string { return fmt.Sprintf(` data "aws_rds_orderable_db_instance" "test" { - engine = "oracle-se2" + engine = %[1]q license_model = "bring-your-own-license" storage_type = "standard" - preferred_instance_classes = ["db.m5.large", "db.m4.large", "db.r4.large"] + preferred_instance_classes = [%[2]s] } resource "aws_db_instance" "test" { allocated_storage = 10 enabled_cloudwatch_logs_exports = ["alert", "listener", "trace"] engine = data.aws_rds_orderable_db_instance.test.engine - identifier = %[1]q + identifier = %[3]q instance_class = data.aws_rds_orderable_db_instance.test.instance_class license_model = "bring-your-own-license" password = "avoid-plaintext-passwords" username = "tfacctest" skip_final_snapshot = true } -`, rName) +`, tfrds.InstanceEngineOracleStandard2, mainInstanceClasses, rName) } -func testAccInstanceConfig_NationalCharacterSet_oracle(rName string) string { +func testAccInstanceConfig_Oracle_nationalCharacterSet(rName string) string { return fmt.Sprintf(` data "aws_rds_orderable_db_instance" "test" { - engine = "oracle-se2" + engine = %[1]q license_model = "bring-your-own-license" storage_type = "standard" - preferred_instance_classes = ["db.m5.large", "db.m4.large", "db.r4.large"] + preferred_instance_classes = [%[2]s] } resource "aws_db_instance" "test" { allocated_storage = 10 engine = data.aws_rds_orderable_db_instance.test.engine - identifier = %[1]q + identifier = %[3]q instance_class = data.aws_rds_orderable_db_instance.test.instance_class license_model = "bring-your-own-license" nchar_character_set_name = "UTF8" @@ -8295,33 +8167,33 @@ resource "aws_db_instance" "test" { username = "tfacctest" skip_final_snapshot = true } -`, rName) +`, tfrds.InstanceEngineOracleStandard2, mainInstanceClasses, rName) } -func testAccInstanceConfig_NoNationalCharacterSet_oracle(rName string) string { +func testAccInstanceConfig_Oracle_noNationalCharacterSet(rName string) string { return fmt.Sprintf(` data "aws_rds_orderable_db_instance" "test" { - engine = "oracle-se2" + engine = %[1]q license_model = "bring-your-own-license" storage_type = "standard" - preferred_instance_classes = ["db.m5.large", "db.m4.large", "db.r4.large"] + preferred_instance_classes = [%[2]s] } resource "aws_db_instance" "test" { allocated_storage = 10 engine = data.aws_rds_orderable_db_instance.test.engine - identifier = %[1]q + identifier = %[3]q instance_class = data.aws_rds_orderable_db_instance.test.instance_class license_model = "bring-your-own-license" password = "avoid-plaintext-passwords" username = "tfacctest" skip_final_snapshot = true } -`, rName) +`, tfrds.InstanceEngineOracleStandard2, mainInstanceClasses, rName) } -func testAccInstanceConfig_EnabledCloudWatchLogsExports_mssql(rName string) string { +func testAccInstanceConfig_CloudWatchLogsExport_mssql(rName string) string { return acctest.ConfigCompose( testAccInstanceConfig_orderableClassSQLServerSe(), fmt.Sprintf(` @@ -8339,7 +8211,7 @@ resource "aws_db_instance" "test" { `, rName)) } -func testAccInstanceConfig_EnabledCloudWatchLogsExports_postgreSQL(rName string) string { +func testAccInstanceConfig_CloudWatchLogsExport_postgreSQL(rName string) string { return acctest.ConfigCompose(testAccInstanceConfig_orderableClassPostgres(), fmt.Sprintf(` resource "aws_db_instance" "test" { allocated_storage = 10 @@ -8354,7 +8226,7 @@ resource "aws_db_instance" "test" { `, rName)) } -func testAccInstanceConfig_maxAllocatedStorage(rName string, maxAllocatedStorage int) string { +func testAccInstanceConfig_Storage_maxAllocated(rName string, maxAllocatedStorage int) string { return acctest.ConfigCompose(testAccInstanceConfig_orderableClassMySQL(), fmt.Sprintf(` resource "aws_db_instance" "test" { allocated_storage = 5 @@ -8385,21 +8257,25 @@ resource "aws_db_instance" "test" { `, rName, password)) } -func testAccInstanceConfig_managedMasterPassword(rName string) string { - return acctest.ConfigCompose(testAccInstanceConfig_orderableClassMySQL(), fmt.Sprintf(` +func testAccInstanceConfig_manageMasterPassword(rName string) string { + return acctest.ConfigCompose( + testAccInstanceConfig_orderableClassMySQL(), + fmt.Sprintf(` resource "aws_db_instance" "test" { allocated_storage = 5 + backup_retention_period = 0 engine = data.aws_rds_orderable_db_instance.test.engine + engine_version = data.aws_rds_orderable_db_instance.test.engine_version identifier = %[1]q instance_class = data.aws_rds_orderable_db_instance.test.instance_class manage_master_user_password = true - username = "tfacctest" skip_final_snapshot = true + username = "tfacctest" } `, rName)) } -func testAccInstanceConfig_managedMasterPasswordKMSKey(rName string) string { +func testAccInstanceConfig_manageMasterPasswordKMSKey(rName string) string { return acctest.ConfigCompose(testAccInstanceConfig_orderableClassMySQL(), fmt.Sprintf(` data "aws_caller_identity" "current" {} data "aws_partition" "current" {} @@ -8589,12 +8465,26 @@ resource "aws_db_instance" "test" { func testAccInstanceConfig_ReplicateSourceDB_iops(rName string, iops int) string { return fmt.Sprintf(` +data "aws_rds_engine_version" "default" { + engine = %[1]q +} + +data "aws_rds_orderable_db_instance" "test" { + engine = data.aws_rds_engine_version.default.engine + engine_version = data.aws_rds_engine_version.default.version + license_model = "general-public-license" + preferred_instance_classes = [%[2]s] + + storage_type = "io1" + supports_iops = true +} + resource "aws_db_instance" "source" { allocated_storage = 200 backup_retention_period = 1 - engine = "mysql" - identifier = "%[1]s-source" - instance_class = "db.t2.micro" + engine = data.aws_rds_orderable_db_instance.test.engine + identifier = "%[3]s-source" + instance_class = data.aws_rds_orderable_db_instance.test.instance_class password = "avoid-plaintext-passwords" username = "tfacctest" skip_final_snapshot = true @@ -8603,24 +8493,38 @@ resource "aws_db_instance" "source" { } resource "aws_db_instance" "test" { - identifier = %[1]q + identifier = %[3]q instance_class = aws_db_instance.source.instance_class replicate_source_db = aws_db_instance.source.identifier skip_final_snapshot = true - iops = %[2]d + iops = %[4]d storage_type = "io1" } -`, rName, iops) +`, tfrds.InstanceEngineMySQL, mainInstanceClasses, rName, iops) } func testAccInstanceConfig_ReplicateSourceDB_allocatedStorageAndIOPS(rName string, allocatedStorage, iops int) string { return fmt.Sprintf(` +data "aws_rds_engine_version" "default" { + engine = %[1]q +} + +data "aws_rds_orderable_db_instance" "test" { + engine = data.aws_rds_engine_version.default.engine + engine_version = data.aws_rds_engine_version.default.version + license_model = "general-public-license" + preferred_instance_classes = [%[2]s] + + storage_type = "io1" + supports_iops = true +} + resource "aws_db_instance" "source" { - allocated_storage = %[2]d + allocated_storage = %[3]d backup_retention_period = 1 - engine = "mysql" - identifier = "%[1]s-source" - instance_class = "db.t2.micro" + engine = data.aws_rds_orderable_db_instance.test.engine + identifier = "%[4]s-source" + instance_class = data.aws_rds_orderable_db_instance.test.instance_class password = "avoid-plaintext-passwords" username = "tfacctest" skip_final_snapshot = true @@ -8629,15 +8533,15 @@ resource "aws_db_instance" "source" { } resource "aws_db_instance" "test" { - allocated_storage = %[2]d - identifier = %[1]q + allocated_storage = %[3]d + identifier = %[4]q instance_class = aws_db_instance.source.instance_class replicate_source_db = aws_db_instance.source.identifier skip_final_snapshot = true - iops = %[3]d + iops = %[5]d storage_type = "io1" } -`, rName, allocatedStorage, iops) +`, tfrds.InstanceEngineMySQL, mainInstanceClasses, allocatedStorage, rName, iops) } func testAccInstanceConfig_ReplicateSourceDB_allowMajorVersionUpgrade(rName string, allowMajorVersionUpgrade bool) string { @@ -8834,7 +8738,7 @@ resource "aws_db_subnet_group" "test" { data "aws_rds_engine_version" "default" { provider = "awsalternate" - engine = "mysql" + engine = %[2]q } data "aws_rds_orderable_db_instance" "test" { @@ -8845,7 +8749,7 @@ data "aws_rds_orderable_db_instance" "test" { license_model = "general-public-license" storage_type = "standard" - preferred_instance_classes = [%[2]s] + preferred_instance_classes = [%[3]s] } resource "aws_db_instance" "source" { @@ -8869,7 +8773,7 @@ resource "aws_db_instance" "test" { replicate_source_db = aws_db_instance.source.arn skip_final_snapshot = true } -`, rName, mySQLPreferredInstanceClasses)) +`, rName, tfrds.InstanceEngineMySQL, mainInstanceClasses)) } // When testing needs to distinguish a second region and second account in the same region @@ -9012,7 +8916,7 @@ resource "aws_security_group" "test" { data "aws_rds_engine_version" "default" { provider = "awssameaccountalternateregion" - engine = "mysql" + engine = %[2]q } data "aws_rds_orderable_db_instance" "test" { @@ -9023,7 +8927,7 @@ data "aws_rds_orderable_db_instance" "test" { license_model = "general-public-license" storage_type = "standard" - preferred_instance_classes = [%[2]s] + preferred_instance_classes = [%[3]s] } resource "aws_db_instance" "source" { @@ -9049,7 +8953,7 @@ resource "aws_db_instance" "test" { skip_final_snapshot = true vpc_security_group_ids = [aws_security_group.test.id] } -`, rName, mySQLPreferredInstanceClasses)) +`, rName, tfrds.InstanceEngineMySQL, mainInstanceClasses)) } func testAccInstanceConfig_ReplicateSourceDB_DBSubnetGroupName_vpcSecurityGroupIDs(rName string) string { @@ -9130,7 +9034,7 @@ resource "aws_db_subnet_group" "test" { data "aws_rds_engine_version" "default" { provider = "awsalternate" - engine = "mysql" + engine = %[2]q } data "aws_rds_orderable_db_instance" "test" { @@ -9141,7 +9045,7 @@ data "aws_rds_orderable_db_instance" "test" { license_model = "general-public-license" storage_type = "standard" - preferred_instance_classes = [%[2]s] + preferred_instance_classes = [%[3]s] } resource "aws_db_instance" "source" { @@ -9166,7 +9070,7 @@ resource "aws_db_instance" "test" { skip_final_snapshot = true vpc_security_group_ids = [aws_security_group.test.id] } -`, rName, mySQLPreferredInstanceClasses)) +`, rName, tfrds.InstanceEngineMySQL, mainInstanceClasses)) } func testAccInstanceConfig_ReplicateSourceDB_deletionProtection(rName string, deletionProtection bool) string { @@ -9607,20 +9511,20 @@ resource "aws_db_instance" "test" { func testAccInstanceConfig_ReplicateSourceDB_replicaMode(rName, replicaMode string) string { return fmt.Sprintf(` data "aws_rds_engine_version" "default" { - engine = "oracle-ee" + engine = %[1]q } data "aws_rds_orderable_db_instance" "test" { - engine = data.aws_rds_engine_version.default.engine - engine_version = data.aws_rds_engine_version.default.version - license_model = "bring-your-own-license" - storage_type = "gp2" - - preferred_instance_classes = [%[1]s] + engine = data.aws_rds_engine_version.default.engine + engine_version = data.aws_rds_engine_version.default.version + license_model = "bring-your-own-license" + storage_type = "gp2" + read_replica_capable = true + preferred_instance_classes = [%[2]s] } resource "aws_db_instance" "source" { - identifier = "%[2]s-source" + identifier = "%[3]s-source" allocated_storage = 20 backup_retention_period = 1 engine = data.aws_rds_orderable_db_instance.test.engine @@ -9633,32 +9537,32 @@ resource "aws_db_instance" "source" { } resource "aws_db_instance" "test" { - identifier = %[2]q + identifier = %[3]q instance_class = aws_db_instance.source.instance_class - replica_mode = %[3]q + replica_mode = %[4]q replicate_source_db = aws_db_instance.source.identifier skip_final_snapshot = true } -`, oraclePreferredInstanceClasses, rName, replicaMode) +`, tfrds.InstanceEngineOracleEnterprise, strings.Replace(mainInstanceClasses, "db.t3.small", "frodo", 1), rName, replicaMode) } func testAccInstanceConfig_ReplicateSourceDB_ParameterGroupTwoStep_setup(rName string) string { return fmt.Sprintf(` data "aws_rds_engine_version" "default" { - engine = "oracle-ee" + engine = %[1]q } data "aws_rds_orderable_db_instance" "test" { - engine = data.aws_rds_engine_version.default.engine - engine_version = data.aws_rds_engine_version.default.version - license_model = "bring-your-own-license" - storage_type = "gp2" - + engine = data.aws_rds_engine_version.default.engine + engine_version = data.aws_rds_engine_version.default.version + license_model = "bring-your-own-license" + storage_type = "gp2" + read_replica_capable = true preferred_instance_classes = [%[2]s] } resource "aws_db_instance" "source" { - identifier = "%[1]s-source" + identifier = "%[3]s-source" allocated_storage = 20 engine = data.aws_rds_orderable_db_instance.test.engine engine_version = data.aws_rds_orderable_db_instance.test.engine_version @@ -9678,7 +9582,7 @@ resource "aws_db_instance" "source" { } ca_cert_identifier = "rds-ca-2019" } -`, rName, oraclePreferredInstanceClasses) +`, tfrds.InstanceEngineOracleEnterprise, strings.Replace(mainInstanceClasses, "db.t3.small", "frodo", 1), rName) } func testAccInstanceConfig_ReplicateSourceDB_parameterGroupTwoStep(rName string) string { @@ -9767,7 +9671,7 @@ resource "aws_db_instance" "test" { `, rName)) } -func testAccInstanceConfig_snapshotID_ManagedMasterPasswordKMSKey(rName string) string { +func testAccInstanceConfig_snapshotID_ManageMasterPasswordKMSKey(rName string) string { return acctest.ConfigCompose( testAccInstanceConfig_orderableClassMariadb(), fmt.Sprintf(` @@ -9935,18 +9839,18 @@ resource "aws_db_instance" "test" { func testAccInstanceConfig_SnapshotID_io1Storage(rName string, iops int) string { return fmt.Sprintf(` data "aws_rds_orderable_db_instance" "test" { - engine = "mariadb" - engine_version = "10.6.12" - license_model = "general-public-license" - storage_type = "io1" + engine = %[1]q + engine_latest_version = true + license_model = "general-public-license" + storage_type = "io1" - preferred_instance_classes = ["db.t3.micro", "db.t2.micro", "db.t2.medium"] + preferred_instance_classes = [%[2]s] } resource "aws_db_instance" "source" { allocated_storage = 200 engine = data.aws_rds_orderable_db_instance.test.engine - identifier = "%[1]s-source" + identifier = "%[3]s-source" instance_class = data.aws_rds_orderable_db_instance.test.instance_class password = "avoid-plaintext-passwords" username = "tfacctest" @@ -9955,37 +9859,47 @@ resource "aws_db_instance" "source" { resource "aws_db_snapshot" "test" { db_instance_identifier = aws_db_instance.source.identifier - db_snapshot_identifier = %[1]q + db_snapshot_identifier = %[3]q } resource "aws_db_instance" "test" { - identifier = %[1]q + identifier = %[3]q instance_class = aws_db_instance.source.instance_class snapshot_identifier = aws_db_snapshot.test.id skip_final_snapshot = true allocated_storage = 200 - iops = %[2]d + iops = %[4]d storage_type = data.aws_rds_orderable_db_instance.test.storage_type } -`, rName, iops) +`, tfrds.InstanceEngineMariaDB, mainInstanceClasses, rName, iops) } func testAccInstanceConfig_SnapshotID_allowMajorVersionUpgrade(rName string, allowMajorVersionUpgrade bool) string { return fmt.Sprintf(` +data "aws_rds_engine_version" "test" { + engine = %[1]q + latest = true + preferred_major_targets = [data.aws_rds_engine_version.upgrade.version_actual] +} + +data "aws_rds_engine_version" "upgrade" { + engine = %[1]q +} + data "aws_rds_orderable_db_instance" "postgres13" { - engine = "postgres" - engine_version = "13.12" + engine = %[1]q + engine_version = data.aws_rds_engine_version.test.version_actual license_model = "postgresql-license" storage_type = "standard" - preferred_instance_classes = ["db.t3.micro", "db.t2.micro", "db.t2.medium"] + preferred_instance_classes = [%[2]s] } resource "aws_db_instance" "source" { allocated_storage = 5 engine = data.aws_rds_orderable_db_instance.postgres13.engine engine_version = data.aws_rds_orderable_db_instance.postgres13.engine_version - identifier = "%[1]s-source" + identifier = "%[3]s-source" instance_class = data.aws_rds_orderable_db_instance.postgres13.instance_class password = "avoid-plaintext-passwords" username = "tfacctest" @@ -9994,28 +9908,28 @@ resource "aws_db_instance" "source" { resource "aws_db_snapshot" "test" { db_instance_identifier = aws_db_instance.source.identifier - db_snapshot_identifier = %[1]q + db_snapshot_identifier = %[3]q } data "aws_rds_orderable_db_instance" "postgres14" { - engine = "postgres" - engine_version = "14.9" + engine = %[1]q + engine_version = data.aws_rds_engine_version.upgrade.version_actual license_model = "postgresql-license" storage_type = "standard" - preferred_instance_classes = ["db.t3.micro", "db.t2.micro", "db.t2.medium"] + preferred_instance_classes = [%[2]s] } resource "aws_db_instance" "test" { - allow_major_version_upgrade = %[2]t + allow_major_version_upgrade = %[4]t engine = data.aws_rds_orderable_db_instance.postgres14.engine engine_version = data.aws_rds_orderable_db_instance.postgres14.engine_version - identifier = %[1]q + identifier = %[3]q instance_class = aws_db_instance.source.instance_class snapshot_identifier = aws_db_snapshot.test.id skip_final_snapshot = true } -`, rName, allowMajorVersionUpgrade) +`, tfrds.InstanceEnginePostgres, mainInstanceClasses, rName, allowMajorVersionUpgrade) } func testAccInstanceConfig_SnapshotID_autoMinorVersionUpgrade(rName string, autoMinorVersionUpgrade bool) string { @@ -10105,7 +10019,7 @@ resource "aws_db_instance" "test" { func testAccInstanceConfig_SnapshotID_BackupRetentionPeriod_unset(rName string) string { return acctest.ConfigCompose(testAccInstanceConfig_orderableClassMariadb(), fmt.Sprintf(` resource "aws_db_instance" "source" { - allocated_storage = 5 + allocated_storage = 10 backup_retention_period = 1 engine = data.aws_rds_orderable_db_instance.test.engine identifier = "%[1]s-source" @@ -10135,7 +10049,7 @@ resource "aws_db_instance" "test" { func testAccInstanceConfig_SnapshotID_backupWindow(rName, backupWindow, maintenanceWindow string) string { return acctest.ConfigCompose(testAccInstanceConfig_orderableClassMariadb(), fmt.Sprintf(` resource "aws_db_instance" "source" { - allocated_storage = 5 + allocated_storage = 10 engine = data.aws_rds_orderable_db_instance.test.engine identifier = "%[1]s-source" instance_class = data.aws_rds_orderable_db_instance.test.instance_class @@ -10632,7 +10546,7 @@ func testAccInstanceConfig_SnapshotID_tags(rName string) string { testAccInstanceConfig_orderableClassMariadb(), fmt.Sprintf(` resource "aws_db_instance" "source" { - allocated_storage = 5 + allocated_storage = 10 engine = data.aws_rds_orderable_db_instance.test.engine identifier = "%[1]s-source" instance_class = data.aws_rds_orderable_db_instance.test.instance_class @@ -10776,7 +10690,7 @@ resource "aws_db_instance" "test" { func testAccInstanceConfig_performanceInsightsDisabled(rName string) string { return fmt.Sprintf(` data "aws_rds_engine_version" "default" { - engine = "mysql" + engine = %[1]q } data "aws_rds_orderable_db_instance" "test" { @@ -10785,7 +10699,7 @@ data "aws_rds_orderable_db_instance" "test" { license_model = "general-public-license" storage_type = "standard" supports_performance_insights = true - preferred_instance_classes = ["db.m3.medium", "db.m3.large", "db.m4.large"] + preferred_instance_classes = [%[2]s] } resource "aws_db_instance" "test" { @@ -10793,20 +10707,20 @@ resource "aws_db_instance" "test" { backup_retention_period = 0 engine = data.aws_rds_engine_version.default.engine engine_version = data.aws_rds_engine_version.default.version - identifier = %[1]q + identifier = %[3]q instance_class = data.aws_rds_orderable_db_instance.test.instance_class db_name = "mydb" password = "mustbeeightcharaters" skip_final_snapshot = true username = "foo" } -`, rName) +`, tfrds.InstanceEngineMySQL, mainInstanceClasses, rName) } func testAccInstanceConfig_performanceInsightsEnabled(rName string) string { return fmt.Sprintf(` data "aws_rds_engine_version" "default" { - engine = "mysql" + engine = %[1]q } data "aws_rds_orderable_db_instance" "test" { @@ -10815,7 +10729,7 @@ data "aws_rds_orderable_db_instance" "test" { license_model = "general-public-license" storage_type = "standard" supports_performance_insights = true - preferred_instance_classes = ["db.m3.medium", "db.m3.large", "db.m4.large"] + preferred_instance_classes = [%[2]s] } resource "aws_db_instance" "test" { @@ -10823,7 +10737,7 @@ resource "aws_db_instance" "test" { backup_retention_period = 0 engine = data.aws_rds_engine_version.default.engine engine_version = data.aws_rds_engine_version.default.version - identifier = %[1]q + identifier = %[3]q instance_class = data.aws_rds_orderable_db_instance.test.instance_class db_name = "mydb" password = "mustbeeightcharaters" @@ -10832,7 +10746,7 @@ resource "aws_db_instance" "test" { skip_final_snapshot = true username = "foo" } -`, rName) +`, tfrds.InstanceEngineMySQL, mainInstanceClasses, rName) } func testAccInstanceConfig_performanceInsightsKMSKeyIdDisabled(rName string) string { @@ -10842,7 +10756,7 @@ resource "aws_kms_key" "test" { } data "aws_rds_engine_version" "default" { - engine = "mysql" + engine = %[1]q } data "aws_rds_orderable_db_instance" "test" { @@ -10851,21 +10765,22 @@ data "aws_rds_orderable_db_instance" "test" { license_model = "general-public-license" storage_type = "standard" supports_performance_insights = true - preferred_instance_classes = ["db.m3.medium", "db.m3.large", "db.m4.large"] + preferred_instance_classes = [%[2]s] } resource "aws_db_instance" "test" { - engine = data.aws_rds_engine_version.default.engine - identifier = %[1]q - instance_class = data.aws_rds_orderable_db_instance.test.instance_class allocated_storage = 5 backup_retention_period = 0 db_name = "mydb" - username = "foo" + engine = data.aws_rds_engine_version.default.engine + engine_version = data.aws_rds_engine_version.default.version + identifier = %[3]q + instance_class = data.aws_rds_orderable_db_instance.test.instance_class password = "mustbeeightcharaters" skip_final_snapshot = true + username = "foo" } -`, rName) +`, tfrds.InstanceEngineMySQL, mainInstanceClasses, rName) } func testAccInstanceConfig_performanceInsightsKMSKeyID(rName string) string { @@ -10875,7 +10790,7 @@ resource "aws_kms_key" "test" { } data "aws_rds_engine_version" "default" { - engine = "mysql" + engine = %[1]q } data "aws_rds_orderable_db_instance" "test" { @@ -10884,17 +10799,17 @@ data "aws_rds_orderable_db_instance" "test" { license_model = "general-public-license" storage_type = "standard" supports_performance_insights = true - preferred_instance_classes = ["db.m3.medium", "db.m3.large", "db.m4.large"] + preferred_instance_classes = [%[2]s] } resource "aws_db_instance" "test" { allocated_storage = 5 backup_retention_period = 0 + db_name = "mydb" engine = data.aws_rds_engine_version.default.engine engine_version = data.aws_rds_engine_version.default.version - identifier = %[1]q + identifier = %[3]q instance_class = data.aws_rds_orderable_db_instance.test.instance_class - db_name = "mydb" password = "mustbeeightcharaters" performance_insights_enabled = true performance_insights_kms_key_id = aws_kms_key.test.arn @@ -10902,13 +10817,13 @@ resource "aws_db_instance" "test" { skip_final_snapshot = true username = "foo" } -`, rName) +`, tfrds.InstanceEngineMySQL, mainInstanceClasses, rName) } func testAccInstanceConfig_performanceInsightsRetentionPeriod(rName string, performanceInsightsRetentionPeriod int) string { return fmt.Sprintf(` data "aws_rds_engine_version" "default" { - engine = "mysql" + engine = %[1]q } data "aws_rds_orderable_db_instance" "test" { @@ -10917,7 +10832,7 @@ data "aws_rds_orderable_db_instance" "test" { license_model = "general-public-license" storage_type = "standard" supports_performance_insights = true - preferred_instance_classes = ["db.m3.medium", "db.m3.large", "db.m4.large"] + preferred_instance_classes = [%[2]s] } resource "aws_db_instance" "test" { @@ -10925,16 +10840,16 @@ resource "aws_db_instance" "test" { backup_retention_period = 0 engine = data.aws_rds_engine_version.default.engine engine_version = data.aws_rds_engine_version.default.version - identifier = %[1]q + identifier = %[3]q instance_class = data.aws_rds_orderable_db_instance.test.instance_class db_name = "mydb" password = "mustbeeightcharaters" performance_insights_enabled = true - performance_insights_retention_period = %[2]d + performance_insights_retention_period = %[4]d skip_final_snapshot = true username = "foo" } -`, rName, performanceInsightsRetentionPeriod) +`, tfrds.InstanceEngineMySQL, mainInstanceClasses, rName, performanceInsightsRetentionPeriod) } func testAccInstanceConfig_ReplicateSourceDB_performanceInsightsEnabled(rName string) string { @@ -10965,7 +10880,7 @@ POLICY } data "aws_rds_engine_version" "default" { - engine = "mysql" + engine = %[1]q } data "aws_rds_orderable_db_instance" "test" { @@ -10974,7 +10889,7 @@ data "aws_rds_orderable_db_instance" "test" { license_model = "general-public-license" storage_type = "standard" supports_performance_insights = true - preferred_instance_classes = ["db.m3.medium", "db.m3.large", "db.m4.large"] + preferred_instance_classes = [%[2]s] } resource "aws_db_instance" "source" { @@ -10982,7 +10897,7 @@ resource "aws_db_instance" "source" { backup_retention_period = 1 engine = data.aws_rds_engine_version.default.engine engine_version = data.aws_rds_engine_version.default.version - identifier = "%[1]s-source" + identifier = "%[3]s-source" instance_class = data.aws_rds_orderable_db_instance.test.instance_class password = "mustbeeightcharaters" username = "tfacctest" @@ -10990,7 +10905,7 @@ resource "aws_db_instance" "source" { } resource "aws_db_instance" "test" { - identifier = %[1]q + identifier = %[3]q instance_class = aws_db_instance.source.instance_class performance_insights_enabled = true performance_insights_kms_key_id = aws_kms_key.test.arn @@ -10998,7 +10913,7 @@ resource "aws_db_instance" "test" { replicate_source_db = aws_db_instance.source.identifier skip_final_snapshot = true } -`, rName) +`, tfrds.InstanceEngineMySQL, mainInstanceClasses, rName) } func testAccInstanceConfig_SnapshotID_performanceInsightsEnabled(rName string) string { @@ -11029,7 +10944,7 @@ POLICY } data "aws_rds_engine_version" "default" { - engine = "mysql" + engine = %[1]q } data "aws_rds_orderable_db_instance" "test" { @@ -11038,14 +10953,14 @@ data "aws_rds_orderable_db_instance" "test" { license_model = "general-public-license" storage_type = "standard" supports_performance_insights = true - preferred_instance_classes = ["db.m3.medium", "db.m3.large", "db.m4.large"] + preferred_instance_classes = [%[2]s] } resource "aws_db_instance" "source" { allocated_storage = 5 engine = data.aws_rds_engine_version.default.engine engine_version = data.aws_rds_engine_version.default.version - identifier = "%[1]s-source" + identifier = "%[3]s-source" instance_class = data.aws_rds_orderable_db_instance.test.instance_class password = "avoid-plaintext-passwords" username = "tfacctest" @@ -11054,11 +10969,11 @@ resource "aws_db_instance" "source" { resource "aws_db_snapshot" "test" { db_instance_identifier = aws_db_instance.source.identifier - db_snapshot_identifier = %[1]q + db_snapshot_identifier = %[3]q } resource "aws_db_instance" "test" { - identifier = %[1]q + identifier = %[3]q instance_class = aws_db_instance.source.instance_class performance_insights_enabled = true performance_insights_kms_key_id = aws_kms_key.test.arn @@ -11066,7 +10981,7 @@ resource "aws_db_instance" "test" { snapshot_identifier = aws_db_snapshot.test.id skip_final_snapshot = true } -`, rName) +`, tfrds.InstanceEngineMySQL, mainInstanceClasses, rName) } func testAccInstanceConfig_noDeleteAutomatedBackups(rName string) string { @@ -11088,7 +11003,7 @@ resource "aws_db_instance" "test" { func testAccInstanceConfig_baseOutpost(rName string) string { return acctest.ConfigCompose( - testAccInstanceConfig_orderableClass("mysql", "general-public-license", "standard", outpostPreferredInstanceClasses), + testAccInstanceConfig_orderableClass(tfrds.InstanceEngineMySQL, "general-public-license", "standard"), fmt.Sprintf(` data "aws_outposts_outposts" "test" {} @@ -11158,7 +11073,7 @@ resource "aws_db_instance" "test" { `, rName, coipEnabled, backupRetentionPeriod)) } -func testAccInstanceConfig_CoIPEnabled_restorePointInTime(rName string, sourceCoipEnabled bool, targetCoipEnabled bool) string { +func testAccInstanceConfig_Outposts_coIPRestorePointInTime(rName string, sourceCoipEnabled bool, targetCoipEnabled bool) string { return acctest.ConfigCompose( testAccInstanceConfig_Outpost_coIPEnabled(rName, sourceCoipEnabled, 1), fmt.Sprintf(` @@ -11177,7 +11092,7 @@ resource "aws_db_instance" "restore" { `, rName, targetCoipEnabled)) } -func testAccInstanceConfig_CoIPEnabled_snapshotID(rName string, sourceCoipEnabled bool, targetCoipEnabled bool) string { +func testAccInstanceConfig_Outposts_coIPSnapshotID(rName string, sourceCoipEnabled bool, targetCoipEnabled bool) string { return acctest.ConfigCompose(testAccInstanceConfig_Outpost_coIPEnabled(rName, sourceCoipEnabled, 1), fmt.Sprintf(` resource "aws_db_snapshot" "test" { db_instance_identifier = aws_db_instance.test.identifier @@ -11196,7 +11111,7 @@ resource "aws_db_instance" "restore" { `, rName, targetCoipEnabled)) } -func testAccInstanceConfig_Outpost_BackupTarget(rName string, backupTarget string, backupRetentionPeriod int) string { +func testAccInstanceConfig_Outposts_backupTarget(rName string, backupTarget string, backupRetentionPeriod int) string { return acctest.ConfigCompose( testAccInstanceConfig_baseOutpost(rName), fmt.Sprintf(` @@ -11221,7 +11136,7 @@ resource "aws_db_instance" "test" { func testAccInstanceConfig_license(rName, license string) string { return acctest.ConfigCompose( - testAccInstanceConfig_orderableClass("oracle-se2", license, "standard", oracleSE2PreferredInstanceClasses), + testAccInstanceConfig_orderableClass(tfrds.InstanceEngineOracleStandard2, license, "standard"), fmt.Sprintf(` resource "aws_db_instance" "test" { apply_immediately = true @@ -11265,7 +11180,7 @@ resource "aws_db_instance" "test" { `, rName)) } -func testAccInstanceConfig_BlueGreenDeployment_engineVersion(rName string, updated bool) string { +func testAccInstanceConfig_BlueGreenDeployment_engineVersion(rName string, update bool) string { return acctest.ConfigCompose( fmt.Sprintf(` resource "aws_db_instance" "test" { @@ -11292,33 +11207,54 @@ data "aws_rds_orderable_db_instance" "test" { license_model = "general-public-license" storage_type = "standard" - preferred_instance_classes = [%[3]s] + preferred_instance_classes = [%[2]s] } data "aws_rds_engine_version" "initial" { - engine = "mysql" - preferred_versions = ["8.0.31", "8.0.30", "8.0.28"] + engine = %[3]q + latest = true + preferred_upgrade_targets = [data.aws_rds_engine_version.update.version_actual] } -data "aws_rds_engine_version" "updated" { - engine = data.aws_rds_engine_version.initial.engine - preferred_versions = data.aws_rds_engine_version.initial.valid_upgrade_targets +data "aws_rds_engine_version" "update" { + engine = %[3]q } locals { - engine_version = %[2]t ? data.aws_rds_engine_version.updated : data.aws_rds_engine_version.initial + engine_version = %[4]t ? data.aws_rds_engine_version.update : data.aws_rds_engine_version.initial } -`, rName, updated, mySQLPreferredInstanceClasses)) +`, rName, mainInstanceClasses, tfrds.InstanceEngineMySQL, update)) +} + +func testAccInstanceConfig_BlueGreenDeployment_pre(rName string, oddClasses bool) string { + var halfClasses []string + start := 0 + if oddClasses { + start = 1 + } + for i := start; i < len(instanceClassesSlice); i += 2 { + halfClasses = append(halfClasses, instanceClassesSlice[i]) + } + halfMainInstClass := strings.Join(halfClasses, ", ") + + return fmt.Sprintf(` +data "aws_rds_engine_version" "default" { + engine = %[1]q +} + +data "aws_rds_orderable_db_instance" "test" { + 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 = [%[4]s] } -func testAccInstanceConfig_BlueGreenDeployment_basic(rName string) string { - return acctest.ConfigCompose( - testAccInstanceConfig_orderableClassMySQL(), - fmt.Sprintf(` resource "aws_db_instance" "test" { - identifier = %[1]q + identifier = %[5]q allocated_storage = 10 - backup_retention_period = 1 + backup_retention_period = 0 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 @@ -11328,11 +11264,12 @@ resource "aws_db_instance" "test" { password = "avoid-plaintext-passwords" username = "tfacctest" - blue_green_update { - enabled = true - } + # Maintenance Window is stored in lower case in the API, though not strictly + # documented. Terraform will downcase this to match (as opposed to throw a + # validation error). + maintenance_window = "Fri:09:00-Fri:09:30" } -`, rName)) +`, tfrds.InstanceEngineMySQL, "general-public-license", "standard", halfMainInstClass, rName) } func testAccInstanceConfig_BlueGreenDeployment_parameterGroup(rName string) string { @@ -11397,17 +11334,21 @@ resource "aws_db_instance" "test" { `, rName, tagKey1, tagValue1)) } -func testAccInstanceConfig_BlueGreenDeployment_updateInstanceClass(rName string) string { +func testAccInstanceConfig_BlueGreenDeployment_basic(rName string) string { return acctest.ConfigCompose( testAccInstanceConfig_orderableClassMySQL(), fmt.Sprintf(` +data "aws_db_parameter_group" "test" { + name = "default.${data.aws_rds_engine_version.default.parameter_group_family}" +} + resource "aws_db_instance" "test" { identifier = %[1]q allocated_storage = 10 backup_retention_period = 1 - engine = data.aws_rds_orderable_db_instance.updated.engine - engine_version = data.aws_rds_orderable_db_instance.updated.engine_version - instance_class = data.aws_rds_orderable_db_instance.updated.instance_class + 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 db_name = "test" parameter_group_name = "default.${data.aws_rds_engine_version.default.parameter_group_family}" skip_final_snapshot = true @@ -11418,27 +11359,99 @@ resource "aws_db_instance" "test" { enabled = true } } +`, rName)) +} + +func testAccInstanceConfig_BlueGreenDeployment_updateableInstanceClass(rName string, oddClasses bool) string { + var halfClasses []string + start := 0 + if oddClasses { + start = 1 + } + for i := start; i < len(instanceClassesSlice); i += 2 { + halfClasses = append(halfClasses, instanceClassesSlice[i]) + } + halfMainInstClass := strings.Join(halfClasses, ", ") -data "aws_rds_orderable_db_instance" "updated" { + return fmt.Sprintf(` +data "aws_rds_engine_version" "default" { + engine = %[1]q +} + +data "aws_rds_orderable_db_instance" "test" { engine = data.aws_rds_engine_version.default.engine engine_version = data.aws_rds_engine_version.default.version - license_model = "general-public-license" - storage_type = "standard" + license_model = %[2]q + storage_type = %[3]q - preferred_instance_classes = ["db.t4g.micro", "db.t4g.small"] + preferred_instance_classes = [%[4]s] } -`, rName)) + +data "aws_db_parameter_group" "test" { + name = "default.${data.aws_rds_engine_version.default.parameter_group_family}" +} + +resource "aws_db_instance" "test" { + identifier = %[5]q + allocated_storage = 10 + backup_retention_period = 1 + 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 + db_name = "test" + parameter_group_name = data.aws_db_parameter_group.test.name + skip_final_snapshot = true + password = "avoid-plaintext-passwords" + username = "tfacctest" + + blue_green_update { + enabled = true + } +} +`, tfrds.InstanceEngineMySQL, "general-public-license", "standard", halfMainInstClass, rName) +} + +func testAccInstanceConfig_BlueGreenDeployment_prePromote(rName string) string { + var e []string + for i := 0; i < len(instanceClassesSlice); i += 2 { + e = append(e, instanceClassesSlice[i]) + } + evenClasses := strings.Join(e, ", ") + + var o []string + for i := 1; i < len(instanceClassesSlice); i += 2 { + o = append(o, instanceClassesSlice[i]) + } + oddClasses := strings.Join(o, ", ") + + return fmt.Sprintf(` +data "aws_rds_engine_version" "default" { + engine = %[1]q +} + +data "aws_rds_orderable_db_instance" "test" { + 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 = [%[4]s] +} + +data "aws_rds_orderable_db_instance" "update" { + 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 = [%[5]s] } -func testAccInstanceConfig_BlueGreenDeployment_promote(rName string) string { - return acctest.ConfigCompose( - testAccInstanceConfig_orderableClassMySQL(), - fmt.Sprintf(` resource "aws_db_instance" "source" { - identifier = "%[1]s-source" allocated_storage = 5 backup_retention_period = 1 engine = data.aws_rds_orderable_db_instance.test.engine + identifier = "%[6]s-source" instance_class = data.aws_rds_orderable_db_instance.test.instance_class password = "avoid-plaintext-passwords" username = "tfacctest" @@ -11446,63 +11459,106 @@ resource "aws_db_instance" "source" { } resource "aws_db_instance" "test" { - identifier = %[1]q - instance_class = data.aws_rds_orderable_db_instance.updated.instance_class - skip_final_snapshot = true + backup_retention_period = 1 + identifier = %[6]q + instance_class = aws_db_instance.source.instance_class + replicate_source_db = aws_db_instance.source.identifier + skip_final_snapshot = true +} +`, tfrds.InstanceEngineMySQL, "general-public-license", "standard", oddClasses, evenClasses, rName) +} - blue_green_update { - enabled = true - } +func testAccInstanceConfig_BlueGreenDeployment_promote(rName string) string { + var e []string + for i := 0; i < len(instanceClassesSlice); i += 2 { + e = append(e, instanceClassesSlice[i]) + } + evenClasses := strings.Join(e, ", ") + + var o []string + for i := 1; i < len(instanceClassesSlice); i += 2 { + o = append(o, instanceClassesSlice[i]) + } + oddClasses := strings.Join(o, ", ") + + return fmt.Sprintf(` +data "aws_rds_engine_version" "default" { + engine = %[1]q } -data "aws_rds_orderable_db_instance" "updated" { +data "aws_rds_orderable_db_instance" "test" { engine = data.aws_rds_engine_version.default.engine engine_version = data.aws_rds_engine_version.default.version - license_model = "general-public-license" - storage_type = "standard" + license_model = %[2]q + storage_type = %[3]q - preferred_instance_classes = ["db.t4g.micro", "db.t4g.small"] + preferred_instance_classes = [%[4]s] } -`, rName)) + +data "aws_rds_orderable_db_instance" "update" { + 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 = [%[5]s] } -func testAccInstanceConfig_BlueGreenDeployment_deletionProtection(rName string, deletionProtection bool) string { - return acctest.ConfigCompose( - testAccInstanceConfig_orderableClassMySQL(), - fmt.Sprintf(` -resource "aws_db_instance" "test" { - identifier = %[1]q - allocated_storage = 10 +resource "aws_db_instance" "source" { + identifier = "%[6]s-source" + allocated_storage = 5 backup_retention_period = 1 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 - db_name = "test" - parameter_group_name = "default.${data.aws_rds_engine_version.default.parameter_group_family}" - skip_final_snapshot = true password = "avoid-plaintext-passwords" username = "tfacctest" + skip_final_snapshot = true +} + +resource "aws_db_instance" "test" { + identifier = %[6]q + instance_class = data.aws_rds_orderable_db_instance.update.instance_class + skip_final_snapshot = true blue_green_update { enabled = true } +} +`, tfrds.InstanceEngineMySQL, "general-public-license", "standard", oddClasses, evenClasses, rName) +} - deletion_protection = %[2]t +func testAccInstanceConfig_BlueGreenDeployment_deletionProtection(rName string, deletionProtection bool, oddClasses bool) string { + var halfClasses []string + start := 0 + if oddClasses { + start = 1 + } + for i := start; i < len(instanceClassesSlice); i += 2 { + halfClasses = append(halfClasses, instanceClassesSlice[i]) + } + halfMainInstClass := strings.Join(halfClasses, ", ") + + return fmt.Sprintf(` +data "aws_rds_engine_version" "default" { + engine = %[1]q } -`, rName, deletionProtection)) + +data "aws_rds_orderable_db_instance" "test" { + 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 = [%[4]s] } -func testAccInstanceConfig_BlueGreenDeployment_updateInstanceClassWithDeletionProtection(rName string, deletionProtection bool) string { - return acctest.ConfigCompose( - testAccInstanceConfig_orderableClassMySQL(), - fmt.Sprintf(` resource "aws_db_instance" "test" { - identifier = %[1]q + identifier = %[5]q allocated_storage = 10 backup_retention_period = 1 - engine = data.aws_rds_orderable_db_instance.updated.engine - engine_version = data.aws_rds_orderable_db_instance.updated.engine_version - instance_class = data.aws_rds_orderable_db_instance.updated.instance_class + 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 db_name = "test" parameter_group_name = "default.${data.aws_rds_engine_version.default.parameter_group_family}" skip_final_snapshot = true @@ -11513,18 +11569,9 @@ resource "aws_db_instance" "test" { enabled = true } - deletion_protection = %[2]t + deletion_protection = %[6]t } - -data "aws_rds_orderable_db_instance" "updated" { - engine = data.aws_rds_engine_version.default.engine - engine_version = data.aws_rds_engine_version.default.version - license_model = "general-public-license" - storage_type = "standard" - - preferred_instance_classes = ["db.t4g.micro", "db.t4g.small"] -} -`, rName, deletionProtection)) +`, tfrds.InstanceEngineMySQL, "general-public-license", "standard", halfMainInstClass, rName, deletionProtection) } func testAccInstanceConfig_BlueGreenDeployment_password(rName, password string) string { @@ -11551,7 +11598,7 @@ resource "aws_db_instance" "test" { `, rName, password)) } -func testAccInstanceConfig_engineVersion(rName string, updated bool) string { +func testAccInstanceConfig_engineVersion(rName string, update bool) string { return acctest.ConfigCompose( fmt.Sprintf(` resource "aws_db_instance" "test" { @@ -11574,26 +11621,26 @@ data "aws_rds_orderable_db_instance" "test" { license_model = "general-public-license" storage_type = "standard" - preferred_instance_classes = [%[3]s] + preferred_instance_classes = [%[2]s] } data "aws_rds_engine_version" "initial" { - engine = "mysql" - preferred_versions = ["8.0.31", "8.0.30", "8.0.28"] + engine = %[3]q + latest = true + preferred_upgrade_targets = [data.aws_rds_engine_version.update.version_actual] } -data "aws_rds_engine_version" "updated" { - engine = data.aws_rds_engine_version.initial.engine - preferred_versions = data.aws_rds_engine_version.initial.valid_upgrade_targets +data "aws_rds_engine_version" "update" { + engine = %[3]q } locals { - engine_version = %[2]t ? data.aws_rds_engine_version.updated : data.aws_rds_engine_version.initial + engine_version = %[4]t ? data.aws_rds_engine_version.update : data.aws_rds_engine_version.initial } -`, rName, updated, mySQLPreferredInstanceClasses)) +`, rName, mainInstanceClasses, tfrds.InstanceEngineMySQL, update)) } -func testAccInstanceConfig_gp3(rName string, orderableClassConfig func() string, allocatedStorage int) string { +func testAccInstanceConfig_Storage_gp3(rName string, orderableClassConfig func() string, allocatedStorage int) string { return acctest.ConfigCompose( orderableClassConfig(), fmt.Sprintf(` @@ -11602,7 +11649,7 @@ resource "aws_db_instance" "test" { engine = data.aws_rds_engine_version.default.engine engine_version = data.aws_rds_engine_version.default.version instance_class = data.aws_rds_orderable_db_instance.test.instance_class - db_name = data.aws_rds_engine_version.default.engine == "sqlserver-ex" ? null : "test" + db_name = data.aws_rds_engine_version.default.engine == "%[2]s" ? null : "test" # using %[2]q breaks linter password = "avoid-plaintext-passwords" username = "tfacctest" parameter_group_name = "default.${data.aws_rds_engine_version.default.parameter_group_family}" @@ -11611,12 +11658,12 @@ resource "aws_db_instance" "test" { apply_immediately = true storage_type = data.aws_rds_orderable_db_instance.test.storage_type - allocated_storage = %[2]d + allocated_storage = %[3]d } -`, rName, allocatedStorage)) +`, rName, tfrds.InstanceEngineSQLServerExpress, allocatedStorage)) } -func testAccInstanceConfig_storageThroughput(rName string, iops, throughput int) string { +func testAccInstanceConfig_Storage_throughput(rName string, iops, throughput int) string { return acctest.ConfigCompose( testAccInstanceConfig_orderableClassMySQLGP3(), fmt.Sprintf(` @@ -11642,10 +11689,10 @@ resource "aws_db_instance" "test" { `, rName, iops, throughput)) } -func testAccInstanceConfig_storageThroughputSSE(rName string, iops, throughput int) string { +func testAccInstanceConfig_Storage_throughputSSE(rName string, iops, throughput int) string { return fmt.Sprintf(` data "aws_rds_engine_version" "default" { - engine = "sqlserver-se" + engine = %[1]q } data "aws_rds_orderable_db_instance" "test" { @@ -11654,7 +11701,7 @@ data "aws_rds_orderable_db_instance" "test" { license_model = "license-included" storage_type = "gp3" - preferred_instance_classes = ["db.m5.medium", "db.m5.large"] + preferred_instance_classes = [%[2]s] } resource "aws_db_instance" "test" { @@ -11662,31 +11709,39 @@ resource "aws_db_instance" "test" { apply_immediately = true engine = data.aws_rds_engine_version.default.engine engine_version = data.aws_rds_engine_version.default.version - identifier = %[1]q + identifier = %[3]q instance_class = data.aws_rds_orderable_db_instance.test.instance_class - iops = %[2]d + iops = %[4]d license_model = data.aws_rds_orderable_db_instance.test.license_model parameter_group_name = "default.${data.aws_rds_engine_version.default.parameter_group_family}" password = "avoid-plaintext-passwords" skip_final_snapshot = true - storage_throughput = %[3]d + storage_throughput = %[5]d storage_type = data.aws_rds_orderable_db_instance.test.storage_type username = "tfacctest" } -`, rName, iops, throughput) +`, tfrds.InstanceEngineSQLServerStandard, mainInstanceClasses, rName, iops, throughput) } -func testAccInstanceConfig_storageTypePostgres(rName string, storageType string, allocatedStorage int) string { +func testAccInstanceConfig_Storage_typePostgres(rName string, storageType string, allocatedStorage int) string { return fmt.Sprintf(` data "aws_rds_engine_version" "default" { - engine = "postgres" + engine = %[1]q +} + +data "aws_rds_orderable_db_instance" "test" { + engine = data.aws_rds_engine_version.default.engine + engine_version = data.aws_rds_engine_version.default.version + storage_type = %[2]q + + preferred_instance_classes = [%[3]s] } resource "aws_db_instance" "test" { - identifier = %[1]q + identifier = %[4]q engine = data.aws_rds_engine_version.default.engine engine_version = data.aws_rds_engine_version.default.version - instance_class = "db.m6g.large" + instance_class = data.aws_rds_orderable_db_instance.test.instance_class db_name = "test" password = "avoid-plaintext-passwords" username = "tfacctest" @@ -11696,7 +11751,7 @@ resource "aws_db_instance" "test" { apply_immediately = true storage_type = %[2]q - allocated_storage = %[3]d + allocated_storage = %[5]d } -`, rName, storageType, allocatedStorage) +`, tfrds.InstanceEnginePostgres, storageType, mainInstanceClasses, rName, allocatedStorage) } diff --git a/internal/service/rds/option_group_test.go b/internal/service/rds/option_group_test.go index 11525107979..8ac9e82e8b4 100644 --- a/internal/service/rds/option_group_test.go +++ b/internal/service/rds/option_group_test.go @@ -818,7 +818,7 @@ resource "aws_db_option_group" "test" { engine_name = data.aws_rds_engine_version.default.engine major_engine_version = regex("^\\d+\\.\\d+", data.aws_rds_engine_version.default.version) } -`, mySQLPreferredInstanceClasses, rName) +`, mainInstanceClasses, rName) } func testAccOptionGroupConfig_optionSettings(rName string) string { diff --git a/internal/service/rds/orderable_instance_data_source.go b/internal/service/rds/orderable_instance_data_source.go index 5cc8d8b28ca..5523a67f3b0 100644 --- a/internal/service/rds/orderable_instance_data_source.go +++ b/internal/service/rds/orderable_instance_data_source.go @@ -5,13 +5,16 @@ package rds import ( "context" + "sort" + "github.com/YakDriver/go-version" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/rds" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" + "github.com/hashicorp/terraform-provider-aws/internal/flex" ) // @SDKDataSource("aws_rds_orderable_db_instance") @@ -48,6 +51,11 @@ func DataSourceOrderableInstance() *schema.Resource { Computed: true, }, + "engine_latest_version": { + Type: schema.TypeBool, + Optional: true, + }, + "license_model": { Type: schema.TypeString, Optional: true, @@ -108,6 +116,7 @@ func DataSourceOrderableInstance() *schema.Resource { "read_replica_capable": { Type: schema.TypeBool, + Optional: true, Computed: true, }, @@ -120,15 +129,23 @@ func DataSourceOrderableInstance() *schema.Resource { "supported_engine_modes": { Type: schema.TypeList, Computed: true, + Optional: true, Elem: &schema.Schema{Type: schema.TypeString}, }, "supported_network_types": { Type: schema.TypeList, Computed: true, + Optional: true, Elem: &schema.Schema{Type: schema.TypeString}, }, + "supports_clusters": { + Type: schema.TypeBool, + Optional: true, + Computed: true, + }, + "supports_enhanced_monitoring": { Type: schema.TypeBool, Optional: true, @@ -159,6 +176,12 @@ func DataSourceOrderableInstance() *schema.Resource { Computed: true, }, + "supports_multi_az": { + Type: schema.TypeBool, + Optional: true, + Computed: true, + }, + "supports_performance_insights": { Type: schema.TypeBool, Optional: true, @@ -190,7 +213,9 @@ func dataSourceOrderableInstanceRead(ctx context.Context, d *schema.ResourceData var diags diag.Diagnostics conn := meta.(*conns.AWSClient).RDSConn(ctx) - input := &rds.DescribeOrderableDBInstanceOptionsInput{} + input := &rds.DescribeOrderableDBInstanceOptionsInput{ + MaxRecords: aws.Int64(3412), + } if v, ok := d.GetOk("availability_zone_group"); ok { input.AvailabilityZoneGroup = aws.String(v.(string)) @@ -224,12 +249,24 @@ func dataSourceOrderableInstanceRead(ctx context.Context, d *schema.ResourceData continue } + if v, ok := d.GetOk("read_replica_capable"); ok { + if aws.BoolValue(instanceOption.ReadReplicaCapable) != v.(bool) { + continue + } + } + if v, ok := d.GetOk("storage_type"); ok { if aws.StringValue(instanceOption.StorageType) != v.(string) { continue } } + if v, ok := d.GetOk("supports_clusters"); ok { + if aws.BoolValue(instanceOption.SupportsClusters) != v.(bool) { + continue + } + } + if v, ok := d.GetOk("supports_enhanced_monitoring"); ok { if aws.BoolValue(instanceOption.SupportsEnhancedMonitoring) != v.(bool) { continue @@ -260,6 +297,12 @@ func dataSourceOrderableInstanceRead(ctx context.Context, d *schema.ResourceData } } + if v, ok := d.GetOk("supports_multi_az"); ok { + if aws.BoolValue(instanceOption.MultiAZCapable) != v.(bool) { + continue + } + } + if v, ok := d.GetOk("supports_performance_insights"); ok { if aws.BoolValue(instanceOption.SupportsPerformanceInsights) != v.(bool) { continue @@ -282,6 +325,7 @@ func dataSourceOrderableInstanceRead(ctx context.Context, d *schema.ResourceData } return !lastPage }) + if err != nil { return sdkdiag.AppendErrorf(diags, "reading RDS Orderable DB Instance Options: %s", err) } @@ -290,90 +334,133 @@ func dataSourceOrderableInstanceRead(ctx context.Context, d *schema.ResourceData return sdkdiag.AppendErrorf(diags, "no RDS Orderable DB Instance Options found matching criteria; try different search") } - // preferred classes/versions - var found *rds.OrderableDBInstanceOption - l := d.Get("preferred_instance_classes").([]interface{}) - v := d.Get("preferred_engine_versions").([]interface{}) - if len(l) > 0 && len(v) > 0 { - for _, elem := range l { - preferredInstanceClass, ok := elem.(string) - - if !ok { - continue + if v, ok := d.GetOk("supported_engine_modes"); ok && len(v.([]interface{})) > 0 { + var matches []*rds.OrderableDBInstanceOption + search := flex.ExpandStringValueList(v.([]interface{})) + + for _, ic := range instanceClassResults { + searchedModes: + for _, s := range search { + for _, mode := range ic.SupportedEngineModes { + if aws.StringValue(mode) == s { + matches = append(matches, ic) + break searchedModes + } + } } + } - for _, ver := range v { - preferredEngineVersion, ok := ver.(string) + if len(matches) == 0 { + return sdkdiag.AppendErrorf(diags, "no RDS Orderable DB Instance Options found matching supported_engine_modes: %#v", search) + } - if !ok { - continue - } + instanceClassResults = matches + } - for _, instanceClassResult := range instanceClassResults { - if preferredInstanceClass == aws.StringValue(instanceClassResult.DBInstanceClass) && - preferredEngineVersion == aws.StringValue(instanceClassResult.EngineVersion) { - found = instanceClassResult - break + if v, ok := d.GetOk("supported_network_types"); ok && len(v.([]interface{})) > 0 { + var matches []*rds.OrderableDBInstanceOption + search := flex.ExpandStringValueList(v.([]interface{})) + + for _, ic := range instanceClassResults { + searchedNetworks: + for _, s := range search { + for _, netType := range ic.SupportedNetworkTypes { + if aws.StringValue(netType) == s { + matches = append(matches, ic) + break searchedNetworks } } - - if found != nil { - break - } } + } - if found != nil { - break - } + if len(matches) == 0 { + return sdkdiag.AppendErrorf(diags, "no RDS Orderable DB Instance Options found matching supported_network_types: %#v", search) } - } else if len(l) > 0 { - for _, elem := range l { - preferredInstanceClass, ok := elem.(string) - if !ok { - continue - } + instanceClassResults = matches + } - for _, instanceClassResult := range instanceClassResults { - if preferredInstanceClass == aws.StringValue(instanceClassResult.DBInstanceClass) { - found = instanceClassResult - break + prefSearch := false + + if v, ok := d.GetOk("preferred_engine_versions"); ok && len(v.([]interface{})) > 0 { + var matches []*rds.OrderableDBInstanceOption + search := flex.ExpandStringValueList(v.([]interface{})) + + for _, s := range search { + for _, ic := range instanceClassResults { + if aws.StringValue(ic.EngineVersion) == s { + matches = append(matches, ic) } + // keeping all the instance classes to ensure we can match any preferred instance classes } + } - if found != nil { - break - } + if len(matches) == 0 { + return sdkdiag.AppendErrorf(diags, "no RDS Orderable DB Instance Options found matching preferred_engine_versions: %#v", search) } - } else if len(v) > 0 { - for _, ver := range v { - preferredEngineVersion, ok := ver.(string) - if !ok { - continue - } + prefSearch = true + instanceClassResults = matches + } + + latestVersion := d.Get("engine_latest_version").(bool) + + if v, ok := d.GetOk("preferred_instance_classes"); ok && len(v.([]interface{})) > 0 { + var matches []*rds.OrderableDBInstanceOption + search := flex.ExpandStringValueList(v.([]interface{})) + + for _, s := range search { + for _, ic := range instanceClassResults { + if aws.StringValue(ic.DBInstanceClass) == s { + matches = append(matches, ic) + } - for _, instanceClassResult := range instanceClassResults { - if preferredEngineVersion == aws.StringValue(instanceClassResult.EngineVersion) { - found = instanceClassResult + if !latestVersion && len(matches) > 0 { break } + + // otherwise, get all the instance classes that match the *first* preferred class (and any other criteria) } - if found != nil { + // if we have a match, we can stop searching + if len(matches) > 0 { break } } + + if len(matches) == 0 { + return sdkdiag.AppendErrorf(diags, "no RDS Orderable DB Instance Options found matching preferred_instance_classes: %#v", search) + } + + prefSearch = true + instanceClassResults = matches } - if found == nil && len(instanceClassResults) > 1 { - return sdkdiag.AppendErrorf(diags, "multiple RDS DB Instance Classes (%v) match the criteria; try a different search", instanceClassResults) + var found *rds.OrderableDBInstanceOption + + if latestVersion && prefSearch { + sortInstanceClassesByVersion(instanceClassResults) + found = instanceClassResults[len(instanceClassResults)-1] + } + + if found == nil && len(instanceClassResults) > 0 && prefSearch { + found = instanceClassResults[0] } if found == nil && len(instanceClassResults) == 1 { found = instanceClassResults[0] } + if found == nil && len(instanceClassResults) > 4 { + // there can be a LOT(!!) of results, so if there are more than this, only include the search criteria + return sdkdiag.AppendErrorf(diags, "multiple (%d) RDS DB Instance Classes match the criteria; try a different search: %+v\nPreferred instance classes: %+v\nPreferred engine versions: %+v", len(instanceClassResults), input, d.Get("preferred_instance_classes"), d.Get("preferred_engine_versions")) + } + + if found == nil && len(instanceClassResults) > 1 { + // there can be a lot of results, so if there are a few, include the results and search criteria + return sdkdiag.AppendErrorf(diags, "multiple (%d) RDS DB Instance Classes (%v) match the criteria; try a different search: %+v\nPreferred instance classes: %+v\nPreferred engine versions: %+v", len(instanceClassResults), instanceClassResults, input, d.Get("preferred_instance_classes"), d.Get("preferred_engine_versions")) + } + if found == nil { return sdkdiag.AppendErrorf(diags, "no RDS DB Instance Classes match the criteria; try a different search") } @@ -401,11 +488,13 @@ func dataSourceOrderableInstanceRead(ctx context.Context, d *schema.ResourceData d.Set("storage_type", found.StorageType) d.Set("supported_engine_modes", aws.StringValueSlice(found.SupportedEngineModes)) d.Set("supported_network_types", aws.StringValueSlice(found.SupportedNetworkTypes)) + d.Set("supports_clusters", found.SupportsClusters) d.Set("supports_enhanced_monitoring", found.SupportsEnhancedMonitoring) d.Set("supports_global_databases", found.SupportsGlobalDatabases) d.Set("supports_iam_database_authentication", found.SupportsIAMDatabaseAuthentication) d.Set("supports_iops", found.SupportsIops) d.Set("supports_kerberos_authentication", found.SupportsKerberosAuthentication) + d.Set("supports_multi_az", found.MultiAZCapable) d.Set("supports_performance_insights", found.SupportsPerformanceInsights) d.Set("supports_storage_autoscaling", found.SupportsStorageAutoscaling) d.Set("supports_storage_encryption", found.SupportsStorageEncryption) @@ -413,3 +502,13 @@ func dataSourceOrderableInstanceRead(ctx context.Context, d *schema.ResourceData return diags } + +func sortInstanceClassesByVersion(ic []*rds.OrderableDBInstanceOption) { + if len(ic) < 2 { + return + } + + sort.Slice(ic, func(i, j int) bool { + return version.LessThan(aws.StringValue(ic[i].EngineVersion), aws.StringValue(ic[j].EngineVersion)) + }) +} diff --git a/internal/service/rds/orderable_instance_data_source_test.go b/internal/service/rds/orderable_instance_data_source_test.go index fc4606ed1ae..3207a6196b1 100644 --- a/internal/service/rds/orderable_instance_data_source_test.go +++ b/internal/service/rds/orderable_instance_data_source_test.go @@ -6,13 +6,16 @@ package rds_test import ( "context" "fmt" + "strings" "testing" + "github.com/YakDriver/regexache" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/rds" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "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 TestAccRDSOrderableInstanceDataSource_basic(t *testing.T) { @@ -49,7 +52,6 @@ func TestAccRDSOrderableInstanceDataSource_preferredClass(t *testing.T) { } dataSourceName := "data.aws_rds_orderable_db_instance.test" - preferredClass := "db.t3.micro" resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acctest.PreCheck(ctx, t); testAccOrderableInstancePreCheck(ctx, t) }, @@ -58,9 +60,9 @@ func TestAccRDSOrderableInstanceDataSource_preferredClass(t *testing.T) { CheckDestroy: nil, Steps: []resource.TestStep{ { - Config: testAccOrderableInstanceDataSourceConfig_preferredClass(preferredClass), + Config: testAccOrderableInstanceDataSourceConfig_preferredClass(), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr(dataSourceName, "instance_class", preferredClass), + resource.TestCheckResourceAttrSet(dataSourceName, "instance_class"), ), }, }, @@ -140,6 +142,179 @@ func TestAccRDSOrderableInstanceDataSource_supportsEnhancedMonitoring(t *testing }) } +func TestAccRDSOrderableInstanceDataSource_latestVersion(t *testing.T) { + ctx := acctest.Context(t) + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + + dataSourceName := "data.aws_rds_orderable_db_instance.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t); testAccOrderableInstancePreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, rds.EndpointsID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: nil, + Steps: []resource.TestStep{ + { + Config: testAccOrderableInstanceDataSourceConfig_latestVersion(false), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(dataSourceName, "engine", tfrds.ClusterEngineAuroraMySQL), + resource.TestCheckResourceAttr(dataSourceName, "engine_latest_version", "false"), + resource.TestMatchResourceAttr(dataSourceName, "engine_version", regexache.MustCompile(`^5\.7\.mysql_aurora\..*`)), + ), + }, + { + Config: testAccOrderableInstanceDataSourceConfig_latestVersion(true), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(dataSourceName, "engine", tfrds.ClusterEngineAuroraMySQL), + resource.TestCheckResourceAttr(dataSourceName, "engine_latest_version", "true"), + resource.TestMatchResourceAttr(dataSourceName, "engine_version", regexache.MustCompile(`^5\.7\.mysql_aurora\..*`)), + ), + }, + }, + }) +} + +func TestAccRDSOrderableInstanceDataSource_supportsGlobalDatabases(t *testing.T) { + ctx := acctest.Context(t) + if testing.Short() { + t.Skip("skipping long-running test in short mode") + } + + dataSourceName := "data.aws_rds_orderable_db_instance.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t); testAccOrderableInstancePreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, rds.EndpointsID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: nil, + Steps: []resource.TestStep{ + { + Config: testAccOrderableInstanceDataSourceConfig_supportsGlobalDatabases(), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(dataSourceName, "supports_global_databases", "true"), + resource.TestCheckResourceAttr(dataSourceName, "engine", tfrds.ClusterEngineAuroraMySQL), + resource.TestCheckResourceAttr(dataSourceName, "engine_latest_version", "true"), + resource.TestMatchResourceAttr(dataSourceName, "engine_version", regexache.MustCompile(`^8\.0\.mysql_aurora\..*`)), + ), + }, + }, + }) +} + +func TestAccRDSOrderableInstanceDataSource_supportsClusters(t *testing.T) { + ctx := acctest.Context(t) + dataSourceName := "data.aws_rds_orderable_db_instance.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t); testAccOrderableInstancePreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, rds.EndpointsID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: nil, + Steps: []resource.TestStep{ + { + Config: testAccOrderableInstanceDataSourceConfig_supportsClusters(), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(dataSourceName, "supports_clusters", "true"), + resource.TestCheckResourceAttr(dataSourceName, "engine", tfrds.ClusterEngineMySQL), + resource.TestCheckResourceAttr(dataSourceName, "engine_latest_version", "true"), + resource.TestMatchResourceAttr(dataSourceName, "instance_class", regexache.MustCompile(`^db\..*large$`)), + ), + }, + }, + }) +} + +func TestAccRDSOrderableInstanceDataSource_readReplicaCapable(t *testing.T) { + ctx := acctest.Context(t) + dataSourceName := "data.aws_rds_orderable_db_instance.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t); testAccOrderableInstancePreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, rds.EndpointsID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: nil, + Steps: []resource.TestStep{ + { + Config: testAccOrderableInstanceDataSourceConfig_readReplicaCapable(), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(dataSourceName, "read_replica_capable", "true"), + resource.TestCheckResourceAttr(dataSourceName, "engine", tfrds.InstanceEngineOracleEnterprise), + resource.TestCheckResourceAttr(dataSourceName, "engine_latest_version", "true"), + resource.TestCheckResourceAttrSet(dataSourceName, "instance_class"), + ), + }, + }, + }) +} + +func TestAccRDSOrderableInstanceDataSource_supportsMultiAZ(t *testing.T) { + ctx := acctest.Context(t) + dataSourceName := "data.aws_rds_orderable_db_instance.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t); testAccOrderableInstancePreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, rds.EndpointsID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: nil, + Steps: []resource.TestStep{ + { + Config: testAccOrderableInstanceDataSourceConfig_supportsMultiAZ(), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(dataSourceName, "supports_multi_az", "true"), + resource.TestCheckResourceAttr(dataSourceName, "engine", tfrds.ClusterEngineMySQL), + resource.TestCheckResourceAttr(dataSourceName, "engine_latest_version", "true"), + ), + }, + }, + }) +} + +func TestAccRDSOrderableInstanceDataSource_supportedEngineModes(t *testing.T) { + ctx := acctest.Context(t) + dataSourceName := "data.aws_rds_orderable_db_instance.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t); testAccOrderableInstancePreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, rds.EndpointsID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: nil, + Steps: []resource.TestStep{ + { + Config: testAccOrderableInstanceDataSourceConfig_supportedEngineModes(), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(dataSourceName, "engine", tfrds.ClusterEngineAuroraPostgreSQL), + resource.TestCheckResourceAttr(dataSourceName, "engine_latest_version", "true"), + resource.TestCheckResourceAttr(dataSourceName, "supported_engine_modes.0", "provisioned"), + ), + }, + }, + }) +} + +func TestAccRDSOrderableInstanceDataSource_supportedNetworkTypes(t *testing.T) { + ctx := acctest.Context(t) + dataSourceName := "data.aws_rds_orderable_db_instance.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t); testAccOrderableInstancePreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, rds.EndpointsID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: nil, + Steps: []resource.TestStep{ + { + Config: testAccOrderableInstanceDataSourceConfig_supportedNetworkTypes(), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(dataSourceName, "engine", tfrds.ClusterEngineAuroraPostgreSQL), + resource.TestCheckResourceAttr(dataSourceName, "engine_latest_version", "true"), + resource.TestCheckTypeSetElemAttr(dataSourceName, "supported_network_types.*", "DUAL"), + ), + }, + }, + }) +} + func TestAccRDSOrderableInstanceDataSource_supportsIAMDatabaseAuthentication(t *testing.T) { ctx := acctest.Context(t) if testing.Short() { @@ -293,7 +468,6 @@ func testAccOrderableInstancePreCheck(ctx context.Context, t *testing.T) { input := &rds.DescribeOrderableDBInstanceOptionsInput{ Engine: aws.String("mysql"), - EngineVersion: aws.String("8.0.20"), DBInstanceClass: aws.String("db.m5.xlarge"), } @@ -327,10 +501,10 @@ data "aws_rds_orderable_db_instance" "test" { license_model = %[3]q storage_type = %[4]q } -`, engine, mySQLPreferredInstanceClasses, license, storage) +`, engine, mainInstanceClasses, license, storage) } -func testAccOrderableInstanceDataSourceConfig_preferredClass(preferredClass string) string { +func testAccOrderableInstanceDataSourceConfig_preferredClass() string { return fmt.Sprintf(` data "aws_rds_engine_version" "default" { engine = "mysql" @@ -341,13 +515,9 @@ data "aws_rds_orderable_db_instance" "test" { engine_version = data.aws_rds_engine_version.default.version license_model = "general-public-license" - preferred_instance_classes = [ - "db.xyz.xlarge", - %[1]q, - "db.t3.small", - ] + preferred_instance_classes = [%[1]s] } -`, preferredClass) +`, mainInstanceClasses) } func testAccOrderableInstanceDataSourceConfig_preferredVersion() string { @@ -397,7 +567,7 @@ data "aws_rds_orderable_db_instance" "test" { "not.a.version", ] } -`, mySQLPreferredInstanceClasses) +`, mainInstanceClasses) } func testAccOrderableInstanceDataSourceConfig_supportsEnhancedMonitoring() string { @@ -415,7 +585,88 @@ data "aws_rds_orderable_db_instance" "test" { preferred_engine_versions = ["8.0.25", "8.0.26", data.aws_rds_engine_version.default.version] preferred_instance_classes = [%[1]s] } -`, mySQLPreferredInstanceClasses) +`, mainInstanceClasses) +} + +func testAccOrderableInstanceDataSourceConfig_supportsGlobalDatabases() string { + return fmt.Sprintf(` +data "aws_rds_orderable_db_instance" "test" { + engine = %[1]q + engine_latest_version = true + preferred_instance_classes = [%[2]s] + supports_global_databases = true +} +`, tfrds.ClusterEngineAuroraMySQL, mainInstanceClasses) +} + +func testAccOrderableInstanceDataSourceConfig_supportsClusters() string { + return fmt.Sprintf(` +data "aws_rds_orderable_db_instance" "test" { + engine = %[1]q + engine_latest_version = true + preferred_instance_classes = [%[2]s] + storage_type = "io1" + supports_iops = true + supports_clusters = true +} +`, tfrds.ClusterEngineMySQL, mainInstanceClasses) +} + +func testAccOrderableInstanceDataSourceConfig_readReplicaCapable() string { + return fmt.Sprintf(` +data "aws_rds_orderable_db_instance" "test" { + engine = %[1]q + engine_latest_version = true + preferred_instance_classes = [%[2]s] + read_replica_capable = true + storage_type = "gp3" +} +`, tfrds.InstanceEngineOracleEnterprise, strings.Replace(mainInstanceClasses, "db.t3.small", "frodo", 1)) +} + +func testAccOrderableInstanceDataSourceConfig_supportsMultiAZ() string { + return fmt.Sprintf(` +data "aws_rds_orderable_db_instance" "test" { + engine = %[1]q + engine_latest_version = true + preferred_instance_classes = [%[2]s] + supports_multi_az = true +} +`, tfrds.ClusterEngineMySQL, mainInstanceClasses) +} + +func testAccOrderableInstanceDataSourceConfig_supportedEngineModes() string { + return fmt.Sprintf(` +data "aws_rds_orderable_db_instance" "test" { + engine = %[1]q + engine_latest_version = true + preferred_instance_classes = [%[2]s] + supports_clusters = true + supported_engine_modes = ["provisioned", "serverless"] +} +`, tfrds.ClusterEngineAuroraPostgreSQL, mainInstanceClasses) +} + +func testAccOrderableInstanceDataSourceConfig_supportedNetworkTypes() string { + return fmt.Sprintf(` +data "aws_rds_orderable_db_instance" "test" { + engine = %[1]q + engine_latest_version = true + preferred_instance_classes = [%[2]s] + supports_clusters = true + supported_network_types = ["DUAL"] +} +`, tfrds.ClusterEngineAuroraPostgreSQL, mainInstanceClasses) +} + +func testAccOrderableInstanceDataSourceConfig_latestVersion(latestVersion bool) string { + return fmt.Sprintf(` +data "aws_rds_orderable_db_instance" "test" { + engine = %[1]q + engine_latest_version = %[2]t + preferred_instance_classes = [%[3]s] +} +`, tfrds.ClusterEngineAuroraMySQL, latestVersion, mainInstanceClasses) } func testAccOrderableInstanceDataSourceConfig_supportsIAMDatabaseAuthentication() string { @@ -433,7 +684,7 @@ data "aws_rds_orderable_db_instance" "test" { preferred_engine_versions = ["8.0.25", "8.0.26", data.aws_rds_engine_version.default.version] preferred_instance_classes = [%[1]s] } -`, mySQLPreferredInstanceClasses) +`, mainInstanceClasses) } func testAccOrderableInstanceDataSourceConfig_supportsIops() string { @@ -450,7 +701,7 @@ data "aws_rds_orderable_db_instance" "test" { preferred_engine_versions = ["8.0.20", "8.0.19", data.aws_rds_engine_version.default.version] preferred_instance_classes = [%[1]s] } -`, mySQLPreferredInstanceClasses) +`, mainInstanceClasses) } func testAccOrderableInstanceDataSourceConfig_supportsKerberosAuthentication() string { @@ -468,7 +719,7 @@ data "aws_rds_orderable_db_instance" "test" { preferred_engine_versions = ["14.1", "13.5", data.aws_rds_engine_version.default.version] preferred_instance_classes = [%[1]s] } -`, postgresPreferredInstanceClasses) +`, mainInstanceClasses) } func testAccOrderableInstanceDataSourceConfig_supportsPerformanceInsights() string { @@ -485,7 +736,7 @@ data "aws_rds_orderable_db_instance" "test" { preferred_engine_versions = ["8.0.25", "8.0.26", data.aws_rds_engine_version.default.version] preferred_instance_classes = [%[1]s] } -`, mySQLPreferredInstanceClasses) +`, mainInstanceClasses) } func testAccOrderableInstanceDataSourceConfig_supportsStorageAutoScaling() string { @@ -502,7 +753,7 @@ data "aws_rds_orderable_db_instance" "test" { preferred_engine_versions = ["8.0.20", "8.0.19", data.aws_rds_engine_version.default.version] preferred_instance_classes = [%[1]s] } -`, mySQLPreferredInstanceClasses) +`, mainInstanceClasses) } func testAccOrderableInstanceDataSourceConfig_supportsStorageEncryption() string { @@ -520,5 +771,5 @@ data "aws_rds_orderable_db_instance" "test" { preferred_engine_versions = ["8.0.25", "8.0.26", data.aws_rds_engine_version.default.version] preferred_instance_classes = [%[1]s] } -`, mySQLPreferredInstanceClasses) +`, mainInstanceClasses) } diff --git a/internal/service/rds/parameter_group_data_source.go b/internal/service/rds/parameter_group_data_source.go new file mode 100644 index 00000000000..71d91d3cc85 --- /dev/null +++ b/internal/service/rds/parameter_group_data_source.go @@ -0,0 +1,71 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package rds + +import ( + "context" + + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/service/rds" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" +) + +// @SDKDataSource("aws_db_parameter_group") +func DataSourceParameterGroup() *schema.Resource { + return &schema.Resource{ + ReadWithoutTimeout: dataSourceParameterGroupRead, + Schema: map[string]*schema.Schema{ + "arn": { + Type: schema.TypeString, + Computed: true, + }, + + "description": { + Type: schema.TypeString, + Computed: true, + }, + + "family": { + Type: schema.TypeString, + Computed: true, + }, + + "name": { + Type: schema.TypeString, + Required: true, + }, + }, + } +} + +func dataSourceParameterGroupRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + var diags diag.Diagnostics + conn := meta.(*conns.AWSClient).RDSConn(ctx) + + groupName := d.Get("name").(string) + + input := rds.DescribeDBParameterGroupsInput{ + DBParameterGroupName: aws.String(groupName), + } + + output, err := conn.DescribeDBParameterGroupsWithContext(ctx, &input) + if err != nil { + return sdkdiag.AppendErrorf(diags, "reading RDS DB Parameter Groups (%s): %s", d.Get("name").(string), err) + } + + if len(output.DBParameterGroups) != 1 || aws.StringValue(output.DBParameterGroups[0].DBParameterGroupName) != groupName { + return sdkdiag.AppendErrorf(diags, "RDS DB Parameter Group not found (%#v): %s", output, err) + } + + d.SetId(aws.StringValue(output.DBParameterGroups[0].DBParameterGroupName)) + d.Set("name", output.DBParameterGroups[0].DBParameterGroupName) + d.Set("arn", output.DBParameterGroups[0].DBParameterGroupArn) + d.Set("family", output.DBParameterGroups[0].DBParameterGroupFamily) + d.Set("description", output.DBParameterGroups[0].Description) + + return nil +} diff --git a/internal/service/rds/parameter_group_data_source_test.go b/internal/service/rds/parameter_group_data_source_test.go new file mode 100644 index 00000000000..779d0c2ffa8 --- /dev/null +++ b/internal/service/rds/parameter_group_data_source_test.go @@ -0,0 +1,68 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package rds_test + +import ( + "fmt" + "testing" + + "github.com/YakDriver/regexache" + "github.com/aws/aws-sdk-go/service/rds" + sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-provider-aws/internal/acctest" +) + +func TestAccRDSParameterGroupDataSource_basic(t *testing.T) { + ctx := acctest.Context(t) + datasourceName := "data.aws_db_parameter_group.test" + resourceName := "aws_db_parameter_group.test" + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, rds.EndpointsID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccParameterGroupDataSourceConfig_nonExistent, + ExpectError: regexache.MustCompile(`not found`), + }, + { + Config: testAccParameterGroupDataSourceConfig_basic(rName), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrPair(datasourceName, "arn", resourceName, "arn"), + resource.TestCheckResourceAttrPair(datasourceName, "description", resourceName, "description"), + resource.TestCheckResourceAttrPair(datasourceName, "family", resourceName, "family"), + resource.TestCheckResourceAttrPair(datasourceName, "name", resourceName, "name"), + ), + }, + }, + }) +} + +const testAccParameterGroupDataSourceConfig_nonExistent = ` +data "aws_db_parameter_group" "test" { + name = "tf-acc-test-does-not-exist" +} +` + +func testAccParameterGroupDataSourceConfig_basic(rName string) string { + return fmt.Sprintf(` +resource "aws_db_parameter_group" "test" { + name = %[1]q + family = "postgres12" + + parameter { + name = "client_encoding" + value = "UTF8" + apply_method = "pending-reboot" + } +} + +data "aws_db_parameter_group" "test" { + name = aws_db_parameter_group.test.name +} +`, rName) +} diff --git a/internal/service/rds/service_package_gen.go b/internal/service/rds/service_package_gen.go index f6d0e9d990a..d6b84d426bb 100644 --- a/internal/service/rds/service_package_gen.go +++ b/internal/service/rds/service_package_gen.go @@ -51,6 +51,10 @@ func (p *servicePackage) SDKDataSources(ctx context.Context) []*types.ServicePac Factory: DataSourceInstances, TypeName: "aws_db_instances", }, + { + Factory: DataSourceParameterGroup, + TypeName: "aws_db_parameter_group", + }, { Factory: DataSourceProxy, TypeName: "aws_db_proxy", diff --git a/website/docs/d/db_parameter_group.markdown b/website/docs/d/db_parameter_group.markdown new file mode 100644 index 00000000000..862e9295128 --- /dev/null +++ b/website/docs/d/db_parameter_group.markdown @@ -0,0 +1,33 @@ +--- +subcategory: "RDS (Relational Database)" +layout: "aws" +page_title: "AWS: aws_db_parameter_group" +description: |- + Information about a database parameter group. +--- + +# Data Source: aws_db_parameter_group + +Information about a database parameter group. + +## Example Usage + +```terraform +data "aws_db_parameter_group" "test" { + name = "default.postgres15" +} +``` + +## Argument Reference + +The following arguments are required: + +* `name` - (Required) DB parameter group name. + +## Attribute Reference + +This data source exports the following attributes in addition to the arguments above: + +* `arn` - ARN of the parameter group. +* `family` - Family of the parameter group. +* `description` - Description of the parameter group. diff --git a/website/docs/d/rds_engine_version.html.markdown b/website/docs/d/rds_engine_version.html.markdown index 34573625de4..acf023311b1 100644 --- a/website/docs/d/rds_engine_version.html.markdown +++ b/website/docs/d/rds_engine_version.html.markdown @@ -38,15 +38,21 @@ data "aws_rds_engine_version" "test" { ## Argument Reference -This data source supports the following arguments: +The following arguments are required: + +* `engine` - (Required) Database engine. Engine values include `aurora`, `aurora-mysql`, `aurora-postgresql`, `docdb`, `mariadb`, `mysql`, `neptune`, `oracle-ee`, `oracle-se`, `oracle-se1`, `oracle-se2`, `postgres`, `sqlserver-ee`, `sqlserver-ex`, `sqlserver-se`, and `sqlserver-web`. + +The following arguments are optional: -* `engine` - (Required) DB engine. Engine values include `aurora`, `aurora-mysql`, `aurora-postgresql`, `docdb`, `mariadb`, `mysql`, `neptune`, `oracle-ee`, `oracle-se`, `oracle-se1`, `oracle-se2`, `postgres`, `sqlserver-ee`, `sqlserver-ex`, `sqlserver-se`, and `sqlserver-web`. * `default_only` - (Optional) When set to `true`, the default version for the specified `engine` or combination of `engine` and major `version` will be returned. Can be used to limit responses to a single version when they would otherwise fail for returning multiple versions. * `filter` - (Optional) One or more name/value pairs to filter off of. There are several valid keys; for a full reference, check out [describe-db-engine-versions in the AWS CLI reference](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/rds/describe-db-engine-versions.html). * `include_all` - (Optional) When set to `true`, the specified `version` or member of `preferred_versions` will be returned even if it is `deprecated`. Otherwise, only `available` versions will be returned. -* `parameter_group_family` - (Optional) Name of a specific DB parameter group family. Examples of parameter group families are `mysql8.0`, `mariadb10.4`, and `postgres12`. -* `preferred_versions` - (Optional) Ordered list of preferred engine versions. The first match in this list will be returned. If no preferred matches are found and the original search returned more than one result, an error is returned. If both the `version` and `preferred_versions` arguments are not configured, the data source will return the default version for the engine. -* `version` - (Optional) Version of the DB engine. For example, `5.7.22`, `10.1.34`, and `12.3`. If both the `version` and `preferred_versions` arguments are not configured, the data source will return the default version for the engine. +* `latest` - (Optional) When set to `true`, the data source attempts to return the most recent version matching the other criteria you provide. This differs from `default_only`. For example, the latest version is not always the default. In addition, AWS may return multiple defaults depending on the criteria. Using `latest` will avoid `multiple RDS engine versions` errors. **Note:** The data source uses a best-effort approach at selecting the latest version but due to the complexity of version identifiers across engines and incomplete version date information provided by AWS, using `latest` may _not_ return the latest version in every situation. +* `parameter_group_family` - (Optional) Name of a specific database parameter group family. Examples of parameter group families are `mysql8.0`, `mariadb10.4`, and `postgres12`. +* `preferred_major_targets` - (Optional) Ordered list of preferred major version upgrade targets. The version corresponding to the first match in this list will be returned unless the `latest` parameter is set to `true`. If you don't configure `version`, `preferred_major_targets`, `preferred_upgrade_targets`, and `preferred_versions`, the data source will return the default version for the engine. You can use this with other version criteria. +* `preferred_upgrade_targets` - (Optional) Ordered list of preferred version upgrade targets. The version corresponding to the first match in this list will be returned unless the `latest` parameter is set to `true`. If you don't configure `version`, `preferred_major_targets`, `preferred_upgrade_targets`, and `preferred_versions`, the data source will return the default version for the engine. You can use this with other version criteria. +* `preferred_versions` - (Optional) Ordered list of preferred versions. The first match in this list that matches any other criteria will be returned unless the `latest` parameter is set to `true`. If you don't configure `version`, `preferred_major_targets`, `preferred_upgrade_targets`, and `preferred_versions`, the data source will return the default version for the engine. You can use this with other version criteria. +* `version` - (Optional) Version of the database engine. For example, `5.7.22`, `10.1.34`, or `12.3`. `version` can be a major version which may result in the data source finding multiple versions and returning an error unless the `latest` parameter is set to `true`. If you don't configure `version`, `preferred_major_targets`, `preferred_upgrade_targets`, and `preferred_versions`, the data source will return the default version for the engine. You can use this with other version criteria. **NOTE:** In a future Terraform AWS provider version, `version` will only contain the version information you configure and not the complete version information that the data source gets from AWS. Instead, that version information will be available in the `version_actual` attribute. ## Attribute Reference @@ -55,14 +61,15 @@ This data source exports the following attributes in addition to the arguments a * `default_character_set` - The default character set for new instances of this engine version. * `engine_description` - Description of the database engine. * `exportable_log_types` - Set of log types that the database engine has available for export to CloudWatch Logs. -* `status` - Status of the DB engine version, either available or deprecated. +* `status` - Status of the database engine version, either available or deprecated. * `supported_character_sets` - Set of the character sets supported by this engine. -* `supported_feature_names` - Set of features supported by the DB engine. -* `supported_modes` - Set of the supported DB engine modes. +* `supported_feature_names` - Set of features supported by the database engine. +* `supported_modes` - Set of the supported database engine modes. * `supported_timezones` - Set of the time zones supported by this engine. -* `supports_global_databases` - Indicates whether you can use Aurora global databases with a specific DB engine version. +* `supports_global_databases` - Indicates whether you can use Aurora global databases with a specific database engine version. * `supports_log_exports_to_cloudwatch` - Indicates whether the engine version supports exporting the log types specified by `exportable_log_types` to CloudWatch Logs. -* `supports_parallel_query` - Indicates whether you can use Aurora parallel query with a specific DB engine version. +* `supports_parallel_query` - Indicates whether you can use Aurora parallel query with a specific database engine version. * `supports_read_replica` - Indicates whether the database engine version supports read replicas. * `valid_upgrade_targets` - Set of engine versions that this database engine version can be upgraded to. +* `version_actual` - Version of the database engine. * `version_description` - Description of the database engine version. diff --git a/website/docs/d/rds_orderable_db_instance.html.markdown b/website/docs/d/rds_orderable_db_instance.html.markdown index 2aac944e96d..703a8fd7e14 100644 --- a/website/docs/d/rds_orderable_db_instance.html.markdown +++ b/website/docs/d/rds_orderable_db_instance.html.markdown @@ -40,13 +40,19 @@ data "aws_rds_orderable_db_instance" "test" { This data source supports the following arguments: * `availability_zone_group` - (Optional) Availability zone group. +* `engine_latest_version` - (Optional) When set to `true`, the data source attempts to return the most recent version matching the other criteria you provide. You must use `engine_latest_version` with `preferred_instance_classes` and/or `preferred_engine_versions`. Using `engine_latest_version` will avoid `multiple RDS DB Instance Classes` errors. If you use `engine_latest_version` with `preferred_instance_classes`, the data source returns the latest version for the _first_ matching instance class (instance class priority). **Note:** The data source uses a best-effort approach at selecting the latest version but due to the complexity of version identifiers across engines, using `engine_latest_version` may _not_ return the latest version in every situation. +* `engine_version` - (Optional) Version of the DB engine. If none is provided, the data source tries to use the AWS-defined default version that matches any other criteria. * `engine` - (Required) DB engine. Engine values include `aurora`, `aurora-mysql`, `aurora-postgresql`, `docdb`, `mariadb`, `mysql`, `neptune`, `oracle-ee`, `oracle-se`, `oracle-se1`, `oracle-se2`, `postgres`, `sqlserver-ee`, `sqlserver-ex`, `sqlserver-se`, and `sqlserver-web`. -* `engine_version` - (Optional) Version of the DB engine. If none is provided, the AWS-defined default version will be used. * `instance_class` - (Optional) DB instance class. Examples of classes are `db.m3.2xlarge`, `db.t2.small`, and `db.m3.medium`. * `license_model` - (Optional) License model. Examples of license models are `general-public-license`, `bring-your-own-license`, and `amazon-license`. -* `preferred_instance_classes` - (Optional) Ordered list of preferred RDS DB instance classes. The first match in this list will be returned. If no preferred matches are found and the original search returned more than one result, an error is returned. -* `preferred_engine_versions` - (Optional) Ordered list of preferred RDS DB instance engine versions. The first match in this list will be returned. If no preferred matches are found and the original search returned more than one result, an error is returned. +* `preferred_engine_versions` - (Optional) Ordered list of preferred RDS DB instance engine versions. When `engine_latest_version` is not set, the data source will return the first match in this list that matches any other criteria. If the data source finds no preferred matches or multiple matches without `engine_latest_version`, it returns an error. **CAUTION:** We don't recommend using `preferred_engine_versions` without `preferred_instance_classes` since the data source returns an arbitrary `instance_class` based on the first one AWS returns that matches the engine version and any other criteria. +* `preferred_instance_classes` - (Optional) Ordered list of preferred RDS DB instance classes. The data source will return the first match in this list that matches any other criteria. If the data source finds no preferred matches or multiple matches without `engine_latest_version`, it returns an error. If you use `preferred_instance_classes` without `preferred_engine_versions` or `engine_latest_version`, the data source returns an arbitrary `engine_version` based on the first one AWS returns matching the instance class and any other criteria. +* `read_replica_capable` - (Optional) Whether a DB instance can have a read replica. * `storage_type` - (Optional) Storage types. Examples of storage types are `standard`, `io1`, `gp2`, and `aurora`. +* `supported_engine_modes` - (Optional) Use to limit results to engine modes such as `provisioned`. +* `supported_network_types` - (Optional) Use to limit results to network types `IPV4` or `DUAL`. +* `supports_clusters` - (Optional) Whether to limit results to instances that support clusters. +* `supports_multi_az` - (Optional) Whether to limit results to instances that are multi-AZ capable. * `supports_enhanced_monitoring` - (Optional) Enable this to ensure a DB instance supports Enhanced Monitoring at intervals from 1 to 60 seconds. * `supports_global_databases` - (Optional) Enable this to ensure a DB instance supports Aurora global databases with a specific combination of other DB engine attributes. * `supports_iam_database_authentication` - (Optional) Enable this to ensure a DB instance supports IAM database authentication. @@ -70,6 +76,3 @@ This data source exports the following attributes in addition to the arguments a * `min_storage_size` - Minimum storage size for a DB instance. * `multi_az_capable` - Whether a DB instance is Multi-AZ capable. * `outpost_capable` - Whether a DB instance supports RDS on Outposts. -* `read_replica_capable` - Whether a DB instance can have a read replica. -* `supported_engine_modes` - A list of the supported DB engine modes. -* `supported_network_types` - The network types supported by the DB instance (`IPV4` or `DUAL`). diff --git a/website/docs/r/neptune_cluster_instance.html.markdown b/website/docs/r/neptune_cluster_instance.html.markdown index 48c61727d98..97781a4e08b 100644 --- a/website/docs/r/neptune_cluster_instance.html.markdown +++ b/website/docs/r/neptune_cluster_instance.html.markdown @@ -59,6 +59,7 @@ This resource supports the following arguments: Syntax: "ddd:hh24:mi-ddd:hh24:mi". Eg: "Mon:00:00-Mon:03:00". * `promotion_tier` - (Optional) Default 0. Failover Priority setting on instance level. The reader who has lower tier has higher priority to get promoter to writer. * `publicly_accessible` - (Optional) Bool to control if instance is publicly accessible. Default is `false`. +* `skip_final_snapshot` - (Optional) Determines whether a final DB snapshot is created before the DB instance is deleted. * `tags` - (Optional) A map of tags to assign to the instance. If configured with a provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block) present, tags with matching keys will overwrite those defined at the provider-level. ## Attribute Reference