Skip to content

Commit

Permalink
feat: Support Query Insights for MySQL (#354)
Browse files Browse the repository at this point in the history
* Support Query Insights for MySQL

* Generated docs

* Add insights_config for safer_mysql

* Update docs with insights_config for safer_mysql
  • Loading branch information
thealgirdas committed Oct 26, 2022
1 parent f991c22 commit d932391
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions modules/mysql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,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. | <pre>object({<br> query_string_length = number<br> record_application_tags = bool<br> record_client_address = bool<br> })</pre> | `null` | no |
| ip\_configuration | The ip\_configuration settings subblock | <pre>object({<br> authorized_networks = list(map(string))<br> ipv4_enabled = bool<br> private_network = string<br> require_ssl = bool<br> allocated_ip_range = string<br> })</pre> | <pre>{<br> "allocated_ip_range": null,<br> "authorized_networks": [],<br> "ipv4_enabled": true,<br> "private_network": null,<br> "require_ssl": null<br>}</pre> | 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/mysql/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,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)
}
}
dynamic "ip_configuration" {
for_each = [local.ip_configurations[local.ip_configuration_enabled ? "enabled" : "disabled"]]
content {
Expand Down
10 changes: 10 additions & 0 deletions modules/mysql/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,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 settings subblock"
type = object({
Expand Down
1 change: 1 addition & 0 deletions modules/safer_mysql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ mysql -S $HOME/mysql_sockets/myproject:region:instance -u user -p
| disk\_size | The disk size for the master instance | `number` | `10` | no |
| disk\_type | The disk type for the master instance. | `string` | `"PD_SSD"` | 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. | <pre>object({<br> query_string_length = number<br> record_application_tags = bool<br> record_client_address = bool<br> })</pre> | `null` | 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 |
| maintenance\_window\_update\_track | The update track of maintenance window for the master instance maintenance. Can be either `canary` or `stable`. | `string` | `"stable"` | no |
Expand Down
2 changes: 2 additions & 0 deletions modules/safer_mysql/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ module "safer_mysql" {

backup_configuration = var.backup_configuration

insights_config = var.insights_config

ip_configuration = {
ipv4_enabled = var.assign_public_ip
# We never set authorized networks, we need all connections via the
Expand Down
10 changes: 10 additions & 0 deletions modules/safer_mysql/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -296,3 +296,13 @@ variable "encryption_key_name" {
type = string
default = null
}

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
}

0 comments on commit d932391

Please sign in to comment.