Skip to content

Commit 2619b42

Browse files
dhoericmorgante
andauthored
feat: Add support for configuring Query Insights on Postgres instances (#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 <[email protected]>
1 parent 2b8a38f commit 2619b42

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

modules/postgresql/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Note: CloudSQL provides [disk autoresize](https://cloud.google.com/sql/docs/mysq
2626
| enable\_default\_db | Enable or disable the creation of the default database | bool | `"true"` | no |
2727
| enable\_default\_user | Enable or disable the creation of the default user | bool | `"true"` | no |
2828
| encryption\_key\_name | The full path to the encryption key used for the CMEK disk encryption | string | `"null"` | no |
29+
| insights\_config | The insights_config settings for the database. | object | `"null"` | no |
2930
| ip\_configuration | The ip configuration for the master instances. | object | `<map>` | no |
3031
| maintenance\_window\_day | The day of week (1-7) for the master instance maintenance. | number | `"1"` | no |
3132
| maintenance\_window\_hour | The hour of day (0-23) maintenance window for the master instance maintenance. | number | `"23"` | no |

modules/postgresql/main.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,16 @@ resource "google_sql_database_instance" "default" {
7575
}
7676
}
7777
}
78+
dynamic "insights_config" {
79+
for_each = var.insights_config != null ? [var.insights_config] : []
80+
81+
content {
82+
query_insights_enabled = true
83+
query_string_length = lookup(insights_config.value, "query_string_length", 1024)
84+
record_application_tags = lookup(insights_config.value, "record_application_tags", false)
85+
record_client_address = lookup(insights_config.value, "record_client_address", false)
86+
}
87+
}
7888

7989
disk_autoresize = var.disk_autoresize
8090
disk_size = var.disk_size

modules/postgresql/variables.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,16 @@ variable "backup_configuration" {
138138
}
139139
}
140140

141+
variable "insights_config" {
142+
description = "The insights_config settings for the database."
143+
type = object({
144+
query_string_length = number
145+
record_application_tags = bool
146+
record_client_address = bool
147+
})
148+
default = null
149+
}
150+
141151
variable "ip_configuration" {
142152
description = "The ip configuration for the master instances."
143153
type = object({

0 commit comments

Comments
 (0)