diff --git a/internal/service/rds/cluster_instance.go b/internal/service/rds/cluster_instance.go index 91301d74838..0ae632982e9 100644 --- a/internal/service/rds/cluster_instance.go +++ b/internal/service/rds/cluster_instance.go @@ -114,7 +114,7 @@ func ResourceClusterInstance() *schema.Resource { ForceNew: true, ValidateFunc: validation.Any( validation.StringMatch(regexache.MustCompile(fmt.Sprintf(`^%s.*$`, InstanceEngineCustomPrefix)), fmt.Sprintf("must begin with %s", InstanceEngineCustomPrefix)), - validation.StringInSlice(ClusterEngine_Values(), false), + validation.StringInSlice(ClusterInstanceEngine_Values(), false), ), }, "engine_version": { @@ -219,7 +219,7 @@ func ResourceClusterInstance() *schema.Resource { "publicly_accessible": { Type: schema.TypeBool, Optional: true, - Default: false, + Computed: true, }, "storage_encrypted": { Type: schema.TypeBool, diff --git a/internal/service/rds/cluster_instance_test.go b/internal/service/rds/cluster_instance_test.go index ae082dff41f..5bfeacdc31a 100644 --- a/internal/service/rds/cluster_instance_test.go +++ b/internal/service/rds/cluster_instance_test.go @@ -381,6 +381,21 @@ func TestAccRDSClusterInstance_publiclyAccessible(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "publicly_accessible", "false"), ), }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{ + "apply_immediately", + }, + }, + { + Config: testAccClusterInstanceConfig_publiclyAccessible(rName, true), + Check: resource.ComposeTestCheckFunc( + testAccCheckClusterInstanceExists(ctx, resourceName, &v), + resource.TestCheckResourceAttr(resourceName, "publicly_accessible", "true"), + ), + }, }, }) } @@ -1343,14 +1358,53 @@ resource "aws_db_parameter_group" "test" { } func testAccClusterInstanceConfig_publiclyAccessible(rName string, publiclyAccessible bool) string { - return acctest.ConfigCompose(testAccClusterInstanceConfig_base(rName, "aurora-mysql"), fmt.Sprintf(` + return acctest.ConfigCompose( + acctest.ConfigAvailableAZsNoOptInDefaultExclude(), + fmt.Sprintf(` +resource "aws_vpc" "test" { + cidr_block = "10.0.0.0/16" + enable_dns_hostnames = true +} + +resource "aws_subnet" "test" { + count = %[2]d + + vpc_id = aws_vpc.test.id + availability_zone = data.aws_availability_zones.available.names[count.index] + cidr_block = cidrsubnet(aws_vpc.test.cidr_block, 8, count.index) +} +`, rName, 2), + testAccClusterInstanceConfig_orderableEngineBase("aurora-mysql", false), + fmt.Sprintf(` resource "aws_rds_cluster_instance" "test" { apply_immediately = true - engine = data.aws_rds_engine_version.default.engine cluster_identifier = aws_rds_cluster.test.id identifier = %[1]q + engine = aws_rds_cluster.test.engine instance_class = data.aws_rds_orderable_db_instance.test.instance_class publicly_accessible = %[2]t + + depends_on = [aws_internet_gateway.test] +} + +resource "aws_internet_gateway" "test" { + vpc_id = aws_vpc.test.id +} + +resource "aws_rds_cluster" "test" { + cluster_identifier = %[1]q + engine = data.aws_rds_engine_version.default.engine + engine_version = data.aws_rds_engine_version.default.version + database_name = "mydb" + master_username = "foo" + master_password = "mustbeeightcharacters" + skip_final_snapshot = true + db_subnet_group_name = aws_db_subnet_group.test.name +} + +resource "aws_db_subnet_group" "test" { + name = %[1]q + subnet_ids = aws_subnet.test[*].id } `, rName, publiclyAccessible)) } diff --git a/internal/service/rds/consts.go b/internal/service/rds/consts.go index 9538da14323..0a209c48a3d 100644 --- a/internal/service/rds/consts.go +++ b/internal/service/rds/consts.go @@ -140,6 +140,13 @@ func ClusterEngine_Values() []string { } } +func ClusterInstanceEngine_Values() []string { + return []string{ + ClusterEngineAuroraMySQL, + ClusterEngineAuroraPostgreSQL, + } +} + const ( GlobalClusterEngineAurora = "aurora" GlobalClusterEngineAuroraMySQL = "aurora-mysql" diff --git a/internal/service/rds/instance_test.go b/internal/service/rds/instance_test.go index 226b70bd5d9..ede4b252c9d 100644 --- a/internal/service/rds/instance_test.go +++ b/internal/service/rds/instance_test.go @@ -2209,7 +2209,7 @@ func TestAccRDSInstance_ReplicateSourceDB_parameterGroupTwoStep(t *testing.T) { resource.TestCheckResourceAttr(sourceResourceName, "parameter_group_name", "default.oracle-ee-19"), testAccCheckInstanceExists(ctx, resourceName, &dbInstance), resource.TestCheckResourceAttr(resourceName, "replica_mode", "open-read-only"), - resource.TestCheckResourceAttrPair(resourceName, "parameter_group_name", parameterGroupResourceName, "id"), + resource.TestCheckResourceAttrPair(resourceName, "parameter_group_name", parameterGroupResourceName, "name"), testAccCheckInstanceParameterApplyStatusInSync(&dbInstance), testAccCheckInstanceParameterApplyStatusInSync(&sourceDbInstance), ), @@ -4856,7 +4856,7 @@ func TestAccRDSInstance_BlueGreenDeployment_updateParameterGroup(t *testing.T) { Check: resource.ComposeAggregateTestCheckFunc( testAccCheckInstanceExists(ctx, resourceName, &v2), testAccCheckDBInstanceRecreated(&v1, &v2), - resource.TestCheckResourceAttrPair(resourceName, "parameter_group_name", parameterGroupResourceName, "id"), + resource.TestCheckResourceAttrPair(resourceName, "parameter_group_name", parameterGroupResourceName, "name"), resource.TestCheckResourceAttr(resourceName, "blue_green_update.0.enabled", "true"), ), }, @@ -8700,7 +8700,7 @@ resource "aws_db_instance" "source" { engine_version = data.aws_rds_orderable_db_instance.test.engine_version identifier = "%[1]s-source" instance_class = data.aws_rds_orderable_db_instance.test.instance_class - parameter_group_name = aws_db_parameter_group.test.id + parameter_group_name = aws_db_parameter_group.test.name password = "avoid-plaintext-passwords" username = "tfacctest" skip_final_snapshot = true @@ -8709,7 +8709,7 @@ resource "aws_db_instance" "source" { resource "aws_db_instance" "test" { identifier = %[1]q instance_class = aws_db_instance.source.instance_class - parameter_group_name = aws_db_parameter_group.test.id + parameter_group_name = aws_db_parameter_group.test.name replicate_source_db = aws_db_instance.source.identifier skip_final_snapshot = true } @@ -8723,7 +8723,7 @@ func testAccInstanceConfig_ReplicateSourceDB_ParameterGroupName_differentSetOnBo resource "aws_db_instance" "test" { identifier = %[1]q instance_class = aws_db_instance.source.instance_class - parameter_group_name = aws_db_parameter_group.test.id + parameter_group_name = aws_db_parameter_group.test.name replicate_source_db = aws_db_instance.source.identifier skip_final_snapshot = true } @@ -8745,7 +8745,7 @@ resource "aws_db_instance" "source" { engine_version = data.aws_rds_orderable_db_instance.test.engine_version identifier = "%[1]s-source" instance_class = data.aws_rds_orderable_db_instance.test.instance_class - parameter_group_name = aws_db_parameter_group.source.id + parameter_group_name = aws_db_parameter_group.source.name password = "avoid-plaintext-passwords" username = "tfacctest" skip_final_snapshot = true @@ -8784,7 +8784,7 @@ resource "aws_db_instance" "source" { engine_version = data.aws_rds_orderable_db_instance.test.engine_version identifier = "%[1]s-source" instance_class = data.aws_rds_orderable_db_instance.test.instance_class - parameter_group_name = aws_db_parameter_group.test.id + parameter_group_name = aws_db_parameter_group.test.name password = "avoid-plaintext-passwords" username = "tfacctest" skip_final_snapshot = true @@ -8828,7 +8828,7 @@ resource "aws_db_instance" "source" { resource "aws_db_instance" "test" { identifier = %[1]q instance_class = aws_db_instance.source.instance_class - parameter_group_name = aws_db_parameter_group.test.id + parameter_group_name = aws_db_parameter_group.test.name replicate_source_db = aws_db_instance.source.identifier skip_final_snapshot = true } @@ -9009,7 +9009,7 @@ resource "aws_db_instance" "test" { skip_final_snapshot = true apply_immediately = true - parameter_group_name = aws_db_parameter_group.test.id + parameter_group_name = aws_db_parameter_group.test.name ca_cert_identifier = "rds-ca-2019" timeouts { @@ -9907,7 +9907,7 @@ resource "aws_db_snapshot" "test" { resource "aws_db_instance" "test" { identifier = %[1]q instance_class = aws_db_instance.source.instance_class - parameter_group_name = aws_db_parameter_group.test.id + parameter_group_name = aws_db_parameter_group.test.name snapshot_identifier = aws_db_snapshot.test.id skip_final_snapshot = true } @@ -10663,7 +10663,7 @@ resource "aws_db_instance" "test" { engine_version = data.aws_rds_orderable_db_instance.test.engine_version instance_class = data.aws_rds_orderable_db_instance.test.instance_class db_name = "test" - parameter_group_name = aws_db_parameter_group.test.id + parameter_group_name = aws_db_parameter_group.test.name skip_final_snapshot = true password = "avoid-plaintext-passwords" username = "tfacctest" diff --git a/website/docs/r/rds_cluster_instance.html.markdown b/website/docs/r/rds_cluster_instance.html.markdown index 77c0cd92feb..92c9177c5df 100644 --- a/website/docs/r/rds_cluster_instance.html.markdown +++ b/website/docs/r/rds_cluster_instance.html.markdown @@ -63,7 +63,8 @@ This argument supports the following arguments: * `db_parameter_group_name` - (Optional) Name of the DB parameter group to associate with this instance. * `db_subnet_group_name` - (Required if `publicly_accessible = false`, Optional otherwise, Forces new resource) DB subnet group to associate with this DB instance. **NOTE:** This must match the `db_subnet_group_name` of the attached [`aws_rds_cluster`](/docs/providers/aws/r/rds_cluster.html). * `engine_version` - (Optional) Database engine version. -* `engine` - (Required, Forces new resource) Name of the database engine to be used for the RDS instance. Valid Values: `aurora-mysql`, `aurora-postgresql`, `mysql`, `postgres`. +* `engine` - (Required, Forces new resource) Name of the database engine to be used for the RDS cluster instance. + Valid Values: `aurora-mysql`, `aurora-postgresql`. * `identifier_prefix` - (Optional, Forces new resource) Creates a unique identifier beginning with the specified prefix. Conflicts with `identifier`. * `identifier` - (Optional, Forces new resource) Identifier for the RDS instance, if omitted, Terraform will assign a random, unique identifier. * `instance_class` - (Required) Instance class to use. For details on CPU and memory, see [Scaling Aurora DB Instances][4]. Aurora uses `db.*` instance classes/types. Please see [AWS Documentation][7] for currently available instance classes and complete details.