Skip to content

Commit

Permalink
feat: adding data_cache_config to postgresql module (#531)
Browse files Browse the repository at this point in the history
Co-authored-by: Imran Nayer <imrannayer@google.com>
Co-authored-by: Awais Malik <awmalik@google.com>
  • Loading branch information
3 people committed Nov 8, 2023
1 parent a99bfe2 commit f04d617
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
6 changes: 4 additions & 2 deletions examples/postgresql-public/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions modules/postgresql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 | <pre>object({<br> enabled = optional(bool, false)<br> start_time = optional(string)<br> location = optional(string)<br> point_in_time_recovery_enabled = optional(bool, false)<br> transaction_log_retention_days = optional(string)<br> retained_backups = optional(number)<br> retention_unit = optional(string)<br> })</pre> | `{}` | 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) | <pre>list(object({<br> name = string<br> value = string<br> }))</pre> | `[]` | no |
| database\_version | The database version to use | `string` | n/a | yes |
Expand Down
6 changes: 6 additions & 0 deletions modules/postgresql/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions modules/postgresql/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
5 changes: 2 additions & 3 deletions test/integration/postgresql-public/postgresql_public_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand Down

0 comments on commit f04d617

Please sign in to comment.