|
1 |
| -# Azure SQL Database Using Failover Groups with Private endpoints |
| 1 | +# Azure SQL Database Terraform Module |
2 | 2 |
|
3 | 3 | Terraform module for Azure to create a MS SQL server with initial database, Azure AD login, Firewall rules, Failover Group, Private endpoint, and corresponding private DNS zone. It also supports creating a database with a custom SQL script initialization.
|
4 | 4 |
|
5 |
| -## Module Usage |
| 5 | +## Module Usage for |
6 | 6 |
|
7 |
| -### Simple Azure SQL single database creation |
8 |
| - |
9 |
| -```hcl |
10 |
| -# Azurerm provider configuration |
11 |
| -provider "azurerm" { |
12 |
| - features {} |
13 |
| -} |
14 |
| -
|
15 |
| -module "mssql-server" { |
16 |
| - source = "kumarvna/mssql-db/azurerm" |
17 |
| - version = "1.2.0" |
18 |
| -
|
19 |
| - # By default, this module will create a resource group |
20 |
| - # proivde a name to use an existing resource group and set the argument |
21 |
| - # to `create_resource_group = false` if you want to existing resoruce group. |
22 |
| - # If you use existing resrouce group location will be the same as existing RG. |
23 |
| - create_resource_group = false |
24 |
| - resource_group_name = "rg-shared-westeurope-01" |
25 |
| - location = "westeurope" |
26 |
| -
|
27 |
| - # SQL Server and Database details |
28 |
| - # The valid service objective name for the database include S0, S1, S2, S3, P1, P2, P4, P6, P11 |
29 |
| - sqlserver_name = "sqldbserver01" |
30 |
| - database_name = "demomssqldb" |
31 |
| - sql_database_edition = "Standard" |
32 |
| - sqldb_service_objective_name = "S1" |
33 |
| -
|
34 |
| - # SQL server extended auditing policy defaults to `true`. |
35 |
| - # To turn off set enable_sql_server_extended_auditing_policy to `false` |
36 |
| - # DB extended auditing policy defaults to `false`. |
37 |
| - # to tun on set the variable `enable_database_extended_auditing_policy` to `true` |
38 |
| - # To enable Azure Defender for database set `enable_threat_detection_policy` to true |
39 |
| - enable_threat_detection_policy = true |
40 |
| - log_retention_days = 30 |
41 |
| -
|
42 |
| - # schedule scan notifications to the subscription administrators |
43 |
| - # Manage Vulnerability Assessment set `enable_vulnerability_assessment` to `true` |
44 |
| - enable_vulnerability_assessment = false |
45 |
| - email_addresses_for_alerts = ["[email protected]", "[email protected]"] |
46 |
| -
|
47 |
| - # AD administrator for an Azure SQL server |
48 |
| - # Allows you to set a user or group as the AD administrator for an Azure SQL server |
49 |
| - ad_admin_login_name = "[email protected]" |
50 |
| -
|
51 |
| - # (Optional) To enable Azure Monitoring for Azure SQL database including audit logs |
52 |
| - # log analytic workspace name required |
53 |
| - enable_log_monitoring = true |
54 |
| - log_analytics_workspace_name = "loganalytics-we-sharedtest2" |
55 |
| -
|
56 |
| - # Firewall Rules to allow azure and external clients and specific Ip address/ranges. |
57 |
| - enable_firewall_rules = true |
58 |
| - firewall_rules = [ |
59 |
| - { |
60 |
| - name = "access-to-azure" |
61 |
| - start_ip_address = "0.0.0.0" |
62 |
| - end_ip_address = "0.0.0.0" |
63 |
| - }, |
64 |
| - { |
65 |
| - name = "desktop-ip" |
66 |
| - start_ip_address = "49.204.225.49" |
67 |
| - end_ip_address = "49.204.225.49" |
68 |
| - } |
69 |
| - ] |
70 |
| -
|
71 |
| - # Create and initialize a database with custom SQL script |
72 |
| - # need sqlcmd utility to run this command |
73 |
| - # your desktop public IP must be added firewall rules to run this command |
74 |
| - initialize_sql_script_execution = true |
75 |
| - sqldb_init_script_file = "../artifacts/db-init-sample.sql" |
76 |
| -
|
77 |
| - # Tags for Azure Resources |
78 |
| - tags = { |
79 |
| - Terraform = "true" |
80 |
| - Environment = "dev" |
81 |
| - Owner = "test-user" |
82 |
| - } |
83 |
| -} |
84 |
| -``` |
85 |
| - |
86 |
| -### Simple Azure SQL single database using private Endpoint |
87 |
| - |
88 |
| -```hcl |
89 |
| -# Azurerm provider configuration |
90 |
| -provider "azurerm" { |
91 |
| - features {} |
92 |
| -} |
93 |
| -
|
94 |
| -module "mssql-server" { |
95 |
| - source = "kumarvna/mssql-db/azurerm" |
96 |
| - version = "1.2.0" |
97 |
| -
|
98 |
| - # By default, this module will create a resource group |
99 |
| - # proivde a name to use an existing resource group and set the argument |
100 |
| - # to `create_resource_group = false` if you want to existing resoruce group. |
101 |
| - # If you use existing resrouce group location will be the same as existing RG. |
102 |
| - create_resource_group = false |
103 |
| - resource_group_name = "rg-shared-westeurope-01" |
104 |
| - location = "westeurope" |
105 |
| - virtual_network_name = "vnet-shared-hub-westeurope-001" |
106 |
| - private_subnet_address_prefix = ["10.1.5.0/29"] |
107 |
| -
|
108 |
| - # SQL Server and Database details |
109 |
| - # The valid service objective name for the database include S0, S1, S2, S3, P1, P2, P4, P6, P11 |
110 |
| - sqlserver_name = "sqldbserver01" |
111 |
| - database_name = "demomssqldb" |
112 |
| - sql_database_edition = "Standard" |
113 |
| - sqldb_service_objective_name = "S1" |
114 |
| -
|
115 |
| - # SQL server extended auditing policy defaults to `true`. |
116 |
| - # To turn off set enable_sql_server_extended_auditing_policy to `false` |
117 |
| - # DB extended auditing policy defaults to `false`. |
118 |
| - # to tun on set the variable `enable_database_extended_auditing_policy` to `true` |
119 |
| - # To enable Azure Defender for database set `enable_threat_detection_policy` to true |
120 |
| - enable_threat_detection_policy = true |
121 |
| - log_retention_days = 30 |
122 |
| -
|
123 |
| - # schedule scan notifications to the subscription administrators |
124 |
| - # Manage Vulnerability Assessment set `enable_vulnerability_assessment` to `true` |
125 |
| - enable_vulnerability_assessment = false |
126 |
| - email_addresses_for_alerts = ["[email protected]", "[email protected]"] |
127 |
| -
|
128 |
| - # enabling the Private Endpoints for Sql servers |
129 |
| - enable_private_endpoint = true |
130 |
| -
|
131 |
| - # AD administrator for an Azure SQL server |
132 |
| - # Allows you to set a user or group as the AD administrator for an Azure SQL server |
133 |
| - ad_admin_login_name = "[email protected]" |
134 |
| -
|
135 |
| - # (Optional) To enable Azure Monitoring for Azure SQL database including audit logs |
136 |
| - # log analytic workspace name required |
137 |
| - enable_log_monitoring = true |
138 |
| - log_analytics_workspace_name = "loganalytics-we-sharedtest2" |
139 |
| -
|
140 |
| - # Firewall Rules to allow azure and external clients and specific Ip address/ranges. |
141 |
| - enable_firewall_rules = true |
142 |
| - firewall_rules = [ |
143 |
| - { |
144 |
| - name = "access-to-azure" |
145 |
| - start_ip_address = "0.0.0.0" |
146 |
| - end_ip_address = "0.0.0.0" |
147 |
| - }, |
148 |
| - { |
149 |
| - name = "desktop-ip" |
150 |
| - start_ip_address = "49.204.225.134" |
151 |
| - end_ip_address = "49.204.225.134" |
152 |
| - } |
153 |
| - ] |
154 |
| -
|
155 |
| - # Create and initialize a database with custom SQL script |
156 |
| - # need sqlcmd utility to run this command |
157 |
| - # your desktop public IP must be added to firewall rules to run this command |
158 |
| - initialize_sql_script_execution = true |
159 |
| - sqldb_init_script_file = "../artifacts/db-init-sample.sql" |
160 |
| -
|
161 |
| - # Tags for Azure Resources |
162 |
| - tags = { |
163 |
| - Terraform = "true" |
164 |
| - Environment = "dev" |
165 |
| - Owner = "test-user" |
166 |
| - } |
167 |
| -} |
168 |
| -``` |
169 |
| - |
170 |
| -### Azure SQL database creation using geo-replication with auto-failover groups |
171 |
| - |
172 |
| -```hcl |
173 |
| -# Azurerm provider configuration |
174 |
| -provider "azurerm" { |
175 |
| - features {} |
176 |
| -} |
177 |
| -
|
178 |
| -module "mssql-server" { |
179 |
| - source = "kumarvna/mssql-db/azurerm" |
180 |
| - version = "1.2.0" |
181 |
| -
|
182 |
| - # By default, this module will create a resource group |
183 |
| - # proivde a name to use an existing resource group and set the argument |
184 |
| - # to `create_resource_group = false` if you want to existing resoruce group. |
185 |
| - # If you use existing resrouce group location will be the same as existing RG. |
186 |
| - create_resource_group = false |
187 |
| - resource_group_name = "rg-shared-westeurope-01" |
188 |
| - location = "westeurope" |
189 |
| -
|
190 |
| - # SQL Server and Database details |
191 |
| - # The valid service objective name for the database include S0, S1, S2, S3, P1, P2, P4, P6, P11 |
192 |
| - sqlserver_name = "sqldbserver01" |
193 |
| - database_name = "demomssqldb" |
194 |
| - sql_database_edition = "Standard" |
195 |
| - sqldb_service_objective_name = "S1" |
196 |
| -
|
197 |
| - # SQL server extended auditing policy defaults to `true`. |
198 |
| - # To turn off set enable_sql_server_extended_auditing_policy to `false` |
199 |
| - # DB extended auditing policy defaults to `false`. |
200 |
| - # to tun on set the variable `enable_database_extended_auditing_policy` to `true` |
201 |
| - # To enable Azure Defender for database set `enable_threat_detection_policy` to true |
202 |
| - enable_threat_detection_policy = true |
203 |
| - log_retention_days = 30 |
204 |
| -
|
205 |
| - # schedule scan notifications to the subscription administrators |
206 |
| - # Manage Vulnerability Assessment set `enable_vulnerability_assessment` to `true` |
207 |
| - enable_vulnerability_assessment = false |
208 |
| - email_addresses_for_alerts = ["[email protected]", "[email protected]"] |
209 |
| -
|
210 |
| - # AD administrator for an Azure SQL server |
211 |
| - # Allows you to set a user or group as the AD administrator for an Azure SQL server |
212 |
| - ad_admin_login_name = "[email protected]" |
213 |
| -
|
214 |
| - # (Optional) To enable Azure Monitoring for Azure SQL database including audit logs |
215 |
| - # log analytic workspace name required |
216 |
| - enable_log_monitoring = true |
217 |
| - log_analytics_workspace_name = "loganalytics-we-sharedtest2" |
218 |
| -
|
219 |
| - # Sql failover group creation. required secondary locaiton input. |
220 |
| - enable_failover_group = true |
221 |
| - secondary_sql_server_location = "northeurope" |
222 |
| -
|
223 |
| - # Firewall Rules to allow azure and external clients and specific Ip address/ranges. |
224 |
| - enable_firewall_rules = true |
225 |
| - firewall_rules = [ |
226 |
| - { |
227 |
| - name = "access-to-azure" |
228 |
| - start_ip_address = "0.0.0.0" |
229 |
| - end_ip_address = "0.0.0.0" |
230 |
| - }, |
231 |
| - { |
232 |
| - name = "desktop-ip" |
233 |
| - start_ip_address = "49.204.225.134" |
234 |
| - end_ip_address = "49.204.225.134" |
235 |
| - } |
236 |
| - ] |
237 |
| -
|
238 |
| - # Create and initialize a database with custom SQL script |
239 |
| - # need sqlcmd utility to run this command |
240 |
| - # your desktop public IP must be added firewall rules to run this command |
241 |
| - initialize_sql_script_execution = true |
242 |
| - sqldb_init_script_file = "../artifacts/db-init-sample.sql" |
243 |
| -
|
244 |
| - # Tags for Azure Resources |
245 |
| - tags = { |
246 |
| - Terraform = "true" |
247 |
| - Environment = "dev" |
248 |
| - Owner = "test-user" |
249 |
| - } |
250 |
| -} |
251 |
| -``` |
252 |
| - |
253 |
| -### Azure SQL database creation using geo-replication with auto-failover groups and Private Endpoints |
254 |
| - |
255 |
| -```hcl |
256 |
| -# Azurerm provider configuration |
257 |
| -provider "azurerm" { |
258 |
| - features {} |
259 |
| -} |
260 |
| -
|
261 |
| -module "mssql-server" { |
262 |
| - source = "kumarvna/mssql-db/azurerm" |
263 |
| - version = "1.2.0" |
264 |
| -
|
265 |
| - # By default, this module will create a resource group |
266 |
| - # proivde a name to use an existing resource group and set the argument |
267 |
| - # to `create_resource_group = false` if you want to existing resoruce group. |
268 |
| - # If you use existing resrouce group location will be the same as existing RG. |
269 |
| - create_resource_group = false |
270 |
| - resource_group_name = "rg-shared-westeurope-01" |
271 |
| - location = "westeurope" |
272 |
| - virtual_network_name = "vnet-shared-hub-westeurope-001" |
273 |
| - private_subnet_address_prefix = ["10.1.5.0/29"] |
274 |
| -
|
275 |
| - # SQL Server and Database details |
276 |
| - # The valid service objective name for the database include S0, S1, S2, S3, P1, P2, P4, P6, P11 |
277 |
| - sqlserver_name = "sqldbserver01" |
278 |
| - database_name = "demomssqldb" |
279 |
| - sql_database_edition = "Standard" |
280 |
| - sqldb_service_objective_name = "S1" |
281 |
| -
|
282 |
| - # SQL server extended auditing policy defaults to `true`. |
283 |
| - # To turn off set enable_sql_server_extended_auditing_policy to `false` |
284 |
| - # DB extended auditing policy defaults to `false`. |
285 |
| - # to tun on set the variable `enable_database_extended_auditing_policy` to `true` |
286 |
| - # To enable Azure Defender for database set `enable_threat_detection_policy` to true |
287 |
| - enable_threat_detection_policy = true |
288 |
| - log_retention_days = 30 |
289 |
| -
|
290 |
| - # schedule scan notifications to the subscription administrators |
291 |
| - # Manage Vulnerability Assessment set `enable_vulnerability_assessment` to `true` |
292 |
| - enable_vulnerability_assessment = false |
293 |
| - email_addresses_for_alerts = ["[email protected]", "[email protected]"] |
294 |
| -
|
295 |
| - # Sql failover group creation. required secondary locaiton input. |
296 |
| - enable_failover_group = true |
297 |
| - secondary_sql_server_location = "northeurope" |
298 |
| -
|
299 |
| - # enabling the Private Endpoints for Sql servers |
300 |
| - enable_private_endpoint = true |
301 |
| -
|
302 |
| - # AD administrator for an Azure SQL server |
303 |
| - # Allows you to set a user or group as the AD administrator for an Azure SQL server |
304 |
| - ad_admin_login_name = "[email protected]" |
305 |
| -
|
306 |
| - # (Optional) To enable Azure Monitoring for Azure SQL database including audit logs |
307 |
| - # log analytic workspace name required |
308 |
| - enable_log_monitoring = true |
309 |
| - log_analytics_workspace_name = "loganalytics-we-sharedtest2" |
310 |
| -
|
311 |
| - # Firewall Rules to allow azure and external clients and specific Ip address/ranges. |
312 |
| - enable_firewall_rules = true |
313 |
| - firewall_rules = [ |
314 |
| - { |
315 |
| - name = "access-to-azure" |
316 |
| - start_ip_address = "0.0.0.0" |
317 |
| - end_ip_address = "0.0.0.0" |
318 |
| - }, |
319 |
| - { |
320 |
| - name = "desktop-ip" |
321 |
| - start_ip_address = "49.204.225.134" |
322 |
| - end_ip_address = "49.204.225.134" |
323 |
| - } |
324 |
| - ] |
325 |
| -
|
326 |
| - # Create and initialize a database with custom SQL script |
327 |
| - # need sqlcmd utility to run this command |
328 |
| - # your desktop public IP must be added to firewall rules to run this command |
329 |
| - initialize_sql_script_execution = true |
330 |
| - sqldb_init_script_file = "../artifacts/db-init-sample.sql" |
331 |
| -
|
332 |
| - # Tags for Azure Resources |
333 |
| - tags = { |
334 |
| - Terraform = "true" |
335 |
| - Environment = "dev" |
336 |
| - Owner = "test-user" |
337 |
| - } |
338 |
| -} |
339 |
| -``` |
| 7 | +[Simple SQL Single DB Creation](Simple_SQL_Single_Database_creation/) |
| 8 | +[Simple SQL Single DB with Private link Endpoint](Simple_SQL_Single_Database_Using_Private_Endpoint/) |
| 9 | +[SQL DB with Geo-Replication and Auto Failover Groups](SQL_DB_Using_Geo-replication_with_Auto-Failover_Groups/) |
| 10 | +[SQL DB with Geo-Replication, Private Endpoints, and Auto Failover Groups](SQL_DB_Using_Geo-replication_with_Auto-Failover_Groups_and_Private_Endpoints/) |
340 | 11 |
|
341 | 12 | ## Terraform Usage
|
342 | 13 |
|
|
0 commit comments