Skip to content

Commit

Permalink
feat: Support for server parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
dploeger committed Apr 5, 2022
1 parent 3be307e commit 35be60b
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 25 deletions.
39 changes: 27 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ No modules.

The following resources are used by this module:

- [azurerm_postgresql_configuration.params](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/postgresql_configuration) (resource)
- [azurerm_postgresql_database.db](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/postgresql_database) (resource)
- [azurerm_postgresql_firewall_rule.firewall](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/postgresql_firewall_rule) (resource)
- [azurerm_postgresql_flexible_server.server](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/postgresql_flexible_server) (resource)
- [azurerm_postgresql_flexible_server_configuration.params](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/postgresql_flexible_server_configuration) (resource)
- [azurerm_postgresql_flexible_server_configuration.pgbouncer](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/postgresql_flexible_server_configuration) (resource)
- [azurerm_postgresql_flexible_server_database.db](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/postgresql_flexible_server_database) (resource)
- [azurerm_postgresql_flexible_server_firewall_rule.firewall](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/postgresql_flexible_server_firewall_rule) (resource)
Expand All @@ -62,8 +64,9 @@ Type: `string`

### collation

Description: Collation for the databases, which needs to be a valid PostgreSQL collation. Note that Microsoft uses
different notation - f.e. en-US instead of en\_US for the non-flexible server
Description: Collation for the databases, which needs to be a valid PostgreSQL collation. Note that *for single server* Microsoft
uses different notation - f.e. en-US instead of en\_US. *For flexible server*, PostgreSQL standard collations are
used.

Type: `string`

Expand Down Expand Up @@ -130,7 +133,7 @@ Default: `{}`

Description: Enable/Disable auto-growing of the storage. Storage auto-grow prevents your server from running out of storage
and becoming read-only. If storage auto grow is enabled, the storage automatically grows without impacting the
workload
workload (only single server)

Type: `bool`

Expand All @@ -146,23 +149,25 @@ Default: `7`

### database\_flexible

Description: Whethert to use Azure's flexible database service
Description: Whether to use Azure's flexible database service

Type: `bool`

Default: `false`

### database\_host\_sku

Description: SKU for the database server to use
Description: SKU for the database server to use. Single server uses values like GP\_Gen5\_2, flexible server uses Azure
machine SKUs like GP\_Standard\_D2s\_v3

Type: `string`

Default: `"GP_Gen5_2"`

### database\_storage

