|
| 1 | +resource "azurerm_postgresql_server" "server" { |
| 2 | + location = var.location |
| 3 | + name = var.server_name |
| 4 | + resource_group_name = var.resource_group_name |
| 5 | + sku_name = var.sku_name |
| 6 | + ssl_enforcement_enabled = var.ssl_enforcement_enabled |
| 7 | + version = var.server_version |
| 8 | + administrator_login = var.administrator_login |
| 9 | + administrator_login_password = var.administrator_password |
| 10 | + auto_grow_enabled = var.auto_grow_enabled |
| 11 | + backup_retention_days = var.backup_retention_days |
| 12 | + create_mode = var.create_mode |
| 13 | + creation_source_server_id = var.creation_source_server_id |
| 14 | + geo_redundant_backup_enabled = var.geo_redundant_backup_enabled |
| 15 | + infrastructure_encryption_enabled = var.infrastructure_encryption_enabled |
| 16 | + public_network_access_enabled = var.public_network_access_enabled |
| 17 | + ssl_minimal_tls_version_enforced = var.ssl_minimal_tls_version_enforced |
| 18 | + storage_mb = var.storage_mb |
| 19 | + tags = var.tags |
| 20 | + |
| 21 | + dynamic "threat_detection_policy" { |
| 22 | + for_each = nonsensitive(var.threat_detection_policy) != null ? ["threat_detection_policy"] : [] |
| 23 | + |
| 24 | + content { |
| 25 | + disabled_alerts = var.threat_detection_policy.disabled_alerts |
| 26 | + email_account_admins = var.threat_detection_policy.email_account_admins |
| 27 | + email_addresses = var.threat_detection_policy.email_addresses |
| 28 | + enabled = var.threat_detection_policy.enabled |
| 29 | + retention_days = var.threat_detection_policy.retention_days |
| 30 | + storage_account_access_key = var.threat_detection_policy.storage_account_access_key |
| 31 | + storage_endpoint = var.threat_detection_policy.storage_endpoint |
| 32 | + } |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +resource "azurerm_postgresql_database" "dbs" { |
| 37 | + count = length(var.db_names) |
| 38 | + |
| 39 | + charset = var.db_charset |
| 40 | + collation = var.db_collation |
| 41 | + name = var.db_names[count.index] |
| 42 | + resource_group_name = var.resource_group_name |
| 43 | + server_name = azurerm_postgresql_server.server.name |
| 44 | +} |
| 45 | + |
| 46 | +resource "azurerm_postgresql_firewall_rule" "firewall_rules" { |
| 47 | + count = length(var.firewall_rules) |
| 48 | + |
| 49 | + end_ip_address = var.firewall_rules[count.index]["end_ip"] |
| 50 | + name = format("%s%s", var.firewall_rule_prefix, lookup(var.firewall_rules[count.index], "name", count.index)) |
| 51 | + resource_group_name = var.resource_group_name |
| 52 | + server_name = azurerm_postgresql_server.server.name |
| 53 | + start_ip_address = var.firewall_rules[count.index]["start_ip"] |
| 54 | +} |
| 55 | + |
| 56 | +resource "azurerm_postgresql_virtual_network_rule" "vnet_rules" { |
| 57 | + count = length(var.vnet_rules) |
| 58 | + |
| 59 | + name = format("%s%s", var.vnet_rule_name_prefix, lookup(var.vnet_rules[count.index], "name", count.index)) |
| 60 | + resource_group_name = var.resource_group_name |
| 61 | + server_name = azurerm_postgresql_server.server.name |
| 62 | + subnet_id = var.vnet_rules[count.index]["subnet_id"] |
| 63 | +} |
| 64 | + |
| 65 | +resource "azurerm_postgresql_configuration" "db_configs" { |
| 66 | + count = length(keys(var.postgresql_configurations)) |
| 67 | + |
| 68 | + name = element(keys(var.postgresql_configurations), count.index) |
| 69 | + resource_group_name = var.resource_group_name |
| 70 | + server_name = azurerm_postgresql_server.server.name |
| 71 | + value = element(values(var.postgresql_configurations), count.index) |
| 72 | +} |
| 73 | + |
0 commit comments