Skip to content

Commit 59b32af

Browse files
smelchiorg-awmalik
andauthored
feat: support query insights for MySQL for read replicas (#453)
Co-authored-by: Awais Malik <[email protected]>
1 parent 4cdb81c commit 59b32af

File tree

5 files changed

+24
-2
lines changed

5 files changed

+24
-2
lines changed

modules/mysql/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Note: CloudSQL provides [disk autoresize](https://cloud.google.com/sql/docs/mysq
4646
| read\_replica\_deletion\_protection | Used to block Terraform from deleting replica SQL Instances. | `bool` | `false` | no |
4747
| read\_replica\_deletion\_protection\_enabled | Enables protection of a read replica from accidental deletion across all surfaces (API, gcloud, Cloud Console and Terraform). | `bool` | `false` | no |
4848
| read\_replica\_name\_suffix | The optional suffix to add to the read instance name | `string` | `""` | no |
49-
| read\_replicas | List of read replicas to create. Encryption key is required for replica in different region. For replica in same region as master set encryption\_key\_name = null | <pre>list(object({<br> name = string<br> name_override = optional(string)<br> tier = string<br> zone = string<br> availability_type = string<br> disk_type = string<br> disk_autoresize = bool<br> disk_autoresize_limit = number<br> disk_size = string<br> user_labels = map(string)<br> database_flags = list(object({<br> name = string<br> value = string<br> }))<br> ip_configuration = 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> })<br> encryption_key_name = string<br> }))</pre> | `[]` | no |
49+
| read\_replicas | List of read replicas to create. Encryption key is required for replica in different region. For replica in same region as master set encryption\_key\_name = null | <pre>list(object({<br> name = string<br> name_override = optional(string)<br> tier = string<br> zone = string<br> availability_type = string<br> disk_type = string<br> disk_autoresize = bool<br> disk_autoresize_limit = number<br> disk_size = string<br> user_labels = map(string)<br> database_flags = list(object({<br> name = string<br> value = string<br> }))<br> insights_config = optional(object({<br> query_string_length = number<br> record_application_tags = bool<br> record_client_address = bool<br> }))<br> ip_configuration = 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> })<br> encryption_key_name = string<br> }))</pre> | `[]` | no |
5050
| region | The region of the Cloud SQL resources | `string` | `"us-central1"` | no |
5151
| replica\_database\_version | The read replica database version to use. This var should only be used during a database update. The update sequence 1. read-replica 2. master, setting this to an updated version will cause the replica to update, then you may update the master with the var database\_version and remove this field after update is complete | `string` | `""` | no |
5252
| root\_password | Mysql password for the root user. If not set, a random one will be generated and available in the root\_password output variable. | `string` | `""` | no |

modules/mysql/read_replica.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@ resource "google_sql_database_instance" "replicas" {
4141
availability_type = lookup(each.value, "availability_type", var.availability_type)
4242
deletion_protection_enabled = var.read_replica_deletion_protection_enabled
4343

44+
45+
dynamic "insights_config" {
46+
for_each = lookup(each.value, "insights_config") != null ? [lookup(each.value, "insights_config")] : []
47+
48+
content {
49+
query_insights_enabled = true
50+
query_string_length = lookup(insights_config.value, "query_string_length", 1024)
51+
record_application_tags = lookup(insights_config.value, "record_application_tags", false)
52+
record_client_address = lookup(insights_config.value, "record_client_address", false)
53+
}
54+
}
55+
4456
dynamic "ip_configuration" {
4557
for_each = [lookup(each.value, "ip_configuration", {})]
4658
content {

modules/mysql/variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,11 @@ variable "read_replicas" {
252252
name = string
253253
value = string
254254
}))
255+
insights_config = optional(object({
256+
query_string_length = number
257+
record_application_tags = bool
258+
record_client_address = bool
259+
}))
255260
ip_configuration = object({
256261
authorized_networks = list(map(string))
257262
ipv4_enabled = bool

modules/safer_mysql/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ mysql -S $HOME/mysql_sockets/myproject:region:instance -u user -p
199199
| read\_replica\_deletion\_protection | Used to block Terraform from deleting replica SQL Instances. | `bool` | `false` | no |
200200
| read\_replica\_deletion\_protection\_enabled | Enables protection of a read replica from accidental deletion across all surfaces (API, gcloud, Cloud Console and Terraform). | `bool` | `false` | no |
201201
| read\_replica\_name\_suffix | The optional suffix to add to the read instance name | `string` | `""` | no |
202-
| read\_replicas | List of read replicas to create. Encryption key is required for replica in different region. For replica in same region as master set encryption\_key\_name = null | <pre>list(object({<br> name = string<br> name_override = optional(string)<br> tier = string<br> availability_type = string<br> zone = string<br> disk_type = string<br> disk_autoresize = bool<br> disk_autoresize_limit = number<br> disk_size = string<br> user_labels = map(string)<br> database_flags = list(object({<br> name = string<br> value = string<br> }))<br> ip_configuration = 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> })<br> encryption_key_name = string<br> }))</pre> | `[]` | no |
202+
| read\_replicas | List of read replicas to create. Encryption key is required for replica in different region. For replica in same region as master set encryption\_key\_name = null | <pre>list(object({<br> name = string<br> name_override = optional(string)<br> tier = string<br> availability_type = string<br> zone = string<br> disk_type = string<br> disk_autoresize = bool<br> disk_autoresize_limit = number<br> disk_size = string<br> user_labels = map(string)<br> database_flags = list(object({<br> name = string<br> value = string<br> }))<br> insights_config = optional(object({<br> query_string_length = number<br> record_application_tags = bool<br> record_client_address = bool<br> }))<br> ip_configuration = 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> })<br> encryption_key_name = string<br> }))</pre> | `[]` | no |
203203
| region | The region of the Cloud SQL resources | `string` | n/a | yes |
204204
| secondary\_zone | The preferred zone for the secondary/failover instance, it should be something like: `us-central1-a`, `us-east1-c`. | `string` | `null` | no |
205205
| tier | The tier for the master instance. | `string` | `"db-n1-standard-1"` | no |

modules/safer_mysql/variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,11 @@ variable "read_replicas" {
227227
name = string
228228
value = string
229229
}))
230+
insights_config = optional(object({
231+
query_string_length = number
232+
record_application_tags = bool
233+
record_client_address = bool
234+
}))
230235
ip_configuration = object({
231236
authorized_networks = list(map(string))
232237
ipv4_enabled = bool

0 commit comments

Comments
 (0)