Skip to content

Commit c724c62

Browse files
committed
feat: add pooling configuration for postgresql and mysql
1 parent 3b07de8 commit c724c62

File tree

19 files changed

+177
-28
lines changed

19 files changed

+177
-28
lines changed

metadata.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ spec:
7575
roles:
7676
- level: Project
7777
roles:
78+
- roles/resourcemanager.projectIamAdmin
79+
- roles/serviceusage.serviceUsageAdmin
7880
- roles/cloudsql.admin
7981
- roles/iam.serviceAccountAdmin
8082
- roles/iam.serviceAccountUser
81-
- roles/resourcemanager.projectIamAdmin
82-
- roles/serviceusage.serviceUsageAdmin
8383
services:
8484
- cloudresourcemanager.googleapis.com
8585
- iam.googleapis.com

modules/backup/metadata.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,4 +199,4 @@ spec:
199199
- sqladmin.googleapis.com
200200
providerVersions:
201201
- source: hashicorp/google
202-
version: ">= 6.11.0, < 7"
202+
version: ">= 6.11.0, < 8"

modules/mssql/metadata.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,10 @@ spec:
221221
retention_unit: null
222222
start_time: null
223223
transaction_log_retention_days: null
224+
- name: retain_backups_on_delete
225+
description: When this parameter is set to true, Cloud SQL retains backups of the instance even after the instance is deleted. The ON_DEMAND backup will be retained until customer deletes the backup or the project. The AUTOMATED backup will be retained based on the backups retention setting.
226+
varType: bool
227+
defaultValue: false
224228
- name: db_name
225229
description: The name of the default database to create
226230
varType: string
@@ -576,9 +580,9 @@ spec:
576580
- sqladmin.googleapis.com
577581
providerVersions:
578582
- source: hashicorp/google
579-
version: ">= 5.12, < 7"
583+
version: ">= 5.12, < 8"
580584
- source: hashicorp/google-beta
581-
version: ">= 5.12, < 7"
585+
version: ">= 5.12, < 8"
582586
- source: hashicorp/null
583587
version: ~> 3.2
584588
- source: hashicorp/random

