Skip to content

Commit

Permalink
feat: config connector_enforcement in postgres (#500)
Browse files Browse the repository at this point in the history
Signed-off-by: Edvin Norling <edvin.norling@kognic.com>
Co-authored-by: Awais Malik <awmalik@google.com>
  • Loading branch information
NissesSenap and g-awmalik committed Aug 23, 2023
1 parent 88309f6 commit 5789b54
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions modules/mssql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ The following dependency must be available for SQL Server module:
| 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 |
| 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 |
| 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 |
| connector\_enforcement | Enforce that clients use the connector library | `bool` | `false` | no |
| create\_timeout | The optional timeout that is applied to limit long database creates. | `string` | `"30m"` | no |
| 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 |
| 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 |
Expand Down
7 changes: 5 additions & 2 deletions modules/mssql/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ locals {
databases = { for db in var.additional_databases : db.name => db }
users = { for u in var.additional_users : u.name => u }

retained_backups = lookup(var.backup_configuration, "retained_backups", null)
retention_unit = lookup(var.backup_configuration, "retention_unit", null)
retained_backups = lookup(var.backup_configuration, "retained_backups", null)
retention_unit = lookup(var.backup_configuration, "retention_unit", null)
connector_enforcement = var.connector_enforcement ? "REQUIRED" : "NOT_REQUIRED"
}

resource "random_id" "suffix" {
Expand Down Expand Up @@ -56,6 +57,8 @@ 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.enabled ? [var.backup_configuration] : []
content {
Expand Down
6 changes: 6 additions & 0 deletions modules/mssql/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,12 @@ variable "deletion_protection" {
default = true
}

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

variable "time_zone" {
description = "The time zone for SQL instance."
type = string
Expand Down
1 change: 1 addition & 0 deletions modules/postgresql/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> }))</pre> | `[]` | no |
| 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 |
| 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 |
| connector\_enforcement | Enforce that clients use the connector library | `bool` | `false` | no |
| create\_timeout | The optional timout that is applied to limit long database creates. | `string` | `"30m"` | no |
| 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 |
| 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 |
Expand Down
4 changes: 4 additions & 0 deletions modules/postgresql/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,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 @@ -62,6 +65,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]
Expand Down
6 changes: 6 additions & 0 deletions modules/postgresql/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -409,3 +409,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 5789b54

Please sign in to comment.