|
| 1 | +# Azure Database for PostgreSQL Terraform Module |
| 2 | + |
| 3 | +Azure Database for PostgreSQL Single Server is a fully managed database service with minimal requirements for customizations of database. The single server platform is designed to handle most of the database management functions such as patching, backups, high availability, security with minimal user configuration and control. The architecture is optimized for built-in high availability with 99.99% availability on single availability zone. It supports community version of PostgreSQL 9.5, 9,6, 10, and 11. |
| 4 | + |
| 5 | +## Module Usage |
| 6 | + |
| 7 | +```terraform |
| 8 | +module "postgresql-db" { |
| 9 | + source = "kumarvna/postgresql-db/azurerm" |
| 10 | + version = "1.0.0" |
| 11 | +
|
| 12 | + # By default, this module will create a resource group |
| 13 | + # proivde a name to use an existing resource group and set the argument |
| 14 | + # to `create_resource_group = false` if you want to existing resoruce group. |
| 15 | + # If you use existing resrouce group location will be the same as existing RG. |
| 16 | + create_resource_group = false |
| 17 | + resource_group_name = "rg-shared-westeurope-01" |
| 18 | + location = "westeurope" |
| 19 | +
|
| 20 | + # PostgreSQL Server and Database settings |
| 21 | + postgresql_server_name = "mypostgresdbsrv01" |
| 22 | +
|
| 23 | + postgresql_server_settings = { |
| 24 | + sku_name = "GP_Gen5_8" |
| 25 | + storage_mb = 640000 |
| 26 | + version = "9.6" |
| 27 | + # default admin user `sqladmin` and can be specified as per the choice here |
| 28 | + # by default random password created by this module. required password can be specified here |
| 29 | + admin_username = "postgresadmin" |
| 30 | + admin_password = "H@Sh1CoR3!" |
| 31 | + # Database name, charset and collection arguments |
| 32 | + database_name = "demo-postgres-db" |
| 33 | + charset = "UTF8" |
| 34 | + collation = "English_United States.1252" |
| 35 | + # Storage Profile and other optional arguments |
| 36 | + auto_grow_enabled = true |
| 37 | + backup_retention_days = 7 |
| 38 | + geo_redundant_backup_enabled = true |
| 39 | + public_network_access_enabled = true |
| 40 | + ssl_enforcement_enabled = true |
| 41 | + ssl_minimal_tls_version_enforced = "TLS1_2" |
| 42 | + } |
| 43 | +
|
| 44 | + # PostgreSQL Server Parameters |
| 45 | + # For more information: https://bit.ly/3dbYTtB |
| 46 | + postgresql_configuration = { |
| 47 | + backslash_quote = "on" |
| 48 | + } |
| 49 | +
|
| 50 | + # Use Virtual Network service endpoints and rules for Azure Database for PostgreSQL |
| 51 | + subnet_id = var.subnet_id |
| 52 | +
|
| 53 | + # The URL to a Key Vault custom managed key |
| 54 | + key_vault_key_id = var.key_vault_key_id |
| 55 | +
|
| 56 | + # To enable Azure Defender for database set `enable_threat_detection_policy` to true |
| 57 | + enable_threat_detection_policy = true |
| 58 | + log_retention_days = 30 |
| 59 | + email_addresses_for_alerts = ["user@example.com", "firstname.lastname@example.com"] |
| 60 | +
|
| 61 | + # AD administrator for an Azure database for PostgreSQL |
| 62 | + # Allows you to set a user or group as the AD administrator for PostgreSQL server |
| 63 | + ad_admin_login_name = "firstname.lastname@example.com" |
| 64 | +
|
| 65 | + # (Optional) To enable Azure Monitoring for Azure PostgreSQL database |
| 66 | + # (Optional) Specify `storage_account_name` to save monitoring logs to storage. |
| 67 | + log_analytics_workspace_name = "loganalytics-we-sharedtest2" |
| 68 | +
|
| 69 | + # Firewall Rules to allow azure and external clients and specific Ip address/ranges. |
| 70 | + firewall_rules = { |
| 71 | + access-to-azure = { |
| 72 | + start_ip_address = "0.0.0.0" |
| 73 | + end_ip_address = "0.0.0.0" |
| 74 | + }, |
| 75 | + desktop-ip = { |
| 76 | + start_ip_address = "49.204.228.223" |
| 77 | + end_ip_address = "49.204.228.223" |
| 78 | + } |
| 79 | + } |
| 80 | +
|
| 81 | + # Tags for Azure Resources |
| 82 | + tags = { |
| 83 | + Terraform = "true" |
| 84 | + Environment = "dev" |
| 85 | + Owner = "test-user" |
| 86 | + } |
| 87 | +} |
| 88 | +``` |
| 89 | + |
| 90 | +## Terraform Usage |
| 91 | + |
| 92 | +To run this example you need to execute following Terraform commands |
| 93 | + |
| 94 | +```hcl |
| 95 | +terraform init |
| 96 | +
|
| 97 | +terraform plan |
| 98 | +
|
| 99 | +terraform apply |
| 100 | +``` |
| 101 | + |
| 102 | +Run `terraform destroy` when you don't need these resources. |
0 commit comments