Skip to content

Commit 5789b54

Browse files
feat: config connector_enforcement in postgres (#500)
Signed-off-by: Edvin Norling <[email protected]> Co-authored-by: Awais Malik <[email protected]>
1 parent 88309f6 commit 5789b54

File tree

6 files changed

+23
-2
lines changed

6 files changed

+23
-2
lines changed

modules/mssql/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ The following dependency must be available for SQL Server module:
1515
| 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> }))</pre> | `[]` | no |
1616
| availability\_type | The availability type for the master instance.This is only used to set up high availability for the MSSQL instance. Can be either `ZONAL` or `REGIONAL`. | `string` | `"ZONAL"` | no |
1717
| backup\_configuration | The database backup configuration. | <pre>object({<br> binary_log_enabled = bool<br> enabled = bool<br> point_in_time_recovery_enabled = bool<br> start_time = string<br> transaction_log_retention_days = string<br> retained_backups = number<br> retention_unit = string<br> })</pre> | <pre>{<br> "binary_log_enabled": null,<br> "enabled": false,<br> "point_in_time_recovery_enabled": null,<br> "retained_backups": null,<br> "retention_unit": null,<br> "start_time": null,<br> "transaction_log_retention_days": null<br>}</pre> | no |
18+
| connector\_enforcement | Enforce that clients use the connector library | `bool` | `false` | no |
1819
| create\_timeout | The optional timeout that is applied to limit long database creates. | `string` | `"30m"` | no |
1920
| database\_flags | The database flags for the master instance. See [more details](https://cloud.google.com/sql/docs/sqlserver/flags) | <pre>list(object({<br> name = string<br> value = string<br> }))</pre> | `[]` | no |
2021
| database\_version | The database version to use: SQLSERVER\_2017\_STANDARD, SQLSERVER\_2017\_ENTERPRISE, SQLSERVER\_2017\_EXPRESS, or SQLSERVER\_2017\_WEB | `string` | `"SQLSERVER_2017_STANDARD"` | no |

modules/mssql/main.tf

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ locals {
2525
databases = { for db in var.additional_databases : db.name => db }
2626
users = { for u in var.additional_users : u.name => u }
2727

28-
retained_backups = lookup(var.backup_configuration, "retained_backups", null)
29-
retention_unit = lookup(var.backup_configuration, "retention_unit", null)
28+
retained_backups = lookup(var.backup_configuration, "retained_backups", null)
29+
retention_unit = lookup(var.backup_configuration, "retention_unit", null)
30+
connector_enforcement = var.connector_enforcement ? "REQUIRED" : "NOT_REQUIRED"
3031
}
3132

3233
resource "random_id" "suffix" {
@@ -56,6 +57,8 @@ resource "google_sql_database_instance" "default" {
5657
activation_policy = var.activation_policy
5758
availability_type = var.availability_type
5859
deletion_protection_enabled = var.deletion_protection_enabled
60+
connector_enforcement = local.connector_enforcement
61+
5962
dynamic "backup_configuration" {
6063
for_each = var.backup_configuration.enabled ? [var.backup_configuration] : []
6164
content {

modules/mssql/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,12 @@ variable "deletion_protection" {
313313
default = true
314314
}
315315

316+
variable "connector_enforcement" {
317+
description = "Enforce that clients use the connector library"
318+
type = bool
319+
default = false
320+
}
321+
316322
variable "time_zone" {
317323
description = "The time zone for SQL instance."
318324
type = string

modules/postgresql/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> }))</pre> | `[]` | no |
1313
| availability\_type | The availability type for the master instance.This is only used to set up high availability for the PostgreSQL instance. Can be either `ZONAL` or `REGIONAL`. | `string` | `"ZONAL"` | no |
1414
| backup\_configuration | The backup\_configuration settings subblock for the database setings | <pre>object({<br> enabled = bool<br> start_time = string<br> location = string<br> point_in_time_recovery_enabled = bool<br> transaction_log_retention_days = string<br> retained_backups = number<br> retention_unit = string<br> })</pre> | <pre>{<br> "enabled": false,<br> "location": null,<br> "point_in_time_recovery_enabled": false,<br> "retained_backups": null,<br> "retention_unit": null,<br> "start_time": null,<br> "transaction_log_retention_days": null<br>}</pre> | no |
15+
| connector\_enforcement | Enforce that clients use the connector library | `bool` | `false` | no |
1516
| create\_timeout | The optional timout that is applied to limit long database creates. | `string` | `"30m"` | no |
1617
| database\_deletion\_policy | The deletion policy for the database. Setting ABANDON allows the resource to be abandoned rather than deleted. This is useful for Postgres, where databases cannot be deleted from the API if there are users other than cloudsqlsuperuser with access. Possible values are: "ABANDON". | `string` | `null` | no |
1718
| database\_flags | The database flags for the master instance. See [more details](https://cloud.google.com/sql/docs/postgres/flags) | <pre>list(object({<br> name = string<br> value = string<br> }))</pre> | `[]` | no |

modules/postgresql/main.tf

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

4040
retained_backups = lookup(var.backup_configuration, "retained_backups", null)
4141
retention_unit = lookup(var.backup_configuration, "retention_unit", null)
42+
43+
// Force the usage of connector_enforcement
44+
connector_enforcement = var.connector_enforcement ? "REQUIRED" : "NOT_REQUIRED"
4245
}
4346

4447
resource "random_id" "suffix" {
@@ -62,6 +65,7 @@ resource "google_sql_database_instance" "default" {
6265
activation_policy = var.activation_policy
6366
availability_type = var.availability_type
6467
deletion_protection_enabled = var.deletion_protection_enabled
68+
connector_enforcement = local.connector_enforcement
6569

6670
dynamic "backup_configuration" {
6771
for_each = [var.backup_configuration]

modules/postgresql/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,3 +409,9 @@ variable "enable_random_password_special" {
409409
type = bool
410410
default = false
411411
}
412+
413+
variable "connector_enforcement" {
414+
description = "Enforce that clients use the connector library"
415+
type = bool
416+
default = false
417+
}

0 commit comments

Comments
 (0)