Skip to content

Commit

Permalink
feat: Add support for configuring Query Insights on Postgres instances (
Browse files Browse the repository at this point in the history
#198)

* Support Query Insights

* Create insights_config when enabled only

* Set default as null

* Simplify logic

* Update

* Update modules/postgresql/variables.tf

* Regenerate doc

Co-authored-by: Morgante Pell <morgante.pell@morgante.net>
  • Loading branch information
dhoeric and morgante committed Mar 8, 2021
1 parent 2b8a38f commit 2619b42
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions modules/postgresql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Note: CloudSQL provides [disk autoresize](https://cloud.google.com/sql/docs/mysq
| enable\_default\_db | Enable or disable the creation of the default database | bool | `"true"` | no |
| enable\_default\_user | Enable or disable the creation of the default user | bool | `"true"` | no |
| encryption\_key\_name | The full path to the encryption key used for the CMEK disk encryption | string | `"null"` | no |
| insights\_config | The insights_config settings for the database. | object | `"null"` | no |
| ip\_configuration | The ip configuration for the master instances. | object | `<map>` | no |
| maintenance\_window\_day | The day of week (1-7) for the master instance maintenance. | number | `"1"` | no |
| maintenance\_window\_hour | The hour of day (0-23) maintenance window for the master instance maintenance. | number | `"23"` | no |
Expand Down
10 changes: 10 additions & 0 deletions modules/postgresql/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ resource "google_sql_database_instance" "default" {
}
}
}
dynamic "insights_config" {
for_each = var.insights_config != null ? [var.insights_config] : []

content {
query_insights_enabled = true
query_string_length = lookup(insights_config.value, "query_string_length", 1024)
record_application_tags = lookup(insights_config.value, "record_application_tags", false)
record_client_address = lookup(insights_config.value, "record_client_address", false)
}
}

disk_autoresize = var.disk_autoresize
disk_size = var.disk_size
Expand Down
10 changes: 10 additions & 0 deletions modules/postgresql/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,16 @@ variable "backup_configuration" {
}
}

variable "insights_config" {
description = "The insights_config settings for the database."
type = object({
query_string_length = number
record_application_tags = bool
record_client_address = bool
})
default = null
}

variable "ip_configuration" {
description = "The ip configuration for the master instances."
type = object({
Expand Down

0 comments on commit 2619b42

Please sign in to comment.