|
1 | | -# terraform-azurerm-postgresql-db |
| 1 | +# Azure Database for PostgreSQL Terraform Module |
| 2 | + |
| 3 | +Azure Database for MySQL is easy to set up, manage and scale. It automates the management and maintenance of your infrastructure and database server, including routine updates, backups and security. Enjoy maximum control of database management with custom maintenance windows and multiple configuration parameters for fine grained tuning with Flexible Server (Preview). |
| 4 | + |
| 5 | +## Resources are supported |
| 6 | + |
| 7 | +* [MySQL Servers](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/mysql_server) |
| 8 | +* [MySQL Database](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/mysql_database) |
| 9 | +* [MySQL Configuration](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/mysql_configuration) |
| 10 | +* [MySQL Firewall Rules](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/mysql_firewall_rule) |
| 11 | +* [MySQL Active Directory Administrator](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/mysql_active_directory_administrator) |
| 12 | +* [MySQL Customer Managed Key](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/mysql_server_key) |
| 13 | +* [MySQL Virtual Network Rule](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/mysql_virtual_network_rule) |
| 14 | +* [MySQL Diagnostics](https://docs.microsoft.com/en-us/azure/azure-sql/database/metrics-diagnostic-telemetry-logging-streaming-export-configure?tabs=azure-portal) |
| 15 | +* [Private Endpoints](https://www.terraform.io/docs/providers/azurerm/r/private_endpoint.html) |
| 16 | +* [Private DNS zone for `privatelink` A records](https://www.terraform.io/docs/providers/azurerm/r/private_dns_zone.html) |
| 17 | + |
| 18 | +```terraform |
| 19 | +module "postgresql-db" { |
| 20 | + source = "kumarvna/postgresql-db/azurerm" |
| 21 | + version = "1.0.0" |
| 22 | +
|
| 23 | + # By default, this module will create a resource group |
| 24 | + # proivde a name to use an existing resource group and set the argument |
| 25 | + # to `create_resource_group = false` if you want to existing resoruce group. |
| 26 | + # If you use existing resrouce group location will be the same as existing RG. |
| 27 | + create_resource_group = false |
| 28 | + resource_group_name = "rg-shared-westeurope-01" |
| 29 | + location = "westeurope" |
| 30 | +
|
| 31 | + # MySQL Server and Database settings |
| 32 | + postgresql_server_name = "mypostgresdbsrv01" |
| 33 | +
|
| 34 | + postgresql_server_settings = { |
| 35 | + sku_name = "GP_Gen5_8" |
| 36 | + storage_mb = 640000 |
| 37 | + version = "9.6" |
| 38 | + # default admin user `sqladmin` and can be specified as per the choice here |
| 39 | + # by default random password created by this module. required password can be specified here |
| 40 | + admin_username = "postgresadmin" |
| 41 | + admin_password = "H@Sh1CoR3!" |
| 42 | + # Database name, charset and collection arguments |
| 43 | + database_name = "demo-postgres-db" |
| 44 | + charset = "UTF8" |
| 45 | + collation = "English_United States.1252" |
| 46 | + # Storage Profile and other optional arguments |
| 47 | + auto_grow_enabled = true |
| 48 | + backup_retention_days = 7 |
| 49 | + geo_redundant_backup_enabled = true |
| 50 | + public_network_access_enabled = true |
| 51 | + ssl_enforcement_enabled = true |
| 52 | + ssl_minimal_tls_version_enforced = "TLS1_2" |
| 53 | + } |
| 54 | +
|
| 55 | + # PostgreSQL Server Parameters |
| 56 | + # For more information: https://bit.ly/3dbYTtB |
| 57 | + postgresql_configuration = { |
| 58 | + backslash_quote = "on" |
| 59 | + } |
| 60 | +
|
| 61 | + # Use Virtual Network service endpoints and rules for Azure Database for MySQL |
| 62 | + subnet_id = var.subnet_id |
| 63 | +
|
| 64 | + # The URL to a Key Vault custom managed key |
| 65 | + key_vault_key_id = var.key_vault_key_id |
| 66 | +
|
| 67 | + # To enable Azure Defender for database set `enable_threat_detection_policy` to true |
| 68 | + enable_threat_detection_policy = true |
| 69 | + log_retention_days = 30 |
| 70 | + email_addresses_for_alerts = ["user@example.com", "firstname.lastname@example.com"] |
| 71 | +
|
| 72 | + # AD administrator for an Azure MySQL server |
| 73 | + # Allows you to set a user or group as the AD administrator for an Azure SQL server |
| 74 | + ad_admin_login_name = "firstname.lastname@example.com" |
| 75 | +
|
| 76 | + # (Optional) To enable Azure Monitoring for Azure MySQL database |
| 77 | + # (Optional) Specify `storage_account_name` to save monitoring logs to storage. |
| 78 | + //log_analytics_workspace_name = "loganalytics-we-sharedtest2" |
| 79 | +
|
| 80 | + # Firewall Rules to allow azure and external clients and specific Ip address/ranges. |
| 81 | + firewall_rules = { |
| 82 | + access-to-azure = { |
| 83 | + start_ip_address = "0.0.0.0" |
| 84 | + end_ip_address = "0.0.0.0" |
| 85 | + }, |
| 86 | + desktop-ip = { |
| 87 | + start_ip_address = "49.204.228.223" |
| 88 | + end_ip_address = "49.204.228.223" |
| 89 | + } |
| 90 | + } |
| 91 | +
|
| 92 | + # Tags for Azure Resources |
| 93 | + tags = { |
| 94 | + Terraform = "true" |
| 95 | + Environment = "dev" |
| 96 | + Owner = "test-user" |
| 97 | + } |
| 98 | +} |
| 99 | +``` |
0 commit comments