Skip to content

Commit

Permalink
tests: add a acc test for CAS instance creation. (#11931)
Browse files Browse the repository at this point in the history
  • Loading branch information
feng-zhe authored Oct 7, 2024
1 parent 64d9dd8 commit 1c7cde2
Showing 1 changed file with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2488,6 +2488,50 @@ func TestAccSqlDatabaseInstance_useInternalCaByDefault(t *testing.T) {
})
}

func TestAccSqlDatabaseInstance_useCasBasedServerCa(t *testing.T) {
t.Parallel()

databaseName := "tf-test-" + acctest.RandString(t, 10)
resourceName := "google_sql_database_instance.instance"

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccSqlDatabaseInstanceDestroyProducer(t),

Steps: []resource.TestStep{
{
Config: testGoogleSqlDatabaseInstance_setCasServerCa(databaseName, "GOOGLE_MANAGED_CAS_CA"),
Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttr(resourceName, "settings.0.ip_configuration.0.server_ca_mode", "GOOGLE_MANAGED_CAS_CA")),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"deletion_protection"},
},
},
})
}

func testGoogleSqlDatabaseInstance_setCasServerCa(databaseName, serverCaMode string) string {
return fmt.Sprintf(`
resource "google_sql_database_instance" "instance" {
name = "%s"
region = "us-central1"
database_version = "POSTGRES_15"
deletion_protection = false
settings {
tier = "db-f1-micro"
ip_configuration {
ipv4_enabled = "true"
server_ca_mode = "%s"
}
}
}
`, databaseName, serverCaMode)
}

func testGoogleSqlDatabaseInstance_setSslOptionsForPostgreSQL(databaseName string, databaseVersion string, sslMode string) string {
return fmt.Sprintf(`
resource "google_sql_database_instance" "instance" {
Expand Down

0 comments on commit 1c7cde2

Please sign in to comment.