Description: Required database storage (in MB)
Description: Required database storage (in MB) (flexible server has a defined set of storage sizes to select from.
See https://docs.microsoft.com/de-de/azure/postgresql/flexible-server/concepts-compute-storage#storage

Type: `string`

Expand All @@ -178,27 +183,37 @@ Default: `"11"`

### geo\_redundant\_backup\_enabled

Description: Turn Geo-redundant server backups on/off. This allows you to choose between locally redundant or geo-redundant backup storage in the
General Purpose and Memory Optimized tiers. This is not support for the Basic tier
Description: Turn Geo-redundant server backups on/off. This allows you to choose between locally redundant or geo-redundant
backup storage in the General Purpose and Memory Optimized tiers. This is not support for the Basic tier
(only single server)

Type: `bool`

Default: `false`

### params

Description: A map of server parameters to set

Type: `set(string)`

Default: `{}`

### public\_access

Description: Wether to allow public access to the database server. True will create firewall rules for allowed\_ips and for subnets. False will
create a private endpoint in each given subnet (allowed\_ips will not be used then) - you have to set
enforce\_private\_link\_endpoint\_network\_policies = true on your subnet in this case (see
Description: Wether to allow public access to the database server. True will create firewall rules for allowed\_ips and for
subnets. False will create a private endpoint in each given subnet (allowed\_ips will not be used then) - you have
to set `enforce_private_link_endpoint_network_policies = true` on your subnet in this case (see
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/subnet#enforce_private_link_endpoint_network_policies).
(false currently not supported for flexible server)

Type: `bool`

Default: `false`

### subnets

Description: Maps of prefix => subnet id that has access to the server
Description: Maps of prefix => subnet id that has access to the server (only single server)

Type: `map(string)`

Expand Down
15 changes: 15 additions & 0 deletions params.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,18 @@ resource "azurerm_postgresql_flexible_server_configuration" "pgbouncer" {
value = "true"
server_id = azurerm_postgresql_flexible_server.server.0.id
}

resource "azurerm_postgresql_flexible_server_configuration" "params" {
for_each = var.database_flexible ? var.params : {}
name = each.key
value = each.value
server_id = azurerm_postgresql_flexible_server.server.0.id
}

resource "azurerm_postgresql_configuration" "params" {
for_each = !var.database_flexible ? var.params : {}
name = each.key
value = each.value
resource_group_name = var.resource_group
server_name = local.server_name
}
1 change: 0 additions & 1 deletion server.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ resource "azurerm_postgresql_flexible_server" "server" {
sku_name = var.database_host_sku
storage_mb = var.database_storage
backup_retention_days = var.backup_retention_days

}

locals {
Expand Down
39 changes: 27 additions & 12 deletions vars.tf
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ variable "charset" {
variable "collation" {
type = string
description = <<EOF
Collation for the databases, which needs to be a valid PostgreSQL collation. Note that Microsoft uses
different notation - f.e. en-US instead of en_US for the non-flexible server
Collation for the databases, which needs to be a valid PostgreSQL collation. Note that *for single server* Microsoft
uses different notation - f.e. en-US instead of en_US. *For flexible server*, PostgreSQL standard collations are
used.
EOF
}
variable "backup_retention_days" {
Expand All @@ -60,8 +61,9 @@ variable "backup_retention_days" {
variable "geo_redundant_backup_enabled" {
type = bool
description = <<EOF
Turn Geo-redundant server backups on/off. This allows you to choose between locally redundant or geo-redundant backup storage in the
General Purpose and Memory Optimized tiers. This is not support for the Basic tier
Turn Geo-redundant server backups on/off. This allows you to choose between locally redundant or geo-redundant
backup storage in the General Purpose and Memory Optimized tiers. This is not support for the Basic tier
(only single server)
EOF
default = false
}
Expand All @@ -79,29 +81,36 @@ variable "admin_password" {

variable "database_host_sku" {
type = string
description = "SKU for the database server to use"
description = <<EOF
SKU for the database server to use. Single server uses values like GP_Gen5_2, flexible server uses Azure
machine SKUs like GP_Standard_D2s_v3
EOF
default = "GP_Gen5_2"
}

variable "database_storage" {
type = string
description = "Required database storage (in MB)"
description = <<EOF
Required database storage (in MB) (flexible server has a defined set of storage sizes to select from.
See https://docs.microsoft.com/de-de/azure/postgresql/flexible-server/concepts-compute-storage#storage
EOF
default = "5120"
}

variable "database_flexible" {
type = bool
description = "Whethert to use Azure's flexible database service"
description = "Whether to use Azure's flexible database service"
default = false
}

variable "public_access" {
type = bool
description = <<EOF
Wether to allow public access to the database server. True will create firewall rules for allowed_ips and for subnets. False will
create a private endpoint in each given subnet (allowed_ips will not be used then) - you have to set
enforce_private_link_endpoint_network_policies = true on your subnet in this case (see
Wether to allow public access to the database server. True will create firewall rules for allowed_ips and for
subnets. False will create a private endpoint in each given subnet (allowed_ips will not be used then) - you have
to set `enforce_private_link_endpoint_network_policies = true` on your subnet in this case (see
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/subnet#enforce_private_link_endpoint_network_policies).
(false currently not supported for flexible server)
EOF
default = false
}
Expand All @@ -121,7 +130,7 @@ variable "allowed_ips" {

variable "subnets" {
type = map(string)
description = "Maps of prefix => subnet id that has access to the server"
description = "Maps of prefix => subnet id that has access to the server (only single server)"
default = {}
}

Expand All @@ -130,7 +139,13 @@ variable "autogrow" {
description = <<EOT
Enable/Disable auto-growing of the storage. Storage auto-grow prevents your server from running out of storage
and becoming read-only. If storage auto grow is enabled, the storage automatically grows without impacting the
workload
workload (only single server)
EOT
default = true
}

variable "params" {
type = set(string)
description = "A map of server parameters to set"
default = {}
}

0 comments on commit 35be60b

Please sign in to comment.