diff --git a/examples/postgresql-public/main.tf b/examples/postgresql-public/main.tf index d439a973..ec8f3ae8 100644 --- a/examples/postgresql-public/main.tf +++ b/examples/postgresql-public/main.tf @@ -19,11 +19,13 @@ module "postgresql-db" { source = "../../modules/postgresql" name = var.db_name random_instance_name = true - database_version = "POSTGRES_9_6" + database_version = "POSTGRES_14" project_id = var.project_id zone = "us-central1-c" region = "us-central1" - tier = "db-custom-1-3840" + edition = "ENTERPRISE_PLUS" + tier = "db-perf-optimized-N-2" + data_cache_enabled = true deletion_protection = false diff --git a/modules/postgresql/README.md b/modules/postgresql/README.md index 7b74bfbd..bd3cc467 100644 --- a/modules/postgresql/README.md +++ b/modules/postgresql/README.md @@ -14,6 +14,7 @@ Note: CloudSQL provides [disk autoresize](https://cloud.google.com/sql/docs/mysq | backup\_configuration | The backup\_configuration settings subblock for the database setings |
object({
enabled = optional(bool, false)
start_time = optional(string)
location = optional(string)
point_in_time_recovery_enabled = optional(bool, false)
transaction_log_retention_days = optional(string)
retained_backups = optional(number)
retention_unit = optional(string)
})
| `{}` | no | | connector\_enforcement | Enforce that clients use the connector library | `bool` | `false` | no | | create\_timeout | The optional timout that is applied to limit long database creates. | `string` | `"30m"` | no | +| data\_cache\_enabled | Whether data cache is enabled for the instance. Defaults to false. Feature is only available for ENTERPRISE\_PLUS tier and supported database\_versions | `bool` | `false` | no | | database\_deletion\_policy | The deletion policy for the database. Setting ABANDON allows the resource to be abandoned rather than deleted. This is useful for Postgres, where databases cannot be deleted from the API if there are users other than cloudsqlsuperuser with access. Possible values are: "ABANDON". | `string` | `null` | no | | database\_flags | The database flags for the master instance. See [more details](https://cloud.google.com/sql/docs/postgres/flags) |
list(object({
name = string
value = string
}))
| `[]` | no | | database\_version | The database version to use | `string` | n/a | yes | diff --git a/modules/postgresql/main.tf b/modules/postgresql/main.tf index 12737b92..e7d49705 100644 --- a/modules/postgresql/main.tf +++ b/modules/postgresql/main.tf @@ -85,6 +85,12 @@ resource "google_sql_database_instance" "default" { } } } + dynamic "data_cache_config" { + for_each = var.edition == "ENTERPRISE_PLUS" && var.data_cache_enabled ? ["cache_enabled"] : [] + content { + data_cache_enabled = var.data_cache_enabled + } + } dynamic "deny_maintenance_period" { for_each = var.deny_maintenance_period content { diff --git a/modules/postgresql/variables.tf b/modules/postgresql/variables.tf index 5adc094f..acf463f5 100644 --- a/modules/postgresql/variables.tf +++ b/modules/postgresql/variables.tf @@ -413,3 +413,9 @@ variable "connector_enforcement" { type = bool default = false } + +variable "data_cache_enabled" { + description = "Whether data cache is enabled for the instance. Defaults to false. Feature is only available for ENTERPRISE_PLUS tier and supported database_versions" + type = bool + default = false +} diff --git a/test/integration/postgresql-public/postgresql_public_test.go b/test/integration/postgresql-public/postgresql_public_test.go index e473dfa2..0c813c90 100644 --- a/test/integration/postgresql-public/postgresql_public_test.go +++ b/test/integration/postgresql-public/postgresql_public_test.go @@ -40,8 +40,7 @@ func TestPostgreSqlPublicModule(t *testing.T) { assert.Equal("SYNCHRONOUS", op.Get("settings.replicationType").String(), "Expected SYNCHRONOUS replicationType") assert.True(op.Get("settings.storageAutoResize").Bool(), "Expected TRUE storageAutoResize") assert.Equal(int64(0), op.Get("settings.storageAutoResizeLimit").Int(), "Expected 0 storageAutoResizeLimit") - assert.Equal("db-custom-1-3840", op.Get("settings.tier").String(), "Expected db-custom-1-3840 tier") - + assert.Equal("db-perf-optimized-N-2", op.Get("settings.tier").String(), "Expected db-perf-optimized-N-2 tier") // assert location database settings assert.Equal("sql#locationPreference", op.Get("settings.locationPreference.kind").String(), "Expected sql#locationPreference locationPreference.kind") assert.Equal("us-central1-c", op.Get("settings.locationPreference.zone").String(), "Expected us-central1-c locationPreference.zone") @@ -53,7 +52,7 @@ func TestPostgreSqlPublicModule(t *testing.T) { assert.Equal("canary", op.Get("settings.maintenanceWindow.updateTrack").String(), "Expected canary maintenanceWindow.updateTrack") // assert standard database settings - assert.Equal("POSTGRES_9_6", op.Get("databaseVersion").String(), "Expected POSTGRES_9_6 databaseVersion") + assert.Equal("POSTGRES_14", op.Get("databaseVersion").String(), "Expected POSTGRES_14 databaseVersion") assert.Equal("SECOND_GEN", op.Get("backendType").String(), "Expected SECOND_GEN backendType") assert.Equal("RUNNABLE", op.Get("state").String(), "Expected RUNNABLE state") assert.Equal("us-central1", op.Get("region").String(), "Expected us-central1 region")