Skip to content

intel/terraform-intel-azure-postgresql-flexible-server

Intel Logo

Intel Optimized Cloud Modules for Terraform

© Copyright 2024, Intel Corporation

Azure PostgreSQL Flexible Server Module

This module can be used to deploy an Intel optimized Azure PostgreSQL Flexible Server instance. Instance selection and PostgreSQL optimization are included by default in the code.

The PostgreSQL Optimizations were based off Intel Xeon Tuning guides

Performance Data

Link

Link

Link

Usage

See examples folder for complete examples.

By default, you will only have to pass three variables

resource_group_name    
db_server_name       
db_password         

variables.tf

variable "db_password" {
  description = "Password for the master database user."
  type        = string
  sensitive   = true
}

main.tf

module "optimized-postgresql-server" {
  source          = "intel/azure-postgresql-flexible-server/intel"
  resource_group_name = "<RESOURCE_GROUP_NAME>"   
  db_server_name      = "<DB_SERVER_NAME>" 
  db_password         = var.db_password
}

Run Terraform

export TF_VAR_db_password ='<USE_A_STRONG_PASSWORD>'

terraform init  
terraform plan
terraform apply 

Considerations

If you see this error message below, this is because the pgsql_server_name already exist and the user needs to provide different unique pgsql_server_name.

Error Message ::: " Server Name: "optimized-pgsql-server"): polling after Create: Code="ServerGroupDropping" Message="Operations on a server group in dropping state are not allowed."

If you see this error message below, this is because the High Avability Mode is disabled for that region. Acceptable regions are Azure Region

Error Message ::: "Server Name: "optimized-postgres-server"): polling after Create: Code="HADisabledForRegion" Message="HA is disabled for region westus2.""

This module further provides the ability to add firewall_ip_range (Usage Example provided above). For more information azurerm_postgresql_flexible_server_firewall_rule

Note that this example creates resources. Run terraform destroy when you don't need these resources.

Requirements

Name Version
terraform >=1.3.0
azurerm ~>3.86

Providers

Name Version
azurerm ~>3.86

Modules

No modules.

Resources

Name Type
azurerm_postgresql_flexible_server.postgres resource
azurerm_postgresql_flexible_server_configuration.postgres resource
azurerm_postgresql_flexible_server_database.postgres resource
azurerm_postgresql_flexible_server_firewall_rule.firewall resource
azurerm_resource_group.rg data source

Inputs

