Skip to content

Commit 0ea8ba8

Browse files
committed
adding postgres firewall configuration
1 parent 18fb36b commit 0ea8ba8

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

examples/PostgreSQL_Server/main.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ module "postgresql-db" {
2323
admin_username = "postgresadmin"
2424
admin_password = "H@Sh1CoR3!"
2525
# Database name, charset and collection arguments
26-
database_name = "demomy-postgres-db"
26+
database_name = "demo-postgres-db"
2727
charset = "UTF8"
2828
collation = "English_United States.1252"
2929
# Storage Profile and other optional arguments
3030
auto_grow_enabled = true
3131
backup_retention_days = 7
3232
geo_redundant_backup_enabled = true
33-
public_network_access_enabled = false
33+
public_network_access_enabled = true
3434
ssl_enforcement_enabled = true
3535
ssl_minimal_tls_version_enforced = "TLS1_2"
3636
}
@@ -59,7 +59,7 @@ module "postgresql-db" {
5959
# (Optional) To enable Azure Monitoring for Azure MySQL database
6060
# (Optional) Specify `storage_account_name` to save monitoring logs to storage.
6161
log_analytics_workspace_name = "loganalytics-we-sharedtest2"
62-
62+
*/
6363
# Firewall Rules to allow azure and external clients and specific Ip address/ranges.
6464
firewall_rules = {
6565
access-to-azure = {
@@ -71,7 +71,7 @@ module "postgresql-db" {
7171
end_ip_address = "49.204.228.223"
7272
}
7373
}
74-
*/
74+
7575
# Tags for Azure Resources
7676
tags = {
7777
Terraform = "true"

main.tf

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,20 @@ resource "azurerm_postgresql_database" "main" {
133133
#------------------------------------------------------------
134134
resource "azurerm_postgresql_configuration" "main" {
135135
for_each = var.postgresql_configuration != null ? { for k, v in var.postgresql_configuration : k => v if v != null } : {}
136-
name = format("%s", each.key)
136+
name = each.key
137137
resource_group_name = local.resource_group_name
138138
server_name = azurerm_postgresql_server.main.name
139139
value = each.value
140140
}
141141

142+
#------------------------------------------------------------
143+
# Adding Firewall rules for MySQL Server - Default is "false"
144+
#------------------------------------------------------------
145+
resource "azurerm_postgresql_firewall_rule" "main" {
146+
for_each = var.firewall_rules != null ? { for k, v in var.firewall_rules : k => v if v != null } : {}
147+
name = format("%s", each.key)
148+
resource_group_name = local.resource_group_name
149+
server_name = azurerm_postgresql_server.main.name
150+
start_ip_address = each.value["start_ip_address"]
151+
end_ip_address = each.value["end_ip_address"]
152+
}

variables.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,15 @@ variable "postgresql_configuration" {
115115
default = {}
116116
}
117117

118+
variable "firewall_rules" {
119+
description = "Range of IP addresses to allow firewall connections."
120+
type = map(object({
121+
start_ip_address = string
122+
end_ip_address = string
123+
}))
124+
default = null
125+
}
126+
118127
variable "tags" {
119128
description = "A map of tags to add to all resources"
120129
type = map(string)

0 commit comments

Comments
 (0)