Skip to content

Commit

Permalink
Update documentation and add test case for data cache setting as it i…
Browse files Browse the repository at this point in the history
…s available for postgres now (GoogleCloudPlatform#9241)
  • Loading branch information
nityanavali1 authored and jialei-chen committed Nov 29, 2023
1 parent 94446d1 commit 18b9038
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1573,6 +1573,38 @@ func TestAccSQLDatabaseInstance_sqlMysqlDataCacheConfig(t *testing.T) {
})
}

func TestAccSQLDatabaseInstance_sqlPostgresDataCacheConfig(t *testing.T) {
t.Parallel()
enterprisePlusInstanceName := "tf-test-enterprise-plus" + acctest.RandString(t, 10)
enterprisePlusTier := "db-perf-optimized-N-2"
enterpriseInstanceName := "tf-test-enterprise-" + acctest.RandString(t, 10)
enterpriseTier := "db-custom-2-13312"
acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccSqlDatabaseInstanceDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testGoogleSqlDatabaseInstance_sqlPostgresDataCacheConfig(enterprisePlusInstanceName, enterprisePlusTier, "ENTERPRISE_PLUS"),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("google_sql_database_instance.instance", "settings.0.data_cache_config.0.data_cache_enabled", "true"),
),
},
{
ResourceName: "google_sql_database_instance.instance",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"deletion_protection"},
},
{
Config: testGoogleSqlDatabaseInstance_sqlPostgresDataCacheConfig(enterpriseInstanceName, enterpriseTier, "ENTERPRISE"),
ExpectError: regexp.MustCompile(
fmt.Sprintf("Error, failed to create instance %s: googleapi: Error 400: Invalid request: Only ENTERPRISE PLUS edition supports data cache.., invalid", enterpriseInstanceName)),
},
},
})
}

func TestAccSqlDatabaseInstance_SqlServerAuditConfig(t *testing.T) {
// Service Networking
acctest.SkipIfVcr(t)
Expand Down Expand Up @@ -2363,6 +2395,24 @@ resource "google_sql_database_instance" "instance" {
}`, instanceName)
}

func testGoogleSqlDatabaseInstance_sqlPostgresDataCacheConfig(instanceName, tier, edition string) string {
return fmt.Sprintf(`
resource "google_sql_database_instance" "instance" {
name = "%s"
region = "us-east1"
database_version = "POSTGRES_14"
deletion_protection = false
settings {
tier = "%s"
edition = "%s"
data_cache_config {
data_cache_enabled = true
}
}
}`, instanceName, tier, edition)
}

func testGoogleSqlDatabaseInstance_SqlServerAuditConfig(databaseName, rootPassword, bucketName, uploadInterval, retentionInterval string) string {
return fmt.Sprintf(`
resource "google_storage_bucket" "gs-bucket" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,7 @@ The optional `settings.active_directory_config` subblock supports:

The optional `settings.data_cache_config` subblock supports:

* `data_cache_enabled` - (Optional) Whether data cache is enabled for the instance. Defaults to `false`
Can only be used with MYSQL.
* `data_cache_enabled` - (Optional) Whether data cache is enabled for the instance. Defaults to `false`. Can be used with MYSQL and PostgreSQL only.

The optional `settings.deny_maintenance_period` subblock supports:

Expand Down

0 comments on commit 18b9038

Please sign in to comment.