Skip to content

Commit 2df794b

Browse files
maguecChris Maguemnahkies
authored
feat: make connector enforcement configurable (#439)
Co-authored-by: Chris Mague <[email protected]> Co-authored-by: Michael Nahkies <[email protected]>
1 parent 0ceb0ed commit 2df794b

File tree

4 files changed

+16
-0
lines changed

4 files changed

+16
-0
lines changed

modules/mysql/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Note: CloudSQL provides [disk autoresize](https://cloud.google.com/sql/docs/mysq
1212
| 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 |
1313
| availability\_type | The availability type for the master instance. Can be either `REGIONAL` or `null`. | `string` | `"REGIONAL"` | no |
1414
| backup\_configuration | The backup\_configuration settings subblock for the database setings | <pre>object({<br> binary_log_enabled = bool<br> enabled = bool<br> start_time = string<br> location = string<br> transaction_log_retention_days = string<br> retained_backups = number<br> retention_unit = string<br> })</pre> | <pre>{<br> "binary_log_enabled": false,<br> "enabled": false,<br> "location": null,<br> "retained_backups": null,<br> "retention_unit": null,<br> "start_time": null,<br> "transaction_log_retention_days": null<br>}</pre> | no |
15+
| connector\_enforcement | Force clients to use the connector. See[more details](https://cloud.google.com/sql/docs/mysql/connect-connectors). | `bool` | `false` | no |
1516
| create\_timeout | The optional timout that is applied to limit long database creates. | `string` | `"30m"` | no |
1617
| database\_flags | List of Cloud SQL flags that are applied to the database server. See [more details](https://cloud.google.com/sql/docs/mysql/flags) | <pre>list(object({<br> name = string<br> value = string<br> }))</pre> | `[]` | no |
1718
| database\_version | The database version to use | `string` | n/a | yes |

modules/mysql/main.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ locals {
3232

3333
retained_backups = lookup(var.backup_configuration, "retained_backups", null)
3434
retention_unit = lookup(var.backup_configuration, "retention_unit", null)
35+
36+
// Force the usage of connector_enforcement
37+
connector_enforcement = var.connector_enforcement ? "REQUIRED" : "NOT_REQUIRED"
3538
}
3639

3740
resource "random_id" "suffix" {
@@ -55,6 +58,7 @@ resource "google_sql_database_instance" "default" {
5558
activation_policy = var.activation_policy
5659
availability_type = var.availability_type
5760
deletion_protection_enabled = var.deletion_protection_enabled
61+
connector_enforcement = local.connector_enforcement
5862
dynamic "backup_configuration" {
5963
for_each = [var.backup_configuration]
6064
content {

modules/mysql/metadata.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ spec:
100100
start_time: null
101101
transaction_log_retention_days: null
102102
required: false
103+
- name: connector_enforcement
104+
description: Force the client to use the connector. See [more details](https://cloud.google.com/sql/docs/mysql/connect-connectors)
105+
type: bool
106+
default: false
107+
required: false
103108
- name: create_timeout
104109
description: The optional timout that is applied to limit long database creates.
105110
type: string

modules/mysql/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,3 +389,9 @@ variable "enable_random_password_special" {
389389
type = bool
390390
default = false
391391
}
392+
393+
variable "connector_enforcement" {
394+
description = "Enforce that clients use the connector library"
395+
type = bool
396+
default = false
397+
}

0 commit comments

Comments
 (0)