Name Description Type Default Required
db_allocated_storage The max storage allowed for the PostgreSQL Flexible Server. Possible values (MB) are 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, and 16777216. number 2097152 no
db_backup_retention_period The days to retain backups for. Must be between 1 and 35. number 7 no
db_charset Specifies the Charset for the database. string "UTF8" no
db_collation Specifies the Collation for the Database. string "en_US.UTF8" no
db_create_mode The creation mode which can be used to restore or replicate existing servers. string "Default" no
db_create_source_id For creation modes other than Default, the source server ID to use. string null no
db_delegated_subnet_id The ID of the virtual network subnet to create the Flexible Server. string null no
db_engine Database engine for Azure database instance. string "postgres" no
db_engine_version Database engine version for the Azure database instance. string "14" no
db_firewall_rules Map of IP ranges that (if specified) will create firewall rules for the server to access those addresses.
list(object({
name = string
start_ip_address = optional(string)
end_ip_address = optional(string)
}))
[] no
db_geo_backup_enabled 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. When the backups are stored in geo-redundant backup storage, they are not only stored within the region in which your server is hosted, but are also replicated to a paired data center. This provides better protection and ability to restore your server in a different region in the event of a disaster bool false no
db_ha_mode The high availability mode for the Flexible Server. Possibles values are ZoneRedundant. string "ZoneRedundant" no
db_ha_standby_zone Specifies the Availability Zone in which the standby Flexible Server should be located. Possible values are 1, 2 and 3. string "1" no
db_maintenance_day The day of week for maintenance window. string null no
db_maintenance_hour The start hour for maintenance window. string null no
db_maintenance_minute The start minute for maintenance window. string null no
db_name Name of the database that will be created on the flexible instance. If this is specified then a database will be created as a part of the instance provisioning process. string null no
db_parameters Intel Cloud optimizations for Xeon processors
object({
postgres = optional(object({
max_connections = optional(object({
value = optional(string, "256")
}))
shared_buffers = optional(object({
value = optional(string, "6291456")
}))
huge_pages = optional(object({
value = optional(string, "on")
}))
temp_buffers = optional(object({
value = optional(string, "4000")
}))
work_mem = optional(object({
value = optional(string, "2097151")
}))
maintenance_work_mem = optional(object({
value = optional(string, "512000")
}))
autovacuum_work_mem = optional(object({
value = optional(string, "-1")
}))
effective_io_concurrency = optional(object({
value = optional(string, "32")
}))
wal_level = optional(object({
value = optional(string, "logical")
}))
wal_buffers = optional(object({
value = optional(string, "512")
}))
cpu_tuple_cost = optional(object({
value = optional(string, "0.03")
}))
effective_cache_size = optional(object({
value = optional(string, "350000000")
}))
random_page_cost = optional(object({
value = optional(string, "1.1")
}))
checkpoint_timeout = optional(object({
value = optional(string, "3600")
}))
checkpoint_completion_target = optional(object({
value = optional(string, "0.9")
}))
checkpoint_warning = optional(object({
value = optional(string, "1")
}))
log_min_messages = optional(object({
value = optional(string, "error")
}))
log_min_error_statement = optional(object({
value = optional(string, "error")
}))
autovacuum = optional(object({
value = optional(string, "on")
}))
autovacuum_max_workers = optional(object({
value = optional(string, "10")
}))
autovacuum_vacuum_cost_limit = optional(object({
value = optional(string, "3000")
}))
datestyle = optional(object({
value = optional(string, "ISO, DMY")
}))
lc_monetary = optional(object({
value = optional(string, "en_US.utf-8")
}))
lc_numeric = optional(object({
value = optional(string, "en_US.utf-8")
}))
default_text_search_config = optional(object({
value = optional(string, "pg_catalog.english")
}))
max_locks_per_transaction = optional(object({
value = optional(string, "64")
}))
max_wal_senders = optional(object({
value = optional(string, "5")
}))
min_wal_size = optional(object({
value = optional(string, "8192")
}))
max_wal_size = optional(object({
value = optional(string, "65536")
}))
}))
# This parameter is READ-Only in Azure Portal and defaults to ON
# "synchronous_commit" = "on",

# Below set of PostgreSQL are recommended on the Xeon Tunning Guide but are not currently not supported by Azure PostgreSQL flexible server
# "max_stack_depth" = 7,
# "dynamic_shared_memory_type" = "posix",
# "max_files_per_process" = 4000,
# "max_pred_locks_per_transaction" = 64,
# "archive_mode" = "off",
# "lc_time" = "en_US.UTF-8",
# "lc_messages" = "en_US.UTF-8",
})
{
"postgres": {
"autovacuum": {},
"autovacuum_max_workers": {},
"autovacuum_vacuum_cost_limit": {},
"autovacuum_work_mem": {},
"checkpoint_completion_target": {},
"checkpoint_timeout": {},
"checkpoint_warning": {},
"cpu_tuple_cost": {},
"datestyle": {},
"default_text_search_config": {},
"effective_cache_size": {},
"effective_io_concurrency": {},
"huge_pages": {},
"lc_monetary": {},
"lc_numeric": {},
"log_min_error_statement": {},
"log_min_messages": {},
"maintenance_work_mem": {},
"max_connections": {},
"max_locks_per_transaction": {},
"max_wal_senders": {},
"max_wal_size": {},
"min_wal_size": {},
"random_page_cost": {},
"shared_buffers": {},
"temp_buffers": {},
"wal_buffers": {},
"wal_level": {},
"work_mem": {}
}
}
no
db_password Password for the master database user. string n/a yes
db_private_dns_zone_id The ID of the private DNS zone to create the Flexible Server. string null no
db_restore_time When create_mode is PointInTimeRestore, specifies the point in time to restore from creation_source_server_id. It should be provided in RFC3339 format, e.g. 2013-11-08T22:00:40Z. string null no
db_server_name Name of the server that will be created. string n/a yes
db_server_sku Instance SKU, see comments above for guidance string "MO_Standard_E8ds_v4" no
db_timeouts Map of timeouts that can be adjusted when executing the module. This allows you to customize how long certain operations are allowed to take before being considered to have failed.
object({
create = optional(string, null)
delete = optional(string, null)
update = optional(string, null)
read = optional(string, null)
})
{
"db_timeouts": {}
}
no
db_username Username for the master database user. string "pgadmin" no
db_zone Specifies the Availability Zone in which this Flexible Server should be located. Possible values are 1, 2 and 3. string "2" no
resource_group_name Existing Resource Group where resource will be created. string n/a yes
tags Tags to apply to the Database Server map(string) {} no

Outputs

Name Description
db_allocated_storage Storage allocated to the database instance.
db_backup_retention Number of configured backups to keep for the database instance.
db_charset The Charset configured on the database.
db_collation The Collation configured on the database.
db_create_mode The creation mode that was configured on the instance.
db_create_source_id For creation modes other than Default, the source server ID to use.
db_delegated_subnet_id The ID of the virtual network subnet to create the MySQL Flexible Server.
db_engine_version_actual Running engine version of the database (full version number)
db_firewall_rules Database Firewall Rules.
db_ha_mode The high availability mode for the MySQL Flexible Server.
db_ha_standby_zone Specifies the Availability Zone in which the standby Flexible Server should be located.
db_hostname Database instance fully qualified domain name.
db_id Database instance ID.
db_location Database instance location.
db_maintenance_window_day Maintainence window for the database instance.
db_maintenance_window_hour Maintainence window for the database instance.
db_maintenance_window_minute Maintainence window for the database instance.
db_name Name of the database that has been provisioned on the database instance.
db_password Database instance master password.
db_private_dns_zone_id The ID of the private DNS zone that the instance will use.
db_resource_group_name Resource Group where the database instance resides.
db_restore_time Specifies the point in time to restore from creation_source_server_id.
db_server_name Database instance hostname.
db_server_sku Instance SKU in use for the database instance that was created.
db_username Database instance master username.
db_zone Zone where the database instance was deployed.

About

Intel Cloud Optimization Module - Azure PostgreSQL Flexible Server

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages