Skip to content

Commit

Permalink
Merge pull request #34580 from hashicorp/b-acctest-rds
Browse files Browse the repository at this point in the history
RDS fixes
  • Loading branch information
gdavison authored Nov 28, 2023
2 parents 816aa99 + cac029f commit 12310e4
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 16 deletions.
4 changes: 2 additions & 2 deletions internal/service/rds/cluster_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -219,7 +219,7 @@ func ResourceClusterInstance() *schema.Resource {
"publicly_accessible": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Computed: true,
},
"storage_encrypted": {
Type: schema.TypeBool,
Expand Down
58 changes: 56 additions & 2 deletions internal/service/rds/cluster_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
),
},
},
})
}
Expand Down Expand Up @@ -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))
}
Expand Down
7 changes: 7 additions & 0 deletions internal/service/rds/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,13 @@ func ClusterEngine_Values() []string {
}
}

func ClusterInstanceEngine_Values() []string {
return []string{
ClusterEngineAuroraMySQL,
ClusterEngineAuroraPostgreSQL,
}
}

const (
GlobalClusterEngineAurora = "aurora"
GlobalClusterEngineAuroraMySQL = "aurora-mysql"
Expand Down
22 changes: 11 additions & 11 deletions internal/service/rds/instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
),
Expand Down Expand Up @@ -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"),
),
},
Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion website/docs/r/rds_cluster_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 12310e4

Please sign in to comment.