From ce3200bf6673671bd6e641722e6c9d7500043fda Mon Sep 17 00:00:00 2001 From: Francesco Cesareo Date: Mon, 9 Dec 2024 11:22:29 +0100 Subject: [PATCH] chore: [PAGOPA-2395] Added configuration and public_network_access_enabled (#387) * added configuration and public_network_access_enabled * changed count * fix precommit --------- Co-authored-by: mamari90 <130982006+mamari90@users.noreply.github.com> --- postgres_flexible_server_replica/01_main.tf | 19 +++++++++++++++++++ .../04_variables.tf | 12 ++++++++++++ postgres_flexible_server_replica/README.md | 4 ++++ 3 files changed, 35 insertions(+) diff --git a/postgres_flexible_server_replica/01_main.tf b/postgres_flexible_server_replica/01_main.tf index 73cc96cc..569bcf07 100644 --- a/postgres_flexible_server_replica/01_main.tf +++ b/postgres_flexible_server_replica/01_main.tf @@ -20,6 +20,9 @@ resource "azurerm_postgresql_flexible_server" "this" { # private_dns_zobe_id will be required when setting a delegated_subnet_id private_dns_zone_id = var.private_endpoint_enabled ? var.private_dns_zone_id : null + # public_network_access_enabled must be set to false when delegated_subnet_id and private_dns_zone_id have a value. + public_network_access_enabled = var.private_endpoint_enabled ? false : true + sku_name = var.sku_name storage_mb = var.storage_mb source_server_id = var.source_server_id @@ -58,3 +61,19 @@ resource "azurerm_postgresql_flexible_server_configuration" "pgbouncer_enabled" value = "True" } +resource "azurerm_postgresql_flexible_server_configuration" "max_connection" { + count = var.max_connections != null ? 1 : 0 + + name = "max_connections" + server_id = azurerm_postgresql_flexible_server.this.id + value = var.max_connections +} + +resource "azurerm_postgresql_flexible_server_configuration" "max_worker_process" { + count = var.max_worker_process != null ? 1 : 0 + + name = "max_worker_processes" + server_id = azurerm_postgresql_flexible_server.this.id + value = var.max_worker_process +} + diff --git a/postgres_flexible_server_replica/04_variables.tf b/postgres_flexible_server_replica/04_variables.tf index ad7c27b9..d3996480 100644 --- a/postgres_flexible_server_replica/04_variables.tf +++ b/postgres_flexible_server_replica/04_variables.tf @@ -96,6 +96,18 @@ variable "pgbouncer_enabled" { description = "Is PgBouncer enabled into configurations?" } +variable "max_connections" { + type = number + description = "The max number of connections allowed for the PostgreSQL Flexible Server. Possible values depends on sku (https://learn.microsoft.com/en-us/azure/postgresql/flexible-server/concepts-limits#maximum-connections)." + default = null +} + +variable "max_worker_process" { + type = number + description = "The max number of background processes that the PostgreSQL Flexible Server can support. https://learn.microsoft.com/en-us/azure/postgresql/flexible-server/concepts-logical." + default = null +} + # # Monitoring & Alert diff --git a/postgres_flexible_server_replica/README.md b/postgres_flexible_server_replica/README.md index 91cc9a62..9ba17491 100644 --- a/postgres_flexible_server_replica/README.md +++ b/postgres_flexible_server_replica/README.md @@ -163,6 +163,8 @@ No modules. | [azurerm_monitor_metric_alert.main_server_alerts](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/monitor_metric_alert) | resource | | [azurerm_monitor_metric_alert.replica_alerts](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/monitor_metric_alert) | resource | | [azurerm_postgresql_flexible_server.this](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/postgresql_flexible_server) | resource | +| [azurerm_postgresql_flexible_server_configuration.max_connection](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/postgresql_flexible_server_configuration) | resource | +| [azurerm_postgresql_flexible_server_configuration.max_worker_process](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/postgresql_flexible_server_configuration) | resource | | [azurerm_postgresql_flexible_server_configuration.pgbouncer_enabled](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/postgresql_flexible_server_configuration) | resource | | [null_resource.ha_sku_check](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource | | [null_resource.pgbouncer_check](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) | resource | @@ -181,6 +183,8 @@ No modules. | [log\_analytics\_workspace\_id](#input\_log\_analytics\_workspace\_id) | (Optional) Specifies the ID of a Log Analytics Workspace where Diagnostics Data should be sent. | `string` | `null` | no | | [main\_server\_additional\_alerts](#input\_main\_server\_additional\_alerts) | Map of name = criteria objects |
map(object({
# criteria.*.aggregation to be one of [Average Count Minimum Maximum Total]
aggregation = string
metric_name = string
# "Insights.Container/pods" "Insights.Container/nodes"
metric_namespace = string
# criteria.0.operator to be one of [Equals NotEquals GreaterThan GreaterThanOrEqual LessThan LessThanOrEqual]
operator = string
threshold = number
# Possible values are PT1M, PT5M, PT15M, PT30M and PT1H
frequency = string
# Possible values are PT1M, PT5M, PT15M, PT30M, PT1H, PT6H, PT12H and P1D.
window_size = string
# severity: The severity of this Metric Alert. Possible values are 0, 1, 2, 3 and 4. Defaults to 3.
severity = number
}))
| `{}` | no | | [maintenance\_window\_config](#input\_maintenance\_window\_config) | (Optional) Allows the configuration of the maintenance window, if not configured default is Wednesday@2.00am |
object({
day_of_week = number
start_hour = number
start_minute = number
})
|
{
"day_of_week": 3,
"start_hour": 2,
"start_minute": 0
}
| no | +| [max\_connections](#input\_max\_connections) | The max number of connections allowed for the PostgreSQL Flexible Server. Possible values depends on sku (https://learn.microsoft.com/en-us/azure/postgresql/flexible-server/concepts-limits#maximum-connections). | `number` | `null` | no | +| [max\_worker\_process](#input\_max\_worker\_process) | The max number of background processes that the PostgreSQL Flexible Server can support. https://learn.microsoft.com/en-us/azure/postgresql/flexible-server/concepts-logical. | `number` | `null` | no | | [name](#input\_name) | (Required) The name which should be used for this PostgreSQL Flexible Server. Changing this forces a new PostgreSQL Flexible Server to be created. | `string` | n/a | yes | | [pgbouncer\_enabled](#input\_pgbouncer\_enabled) | Is PgBouncer enabled into configurations? | `bool` | `true` | no | | [private\_dns\_zone\_id](#input\_private\_dns\_zone\_id) | (Optional) The ID of the private dns zone to create the PostgreSQL Flexible Server. Changing this forces a new PostgreSQL Flexible Server to be created. | `string` | `null` | no |