Skip to content

Commit 7ea753b

Browse files
committed
feat: Firewall rules
1 parent f831a55 commit 7ea753b

File tree

4 files changed

+61
-9
lines changed

4 files changed

+61
-9
lines changed

README.md

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ No modules.
3535
The following resources are used by this module:
3636

3737
- [azurerm_mysql_database.db](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/mysql_database) (resource)
38+
- [azurerm_mysql_firewall_rule.firewall](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/mysql_firewall_rule) (resource)
3839
- [azurerm_mysql_server.server](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/mysql_server) (resource)
3940

4041
## Required Inputs
@@ -89,6 +90,22 @@ Type: `string`
8990

9091
Default: `"mysqladmin"`
9192

93+
### allowed\_ips
94+
95+
Description: A hash of permissions to access the database server by ip. The hash key is the name suffix and each value
96+
has a start and an end value.
97+
98+
Type:
99+
100+
```hcl
101+
object({
102+
start = string,
103+
end = string
104+
})
105+
```
106+
107+
Default: `[]`
108+
92109
### backup\_retention\_days
93110

94111
Description: Number of days to keep backups
@@ -99,15 +116,15 @@ Default: `7`
99116

100117
### database\_host\_sku
101118

102-
Description: n/a
119+
Description: SKU for the database server to use
103120

104121
Type: `string`
105122

106-
Default: `"GP_Gen5_1"`
123+
Default: `"GP_Gen5_2"`
107124

108125
### database\_storage
109126

110-
Description: n/a
127+
Description: Required database storage (in MB)
111128

112129
Type: `string`
113130

@@ -121,6 +138,14 @@ Type: `string`
121138

122139
Default: `"8.0"`
123140

141+
### public\_access
142+
143+
Description: Wether to allow public access to the database server
144+
145+
Type: `bool`
146+
147+
Default: `false`
148+
124149
### suffix
125150

126151
Description: Naming suffix to allow multiple instances of this module

firewall.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
resource "azurerm_mysql_firewall_rule" "firewall" {
2+
for_each = var.allowed_ips
3+
start_ip_address = each.value.start
4+
end_ip_address = each.value.end
5+
name = "${var.project}${var.stage}dbfw${each.key}"
6+
resource_group_name = var.resource_group
7+
server_name = azurerm_mysql_server.server.name
8+
}

main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ resource "azurerm_mysql_server" "server" {
1414
backup_retention_days = var.backup_retention_days
1515
geo_redundant_backup_enabled = false
1616
infrastructure_encryption_enabled = true
17-
public_network_access_enabled = false
17+
public_network_access_enabled = var.public_access
1818
ssl_enforcement_enabled = true
1919
}
2020

vars.tf

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ variable "backup_retention_days" {
4545
}
4646
}
4747

48-
4948
variable "admin_login" {
5049
type = string
5150
description = "Admin login"
@@ -58,11 +57,31 @@ variable "admin_password" {
5857
}
5958

6059
variable "database_host_sku" {
61-
type = string
62-
default = "GP_Gen5_2"
60+
type = string
61+
default = "GP_Gen5_2"
62+
description = "SKU for the database server to use"
6363
}
6464

6565
variable "database_storage" {
66-
type = string
67-
default = "5120"
66+
type = string
67+
default = "5120"
68+
description = "Required database storage (in MB)"
69+
}
70+
71+
variable "public_access" {
72+
description = "Wether to allow public access to the database server"
73+
type = bool
74+
default = false
75+
}
76+
77+
variable "allowed_ips" {
78+
description = <<EOF
79+
A hash of permissions to access the database server by ip. The hash key is the name suffix and each value
80+
has a start and an end value.
81+
EOF
82+
type = object({
83+
start = string,
84+
end = string
85+
})
86+
default = []
6887
}

0 commit comments

Comments
 (0)