modules/mysql/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ module "mysql-db" {
5050
| additional\_users | A list of users to be created in your cluster. A random password would be set for the user if the `random_password` variable is set. | <pre>list(object({<br> name = string<br> password = string<br> random_password = bool<br> type = string<br> host = string<br> }))</pre> | `[]` | no |
5151
| availability\_type | The availability type for the master instance. Can be either `REGIONAL` or `null`. | `string` | `"REGIONAL"` | no |
5252
| backup\_configuration | The backup\_configuration settings subblock for the database settings | <pre>object({<br> binary_log_enabled = optional(bool, false)<br> enabled = optional(bool, false)<br> start_time = optional(string)<br> location = optional(string)<br> transaction_log_retention_days = optional(string)<br> retained_backups = optional(number)<br> retention_unit = optional(string)<br> })</pre> | `{}` | no |
53+
| connection\_pool\_config | Manager connection pooling configuration | <pre>object({<br> enabled = optional(bool, false)<br> flags = optional(list(object({<br> name = string<br> value = string<br> })), [])<br> })</pre> | n/a | yes |
5354
| connector\_enforcement | Enforce that clients use the connector library | `bool` | `false` | no |
5455
| create\_timeout | The optional timout that is applied to limit long database creates. | `string` | `"30m"` | no |
5556
| data\_cache\_enabled | Whether data cache is enabled for the instance. Defaults to false. Feature is only available for ENTERPRISE\_PLUS tier and supported database\_versions | `bool` | `false` | no |
@@ -94,7 +95,7 @@ module "mysql-db" {
9495
| read\_replica\_deletion\_protection | Used to block Terraform from deleting replica SQL Instances. | `bool` | `false` | no |
9596
| 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 |
9697
| read\_replica\_name\_suffix | The optional suffix to add to the read instance name | `string` | `""` | no |
97-
| 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 = optional(string)<br> edition = optional(string)<br> availability_type = optional(string)<br> zone = optional(string)<br> disk_type = optional(string)<br> disk_autoresize = optional(bool)<br> disk_autoresize_limit = optional(number)<br> disk_size = optional(string)<br> user_labels = map(string)<br> database_flags = list(object({<br> name = string<br> value = string<br> }))<br> backup_configuration = optional(object({<br> binary_log_enabled = bool<br> transaction_log_retention_days = string<br> }))<br> insights_config = optional(object({<br> query_plans_per_minute = number<br> query_string_length = number<br> record_application_tags = bool<br> record_client_address = bool<br> }))<br> ip_configuration = object({<br> authorized_networks = optional(list(map(string)), [])<br> ipv4_enabled = optional(bool)<br> private_network = optional(string)<br> ssl_mode = optional(string)<br> allocated_ip_range = optional(string)<br> enable_private_path_for_google_cloud_services = optional(bool, false)<br> psc_enabled = optional(bool, false)<br> psc_allowed_consumer_projects = optional(list(string), [])<br> })<br> encryption_key_name = optional(string)<br> data_cache_enabled = optional(bool)<br> }))</pre> | `[]` | no |
98+
| 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 = optional(string)<br> edition = optional(string)<br> availability_type = optional(string)<br> zone = optional(string)<br> disk_type = optional(string)<br> disk_autoresize = optional(bool)<br> disk_autoresize_limit = optional(number)<br> disk_size = optional(string)<br> user_labels = map(string)<br> connection_pool_config = optional(object({<br> enabled = optional(bool, false)<br> flags = optional(list(object({<br> name = string<br> value = string<br> })), [])<br> }), null)<br> database_flags = list(object({<br> name = string<br> value = string<br> }))<br> backup_configuration = optional(object({<br> binary_log_enabled = bool<br> transaction_log_retention_days = string<br> }))<br> insights_config = optional(object({<br> query_plans_per_minute = number<br> query_string_length = number<br> record_application_tags = bool<br> record_client_address = bool<br> }))<br> ip_configuration = object({<br> authorized_networks = optional(list(map(string)), [])<br> ipv4_enabled = optional(bool)<br> private_network = optional(string)<br> ssl_mode = optional(string)<br> allocated_ip_range = optional(string)<br> enable_private_path_for_google_cloud_services = optional(bool, false)<br> psc_enabled = optional(bool, false)<br> psc_allowed_consumer_projects = optional(list(string), [])<br> })<br> encryption_key_name = optional(string)<br> data_cache_enabled = optional(bool)<br> }))</pre> | `[]` | no |
9899
| region | The region of the Cloud SQL resources | `string` | `"us-central1"` | no |
99100
| 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 |
100101
| retain\_backups\_on\_delete | When this parameter is set to true, Cloud SQL retains backups of the instance even after the instance is deleted. The ON\_DEMAND backup will be retained until customer deletes the backup or the project. The AUTOMATED backup will be retained based on the backups retention setting. | `bool` | `false` | no |

