Skip to content

Commit

Permalink
Merge pull request hashicorp#40278 from hashicorp/f-certs-rds-oh-my
Browse files Browse the repository at this point in the history
rds/instance: Test correct updating of cert
  • Loading branch information
YakDriver authored Nov 22, 2024
2 parents 042a38f + 1e8dbbc commit 967d545
Showing 1 changed file with 60 additions and 5 deletions.
65 changes: 60 additions & 5 deletions internal/service/rds/instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4712,7 +4712,7 @@ func TestAccRDSInstance_SnapshotIdentifier_performanceInsightsEnabled(t *testing
})
}

func TestAccRDSInstance_caCertificateIdentifier(t *testing.T) {
func TestAccRDSInstance_CACertificate_latest(t *testing.T) {
ctx := acctest.Context(t)
if testing.Short() {
t.Skip("skipping long-running test in short mode")
Expand All @@ -4730,7 +4730,7 @@ func TestAccRDSInstance_caCertificateIdentifier(t *testing.T) {
CheckDestroy: testAccCheckDBInstanceDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccInstanceConfig_caCertificateID(rName),
Config: testAccInstanceConfig_CACertificate_latest(rName),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckDBInstanceExists(ctx, resourceName, &v),
resource.TestCheckResourceAttrPair(resourceName, "ca_cert_identifier", dataSourceName, names.AttrID),
Expand All @@ -4740,6 +4740,40 @@ func TestAccRDSInstance_caCertificateIdentifier(t *testing.T) {
})
}

func TestAccRDSInstance_CACertificate_update(t *testing.T) {
ctx := acctest.Context(t)
if testing.Short() {
t.Skip("skipping long-running test in short mode")
}

var v types.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, names.RDSServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckDBInstanceDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccInstanceConfig_CACertificate_update(rName, "rds-ca-ecc384-g1"),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckDBInstanceExists(ctx, resourceName, &v),
resource.TestCheckResourceAttr(resourceName, "ca_cert_identifier", "rds-ca-ecc384-g1"),
),
},
{
Config: testAccInstanceConfig_CACertificate_update(rName, "rds-ca-rsa2048-g1"),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckDBInstanceExists(ctx, resourceName, &v),
resource.TestCheckResourceAttr(resourceName, "ca_cert_identifier", "rds-ca-rsa2048-g1"),
),
},
},
})
}

func TestAccRDSInstance_RestoreToPointInTime_sourceIdentifier(t *testing.T) {
ctx := acctest.Context(t)
if testing.Short() {
Expand Down Expand Up @@ -7135,7 +7169,7 @@ resource "aws_db_instance" "test" {
`, rName))
}

func testAccInstanceConfig_caCertificateID(rName string) string {
func testAccInstanceConfig_CACertificate_latest(rName string) string {
return acctest.ConfigCompose(testAccInstanceConfig_orderableClassMySQL(), fmt.Sprintf(`
data "aws_rds_certificate" "latest" {
latest_valid_till = true
Expand All @@ -7156,6 +7190,23 @@ resource "aws_db_instance" "test" {
`, rName))
}

func testAccInstanceConfig_CACertificate_update(rName, cert string) string {
return acctest.ConfigCompose(testAccInstanceConfig_orderableClassMySQL(), fmt.Sprintf(`
resource "aws_db_instance" "test" {
identifier = %[1]q
allocated_storage = 10
apply_immediately = true
ca_cert_identifier = %[2]q
engine = data.aws_rds_orderable_db_instance.test.engine
instance_class = data.aws_rds_orderable_db_instance.test.instance_class
db_name = "test"
skip_final_snapshot = true
password = "avoid-plaintext-passwords"
username = "tfacctest"
}
`, rName, cert))
}

func testAccInstanceConfig_iamAuth(rName string) string {
return fmt.Sprintf(`
data "aws_rds_engine_version" "default" {
Expand Down Expand Up @@ -10187,6 +10238,10 @@ data "aws_rds_orderable_db_instance" "test" {
preferred_instance_classes = [%[2]s]
}
data "aws_rds_certificate" "latest" {
latest_valid_till = true
}
resource "aws_db_instance" "source" {
identifier = "%[3]s-source"
allocated_storage = 20
Expand All @@ -10206,7 +10261,7 @@ resource "aws_db_instance" "source" {
timeouts {
update = "120m"
}
ca_cert_identifier = "rds-ca-2019"
ca_cert_identifier = data.aws_rds_certificate.latest.id
}
`, tfrds.InstanceEngineOracleEnterprise, strings.Replace(mainInstanceClasses, "db.t3.small", "frodo", 1), rName)
}
Expand All @@ -10224,7 +10279,7 @@ resource "aws_db_instance" "test" {
apply_immediately = true
parameter_group_name = aws_db_parameter_group.test.name
ca_cert_identifier = "rds-ca-2019"
ca_cert_identifier = data.aws_rds_certificate.latest.id
timeouts {
update = "120m"
Expand Down

0 comments on commit 967d545

Please sign in to comment.