Skip to content

Commit

Permalink
chore: [PAGOPA-2395] Added configuration and public_network_access_en…
Browse files Browse the repository at this point in the history
…abled (#387)

* added configuration and public_network_access_enabled

* changed count

* fix precommit

---------

Co-authored-by: mamari90 <130982006+mamari90@users.noreply.github.com>
  • Loading branch information
aomegax and mamari90 authored Dec 9, 2024
1 parent f348510 commit ce3200b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
19 changes: 19 additions & 0 deletions postgres_flexible_server_replica/01_main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

12 changes: 12 additions & 0 deletions postgres_flexible_server_replica/04_variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions postgres_flexible_server_replica/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand All @@ -181,6 +183,8 @@ No modules.
| <a name="input_log_analytics_workspace_id"></a> [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 |
| <a name="input_main_server_additional_alerts"></a> [main\_server\_additional\_alerts](#input\_main\_server\_additional\_alerts) | Map of name = criteria objects | <pre>map(object({<br/> # criteria.*.aggregation to be one of [Average Count Minimum Maximum Total]<br/> aggregation = string<br/> metric_name = string<br/> # "Insights.Container/pods" "Insights.Container/nodes"<br/> metric_namespace = string<br/> # criteria.0.operator to be one of [Equals NotEquals GreaterThan GreaterThanOrEqual LessThan LessThanOrEqual]<br/> operator = string<br/> threshold = number<br/> # Possible values are PT1M, PT5M, PT15M, PT30M and PT1H<br/> frequency = string<br/> # Possible values are PT1M, PT5M, PT15M, PT30M, PT1H, PT6H, PT12H and P1D.<br/> window_size = string<br/> # severity: The severity of this Metric Alert. Possible values are 0, 1, 2, 3 and 4. Defaults to 3.<br/> severity = number<br/> }))</pre> | `{}` | no |
| <a name="input_maintenance_window_config"></a> [maintenance\_window\_config](#input\_maintenance\_window\_config) | (Optional) Allows the configuration of the maintenance window, if not configured default is Wednesday@2.00am | <pre>object({<br/> day_of_week = number<br/> start_hour = number<br/> start_minute = number<br/> })</pre> | <pre>{<br/> "day_of_week": 3,<br/> "start_hour": 2,<br/> "start_minute": 0<br/>}</pre> | no |
| <a name="input_max_connections"></a> [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 |
| <a name="input_max_worker_process"></a> [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 |
| <a name="input_name"></a> [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 |
| <a name="input_pgbouncer_enabled"></a> [pgbouncer\_enabled](#input\_pgbouncer\_enabled) | Is PgBouncer enabled into configurations? | `bool` | `true` | no |
| <a name="input_private_dns_zone_id"></a> [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 |
Expand Down

0 comments on commit ce3200b

Please sign in to comment.