modules/mysql/main.tf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,21 @@ resource "google_sql_database_instance" "default" {
173173
disk_type = var.disk_type
174174
pricing_plan = var.pricing_plan
175175
user_labels = var.user_labels
176+
177+
dynamic "connection_pool_config" {
178+
for_each = var.connection_pool_config != null ? [var.connection_pool_config] : []
179+
content {
180+
connection_pooling_enabled = var.connection_pool_config.enabled
181+
dynamic "flags" {
182+
for_each = var.connection_pool_config.flags
183+
content {
184+
name = flags.name
185+
value = flags.value
186+
}
187+
}
188+
}
189+
}
190+
176191
dynamic "database_flags" {
177192
for_each = var.database_flags
178193
content {

modules/mysql/metadata.yaml

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ spec:
189189
description: Users can upgrade a read replica instance to a stand-alone Cloud SQL instance with the help of instance_type. To promote, users have to set the instance_type property as CLOUD_SQL_INSTANCE and remove/unset master_instance_name and replica_configuration from instance configuration. This operation might cause your instance to restart.
190190
varType: string
191191
- name: tier
192-
description: The tier for the master instance, for ADC its defualt value will be db-perf-optimized-N-8 which is tier value for edtion ENTERPRISE_PLUS, if user wants to change the edition, he should chose compatible tier.
192+
description: The tier for the master instance, for ADC its default value will be db-perf-optimized-N-8 which is tier value for edition ENTERPRISE_PLUS, if user wants to change the edition, he should chose compatible tier.
193193
varType: string
194194
defaultValue: db-n1-standard-1
195195
- name: zone
@@ -267,7 +267,7 @@ spec:
267267
}))
268268
defaultValue: []
269269
- name: backup_configuration
270-
description: The backup_configuration settings subblock for the database setings
270+
description: The backup_configuration settings subblock for the database settings
271271
varType: |-
272272
object({
273273
binary_log_enabled = optional(bool, false)
@@ -338,6 +338,13 @@ spec:
338338
disk_autoresize_limit = optional(number)
339339
disk_size = optional(string)
340340
user_labels = map(string)
341+
connection_pool_config = optional(object({
342+
enabled = optional(bool, false)
343+
flags = optional(list(object({
344+
name = string
345+
value = string
346+
})), [])
347+
}), null)
341348
database_flags = list(object({
342349
name = string
343350
value = string
@@ -421,6 +428,17 @@ spec:
421428
description: The roles required by default database instance service account for integration with GCP services
422429
varType: list(string)
423430
defaultValue: []
431+
- name: connection_pool_config
432+
description: Manager connection pooling configuration
433+
varType: |-
434+
object({
435+
enabled = optional(bool, false)
436+
flags = optional(list(object({
437+
name = string
438+
value = string
439+
})), [])
440+
})
441+
required: true
424442
outputs:
425443
- name: additional_users
426444
description: List of maps of additional users and passwords
@@ -918,12 +936,12 @@ spec:
918936
roles:
919937
- level: Project
920938
roles:
921-
- roles/iam.serviceAccountUser
922-
- roles/compute.networkAdmin
923939
- roles/cloudkms.cryptoKeyEncrypterDecrypter
924940
- roles/logging.logWriter
925941
- roles/cloudsql.admin
926942
- roles/resourcemanager.projectIamAdmin
943+
- roles/iam.serviceAccountUser
944+
- roles/compute.networkAdmin
927945
services:
928946
- cloudkms.googleapis.com
929947
- cloudresourcemanager.googleapis.com
@@ -935,9 +953,9 @@ spec:
935953
- sqladmin.googleapis.com
936954
providerVersions:
937955
- source: hashicorp/google
938-
version: ">= 6.31, < 7"
956+
version: ">= 6.31, < 8"
939957
- source: hashicorp/google-beta
940-
version: ">= 6.31, < 7"
958+
version: ">= 6.31, < 8"
941959
- source: hashicorp/null
942960
version: ~> 3.1
943961
- source: hashicorp/random

modules/mysql/read_replica.tf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,20 @@ resource "google_sql_database_instance" "replicas" {
104104
pricing_plan = "PER_USE"
105105
user_labels = lookup(each.value, "user_labels", var.user_labels)
106106

107+
dynamic "connection_pool_config" {
108+
for_each = var.connection_pool_config != null ? [var.connection_pool_config] : []
109+
content {
110+
connection_pooling_enabled = var.connection_pool_config.enabled
111+
dynamic "flags" {
112+
for_each = var.connection_pool_config.flags
113+
content {
114+
name = flags.value.name
115+
value = flags.value.value
116+
}
117+
}
118+
}
119+
}
120+
107121
dynamic "database_flags" {
108122
for_each = lookup(each.value, "database_flags", [])
109123
content {

modules/mysql/variables.tf

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,13 @@ variable "read_replicas" {
373373
disk_autoresize_limit = optional(number)
374374
disk_size = optional(string)
375375
user_labels = map(string)
376+
connection_pool_config = optional(object({
377+
enabled = optional(bool, false)
378+
flags = optional(list(object({
379+
name = string
380+
value = string
381+
})), [])
382+
}), null)
376383
database_flags = list(object({
377384
name = string
378385
value = string
@@ -487,3 +494,13 @@ variable "database_integration_roles" {
487494
default = []
488495
}
489496

497+
variable "connection_pool_config" {
498+
description = "Manager connection pooling configuration"
499+
type = object({
500+
enabled = optional(bool, false)
501+
flags = optional(list(object({
502+
name = string
503+
value = string
504+
})), [])
505+
})
506+
}

0 commit comments

Comments
 (0)