Skip to content

Commit

Permalink
Add 'TestAccDocDBCluster_updateEngineMajorVersion'.
Browse files Browse the repository at this point in the history
  • Loading branch information
ewbankkit committed Oct 10, 2023
1 parent d78f87b commit 4e8ee14
Showing 1 changed file with 100 additions and 0 deletions.
100 changes: 100 additions & 0 deletions internal/service/docdb/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,81 @@ func TestAccDocDBCluster_deleteProtection(t *testing.T) {
})
}

func TestAccDocDBCluster_updateEngineMajorVersion(t *testing.T) {
ctx := acctest.Context(t)
var dbCluster docdb.DBCluster
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_docdb_cluster.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, docdb.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckClusterDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccClusterConfig_engineVersion(rName, "4.0.0"),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckClusterExists(ctx, resourceName, &dbCluster),
resource.TestCheckResourceAttr(resourceName, "allow_major_version_upgrade", "true"),
resource.TestCheckResourceAttr(resourceName, "apply_immediately", "true"),
acctest.MatchResourceAttrRegionalARN(resourceName, "arn", "rds", regexache.MustCompile(fmt.Sprintf("cluster:%s", rName))),
resource.TestCheckResourceAttr(resourceName, "availability_zones.#", "3"),
resource.TestCheckResourceAttr(resourceName, "backup_retention_period", "1"),
resource.TestCheckResourceAttr(resourceName, "cluster_identifier", rName),
resource.TestCheckNoResourceAttr(resourceName, "cluster_identifier_prefix"),
resource.TestCheckResourceAttr(resourceName, "cluster_members.#", "0"),
resource.TestCheckResourceAttrSet(resourceName, "cluster_resource_id"),
resource.TestCheckResourceAttr(resourceName, "db_cluster_parameter_group_name", "default.docdb4.0"),
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", "docdb"),
resource.TestCheckResourceAttr(resourceName, "engine_version", "4.0.0"),
resource.TestCheckNoResourceAttr(resourceName, "final_snapshot_identifier"),
resource.TestCheckResourceAttr(resourceName, "global_cluster_identifier", ""),
resource.TestCheckResourceAttrSet(resourceName, "hosted_zone_id"),
resource.TestCheckResourceAttr(resourceName, "kms_key_id", ""),
resource.TestCheckResourceAttr(resourceName, "master_password", "avoid-plaintext-passwords"),
resource.TestCheckResourceAttr(resourceName, "master_username", "tfacctest"),
resource.TestCheckResourceAttr(resourceName, "port", "27017"),
resource.TestCheckResourceAttrSet(resourceName, "preferred_backup_window"),
resource.TestCheckResourceAttrSet(resourceName, "preferred_maintenance_window"),
resource.TestCheckResourceAttrSet(resourceName, "reader_endpoint"),
resource.TestCheckResourceAttr(resourceName, "skip_final_snapshot", "true"),
resource.TestCheckNoResourceAttr(resourceName, "snapshot_identifier"),
resource.TestCheckResourceAttr(resourceName, "storage_encrypted", "false"),
resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),
resource.TestCheckResourceAttr(resourceName, "vpc_security_group_ids.#", "1"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
"allow_major_version_upgrade",
"apply_immediately",
"cluster_identifier_prefix",
"final_snapshot_identifier",
"master_password",
"skip_final_snapshot",
},
},
{
Config: testAccClusterConfig_engineVersion(rName, "5.0.0"),
Check: resource.ComposeTestCheckFunc(
testAccCheckClusterExists(ctx, resourceName, &dbCluster),
resource.TestCheckResourceAttr(resourceName, "cluster_members.#", "1"),
resource.TestCheckResourceAttr(resourceName, "db_cluster_parameter_group_name", "default.docdb5.0"),
resource.TestCheckResourceAttr(resourceName, "engine_version", "5.0.0"),
),
},
},
})
}

func testAccCheckClusterDestroy(ctx context.Context) resource.TestCheckFunc {
return func(s *terraform.State) error {
conn := acctest.Provider.Meta().(*conns.AWSClient).DocDBConn(ctx)
Expand Down Expand Up @@ -1213,3 +1288,28 @@ resource "aws_docdb_cluster" "test" {
}
`, rName)
}

func testAccClusterConfig_engineVersion(rName, engineVersion string) string {
return fmt.Sprintf(`
resource "aws_docdb_cluster" "test" {
cluster_identifier = %[1]q
engine_version = %[2]q
master_password = "avoid-plaintext-passwords"
master_username = "tfacctest"
skip_final_snapshot = true
apply_immediately = true
allow_major_version_upgrade = true
}
data "aws_docdb_orderable_db_instance" "test" {
engine = aws_docdb_cluster.test.engine
preferred_instance_classes = ["db.t3.medium", "db.4tg.medium", "db.r5.large", "db.r6g.large"]
}
resource "aws_docdb_cluster_instance" "test" {
identifier = %[1]q
cluster_identifier = aws_docdb_cluster.test.id
instance_class = data.aws_docdb_orderable_db_instance.test.instance_class
}
`, rName, engineVersion)
}

0 comments on commit 4e8ee14

Please sign in to comment.