Skip to content

Commit

Permalink
feat: make connector enforcement configurable (#439)
Browse files Browse the repository at this point in the history
Co-authored-by: Chris Mague <mague@google.com>
Co-authored-by: Michael Nahkies <michael@nahkies.co.nz>
  • Loading branch information
3 people authored Mar 15, 2023
1 parent 0ceb0ed commit 2df794b
Show file tree
Hide file tree
Showing 4 changed files with 16 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 @@ -12,6 +12,7 @@ Note: CloudSQL provides [disk autoresize](https://cloud.google.com/sql/docs/mysq
| 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 |
| availability\_type | The availability type for the master instance. Can be either `REGIONAL` or `null`. | `string` | `"REGIONAL"` | no |
| 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 |
| connector\_enforcement | Force clients to use the connector. See[more details](https://cloud.google.com/sql/docs/mysql/connect-connectors). | `bool` | `false` | no |
| create\_timeout | The optional timout that is applied to limit long database creates. | `string` | `"30m"` | no |
| 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 |
| database\_version | The database version to use | `string` | n/a | yes |
Expand Down
4 changes: 4 additions & 0 deletions modules/mysql/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ locals {

retained_backups = lookup(var.backup_configuration, "retained_backups", null)
retention_unit = lookup(var.backup_configuration, "retention_unit", null)

// Force the usage of connector_enforcement
connector_enforcement = var.connector_enforcement ? "REQUIRED" : "NOT_REQUIRED"
}

resource "random_id" "suffix" {
Expand All @@ -55,6 +58,7 @@ resource "google_sql_database_instance" "default" {
activation_policy = var.activation_policy
availability_type = var.availability_type
deletion_protection_enabled = var.deletion_protection_enabled
connector_enforcement = local.connector_enforcement
dynamic "backup_configuration" {
for_each = [var.backup_configuration]
content {
Expand Down
5 changes: 5 additions & 0 deletions modules/mysql/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ spec:
start_time: null
transaction_log_retention_days: null
required: false
- name: connector_enforcement
description: Force the client to use the connector. See [more details](https://cloud.google.com/sql/docs/mysql/connect-connectors)
type: bool
default: false
required: false
- name: create_timeout
description: The optional timout that is applied to limit long database creates.
type: string
Expand Down
6 changes: 6 additions & 0 deletions modules/mysql/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -389,3 +389,9 @@ variable "enable_random_password_special" {
type = bool
default = false
}

variable "connector_enforcement" {
description = "Enforce that clients use the connector library"
type = bool
default = false
}

0 comments on commit 2df794b

Please sign in to comment.