Last active
April 17, 2023 15:53
-
-
Save holms/0ddad2b3917dcab3661b6416f37986ce to your computer and use it in GitHub Desktop.
terraform azure postgresql flexible server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource "azurerm_postgresql_flexible_server" "mydb" { | |
name = "pbs-northeurope" | |
location = azurerm_resource_group.mycompany.location | |
resource_group_name = azurerm_resource_group.mycompany.name | |
administrator_login = "psqladmin" | |
administrator_password = "mypassword" | |
sku_name = "MO_Standard_E4s_v3" | |
version = "12" | |
storage_mb = 32768 | |
zone = 1 | |
backup_retention_days = 7 | |
lifecycle { | |
ignore_changes = [zone, high_availability.0.standby_availability_zone] | |
} | |
} | |
resource "azurerm_postgresql_flexible_server_firewall_rule" "mydb_allowall" { | |
name = "allowall" | |
server_id = azurerm_postgresql_flexible_server.mydb.id | |
start_ip_address = "0.0.0.0" | |
end_ip_address = "0.0.0.0" | |
} | |
resource "azurerm_postgresql_flexible_server_database" "mydb" { | |
name = "pbs_storedrequests" | |
server_id = azurerm_postgresql_flexible_server.mydb.id | |
collation = "en_US.utf8" | |
charset = "utf8" | |
depends_on = [azurerm_postgresql_flexible_server_firewall_rule.mydb_allowall] | |
} | |
# POSTGRES CONFIGURATION | |
variable "mydb_config" { | |
description = "PostgreSQL configurations to enable" | |
type = map(string) | |
default = { | |
"require_secure_transport" = "off" | |
"pg_qs.query_capture_mode" = "TOP" | |
"pg_qs.retention_period_in_days" = "2" | |
"pg_qs.store_query_plans" = "on" | |
"pg_qs.max_plan_size" = "7500" | |
"pg_qs.track_utility" = "on" | |
"pgms_wait_sampling.query_capture_mode" = "ALL" | |
"pgbouncer.max_client_conn" = "10000" | |
"pgbouncer.enabled" = "true" | |
"pgbouncer.ignore_startup_parameters" = "extra_float_digits" | |
"pgbouncer.default_pool_size" = "50" | |
"pgbouncer.pool_mode" = "TRANSACTION" | |
"pgbouncer.min_pool_size" = "0" | |
"pgbouncer.query_wait_timeout" = "200" | |
"pgbouncer.server_idle_timeout" = "200" | |
} | |
} | |
resource "azurerm_postgresql_flexible_server_configuration" "mydb_config" { | |
for_each = var.mydb_config | |
name = each.key | |
server_id = azurerm_postgresql_flexible_server.mydb.id | |
value = each.value | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment