Skip to content

Commit

Permalink
feat: Additional database flags and refactor to allow new flags to be…
Browse files Browse the repository at this point in the history
… passed via map (#181)

* feat: Additional database flags and refactor to allow new flags to be passed via map

* terraform-docs: automated action

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
danielpanzella and github-actions[bot] authored Nov 27, 2024
1 parent 6b86b4a commit 68ed4d2
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 24 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ resources that lack official modules.
| <a name="input_create_private_link"></a> [create\_private\_link](#input\_create\_private\_link) | Whether to create a private link service. | `bool` | `false` | no |
| <a name="input_create_redis"></a> [create\_redis](#input\_create\_redis) | Boolean indicating whether to provision an redis instance (true) or not (false). | `bool` | `false` | no |
| <a name="input_create_workload_identity"></a> [create\_workload\_identity](#input\_create\_workload\_identity) | Flag to indicate whether to create a workload identity for the service account. | `bool` | `false` | no |
| <a name="input_database_flags"></a> [database\_flags](#input\_database\_flags) | Flags to set for the database | `map(string)` | `{}` | no |
| <a name="input_database_machine_type"></a> [database\_machine\_type](#input\_database\_machine\_type) | Specifies the machine type to be allocated for the database. Defaults to null and value from deployment-size.tf is used | `string` | `null` | no |
| <a name="input_database_sort_buffer_size"></a> [database\_sort\_buffer\_size](#input\_database\_sort\_buffer\_size) | Specifies the sort\_buffer\_size value to set for the database | `number` | `67108864` | no |
| <a name="input_database_version"></a> [database\_version](#input\_database\_version) | Version for MySQL | `string` | `"MYSQL_8_0_31"` | no |
Expand Down
1 change: 1 addition & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ module "database" {
database_version = var.database_version
force_ssl = var.force_ssl
tier = local.database_machine_type
database_flags = var.database_flags
sort_buffer_size = var.database_sort_buffer_size
network_connection = local.network_connection
deletion_protection = var.deletion_protection
Expand Down
46 changes: 22 additions & 24 deletions modules/database/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@ locals {
data "google_project" "default" {
}

locals {
default_flags = {
"binlog_row_image" = "MINIMAL"
"binlog_row_value_options" = "PARTIAL_JSON"
"innodb_autoinc_lock_mode" = "2"
"innodb_lru_scan_depth" = "100"
"innodb_print_all_deadlocks" = "off"
"long_query_time" = "1"
"max_prepared_stmt_count" = "1048576"
"max_execution_time" = "60000"
"slow_query_log" = "on"
"sort_buffer_size" = var.sort_buffer_size
}
database_flags = merge(local.default_flags, var.database_flags)
}

resource "google_sql_database_instance" "default" {
name = local.master_instance_name
database_version = var.database_version
Expand Down Expand Up @@ -59,30 +75,12 @@ resource "google_sql_database_instance" "default" {
require_ssl = var.force_ssl
}

# requires minimum memory of 26624 MB
# database_flags {
# name = "performance_schema"
# value = 1
# }
database_flags {
name = "slow_query_log"
value = "on"
}
database_flags {
name = "long_query_time"
value = 1
}
database_flags {
name = "max_prepared_stmt_count"
value = 1048576
}
database_flags {
name = "max_execution_time"
value = 60000
}
database_flags {
name = "sort_buffer_size"
value = var.sort_buffer_size
dynamic "database_flags" {
for_each = local.database_flags
content {
name = database_flags.key
value = database_flags.value
}
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions modules/database/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ variable "database_version" {
default = "MYSQL_8_0_31"
}

variable "database_flags" {
description = "Flags to set for the database"
type = map(string)
default = {}
}

variable "sort_buffer_size" {
description = "Specifies the sort_buffer_size value to set for the database"
type = number
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,12 @@ variable "database_machine_type" {
default = null
}

variable "database_flags" {
description = "Flags to set for the database"
type = map(string)
default = {}
}

variable "database_sort_buffer_size" {
description = "Specifies the sort_buffer_size value to set for the database"
type = number
Expand Down

0 comments on commit 68ed4d2

Please sign in to comment.