Skip to content

Commit 4b85fac

Browse files
committed
Merge tag 'release-1.3.0-private-link-update' into develop
2 parents 782ee6e + 01168ab commit 4b85fac

File tree

28 files changed

+1601
-1243
lines changed

28 files changed

+1601
-1243
lines changed

README.md

+97-53
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
# Azure SQL Database - Using Failover Groups with Private Endpoints
1+
# Azure SQL Database Terraform Module
22

33
Terraform module to create an MS SQL server with initial database, Azure AD login, Firewall rules, geo-replication using auto-failover groups, Private endpoints, and corresponding private DNS zone. It also supports creating a database with a custom SQL script initialization.
44

55
A single database is the quickest and simplest deployment option for Azure SQL Database. You manage a single database within a SQL Database server, which is inside an Azure resource group in a specified Azure region with this module.
66

77
You can also create a single database in the provisioned or serverless compute tier. A provisioned database is pre-allocated a fixed amount of computing resources, including CPU and memory, and uses one of two purchasing models. This module creates a provisioned database using the vCore-based purchasing model, but you can choose a DTU-based model as well.
88

9-
> **[NOTE]**
10-
> **This module now supports the meta arguments including `providers`, `depends_on`, `count`, and `for_each`.**
11-
129
## Resources supported
1310

1411
* [SQL Servers](https://www.terraform.io/docs/providers/azurerm/r/sql_server.html)
@@ -27,29 +24,32 @@ You can also create a single database in the provisioned or serverless compute t
2724

2825
## Module Usage
2926

30-
```hcl
27+
```terraform
3128
# Azurerm provider configuration
3229
provider "azurerm" {
3330
features {}
3431
}
3532
33+
data "azurerm_log_analytics_workspace" "example" {
34+
name = "loganalytics-we-sharedtest2"
35+
resource_group_name = "rg-shared-westeurope-01"
36+
}
37+
3638
module "mssql-server" {
3739
source = "kumarvna/mssql-db/azurerm"
38-
version = "1.2.0"
40+
version = "1.3.0"
3941
4042
# By default, this module will create a resource group
4143
# proivde a name to use an existing resource group and set the argument
4244
# to `create_resource_group = false` if you want to existing resoruce group.
4345
# If you use existing resrouce group location will be the same as existing RG.
44-
create_resource_group = false
45-
resource_group_name = "rg-shared-westeurope-01"
46-
location = "westeurope"
47-
virtual_network_name = "vnet-shared-hub-westeurope-001"
48-
private_subnet_address_prefix = ["10.1.5.0/29"]
46+
create_resource_group = false
47+
resource_group_name = "rg-shared-westeurope-01"
48+
location = "westeurope"
4949
5050
# SQL Server and Database details
5151
# The valid service objective name for the database include S0, S1, S2, S3, P1, P2, P4, P6, P11
52-
sqlserver_name = "sqldbserver01"
52+
sqlserver_name = "te-sqldbserver01"
5353
database_name = "demomssqldb"
5454
sql_database_edition = "Standard"
5555
sqldb_service_objective_name = "S1"
@@ -67,21 +67,15 @@ module "mssql-server" {
6767
enable_vulnerability_assessment = false
6868
email_addresses_for_alerts = ["[email protected]", "[email protected]"]
6969
70-
# Sql failover group creation. required secondary locaiton input.
71-
enable_failover_group = true
72-
secondary_sql_server_location = "northeurope"
73-
74-
# enabling the Private Endpoints for Sql servers
75-
enable_private_endpoint = true
76-
7770
# AD administrator for an Azure SQL server
7871
# Allows you to set a user or group as the AD administrator for an Azure SQL server
7972
ad_admin_login_name = "[email protected]"
8073
8174
# (Optional) To enable Azure Monitoring for Azure SQL database including audit logs
82-
# log analytic workspace name required
83-
enable_log_monitoring = true
84-
log_analytics_workspace_name = "loganalytics-we-sharedtest2"
75+
# Log Analytic workspace resource id required
76+
# (Optional) Specify `storage_account_id` to save monitoring logs to storage.
77+
enable_log_monitoring = true
78+
log_analytics_workspace_id = data.azurerm_log_analytics_workspace.example.id
8579
8680
# Firewall Rules to allow azure and external clients and specific Ip address/ranges.
8781
enable_firewall_rules = true
@@ -93,22 +87,18 @@ module "mssql-server" {
9387
},
9488
{
9589
name = "desktop-ip"
96-
start_ip_address = "49.204.225.134"
97-
end_ip_address = "49.204.225.134"
90+
start_ip_address = "49.204.225.49"
91+
end_ip_address = "49.204.225.49"
9892
}
9993
]
10094
101-
# Create and initialize a database with custom SQL script
102-
# need sqlcmd utility to run this command
103-
# your desktop public IP must be added to firewall rules to run this command
104-
initialize_sql_script_execution = true
105-
sqldb_init_script_file = "../artifacts/db-init-sample.sql"
106-
107-
# Tags for Azure Resources
95+
# Adding additional TAG's to your Azure resources
10896
tags = {
109-
Terraform = "true"
110-
Environment = "dev"
111-
Owner = "test-user"
97+
ProjectName = "demo-project"
98+
Env = "dev"
99+
100+
BusinessUnit = "CORP"
101+
ServiceClass = "Gold"
112102
}
113103
}
114104
```
@@ -121,16 +111,10 @@ By default, this module generates a strong password for all virtual machines als
121111

122112
### Resource Group
123113

124-
By default, this module will not create a resource group and the name of an existing resource group to be given in an argument `resource_group_name`. If you want to create a new resource group, set the argument `create_resource_group = true`.
114+
By default, this module will create a resource group. To use the existing resource group, set the arguments `create_resource_group = false` and provide a valid resource group name with`resource_group_name`.
125115

126116
*If you are using an existing resource group, then this module uses the same resource group location to create all resources in this module.*
127117

128-
### VNet and Subnets
129-
130-
This module is not going to create a `VNet` and corresponding services. However, this module expect you to provide VPC and Subnet address space for private end points.
131-
132-
Deploy Azure VNet terraform module to overcome with this dependency. The [`terraform-azurerm-vnet`](https://github.com/tietoevry-cloud-infra/terraform-azurerm-vnet) module currently available from [GitHub](https://github.com/tietoevry-cloud-infra/terraform-azurerm-vnet), also aligned with this module.
133-
134118
## Advance usage of module
135119

136120
### `extended_auditing_policy` - Auditing for SQL Database
@@ -179,7 +163,49 @@ Azure Private Endpoint is a network interface that connects you privately and se
179163

180164
With Private Link, Microsoft offering the ability to associate a logical server to a specific private IP address (also known as private endpoint) within the VNet. This module helps to implement Failover Groups using private endpoint for SQL Database instead of the public endpoint thus ensuring that customers can get security benefits that it offers.
181165

182-
Clients can connect to the Private endpoint from the same VNet, peered VNet in same region, or via VNet-to-VNet connection across regions. Additionally, clients can connect from on-premises using ExpressRoute, private peering, or VPN tunneling.
166+
By default, this feature not enabled on this module. To create private link with private endpoints set the variable `enable_private_endpoint` to `true` and provide `virtual_network_name`, `private_subnet_address_prefix` with a valid values. You can also use the existing private DNS zone to create DNS records. To use this feature, set the `existing_private_dns_zone` with a valid existing private DNS zone name.
167+
168+
```terraform
169+
module "mssql-server" {
170+
source = "kumarvna/mssql-db/azurerm"
171+
version = "1.3.0"
172+
173+
# .... omitted
174+
175+
# Creating Private Endpoint requires, VNet name and address prefix to create a subnet
176+
# By default this will create a `privatelink.database.windows.net` DNS zone.
177+
# To use existing private DNS zone specify `existing_private_dns_zone` with valid zone name
178+
enable_private_endpoint = true
179+
virtual_network_name = "vnet-shared-hub-westeurope-001"
180+
private_subnet_address_prefix = ["10.1.5.0/29"]
181+
# existing_private_dns_zone = "demo.example.com"
182+
183+
# ....omitted
184+
185+
}
186+
```
187+
188+
If you want to use eixsting VNet and Subnet to create a private endpoints, set a variable `enable_private_endpoint` to `true` and provide `existing_vnet_id`, `existing_subnet_id` with a valid resource ids. You can also use the existing private DNS zone to create DNS records. To use this feature, set the `existing_private_dns_zone` with a valid existing private DNS zone name.
189+
190+
```terraform
191+
module "mssql-server" {
192+
source = "kumarvna/mssql-db/azurerm"
193+
version = "1.3.0"
194+
195+
# .... omitted
196+
197+
# Creating Private Endpoint requires, VNet name and address prefix to create a subnet
198+
# By default this will create a `privatelink.database.windows.net` DNS zone.
199+
# To use existing private DNS zone specify `existing_private_dns_zone` with valid zone name
200+
enable_private_endpoint = true
201+
existing_vnet_id = data.azurerm_virtual_network.example.id
202+
existing_subnet_id = data.azurerm_subnet.example.id
203+
# existing_private_dns_zone = "demo.example.com"
204+
205+
# ....omitted
206+
207+
}
208+
```
183209

184210
### Create schema and Initialize SQL Database
185211

@@ -189,6 +215,24 @@ This module uses the tool slqcmd as a local provisioner to connect and inject th
189215
190216
Installation of the Microsoft `sqlcmd` utility on [Ubuntu](https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-setup-tools?view=sql-server-ver15#ubuntu) or on [Windows](https://docs.microsoft.com/en-us/sql/tools/sqlcmd-utility?view=sql-server-ver15) found here.
191217

218+
```terraform
219+
module "mssql-server" {
220+
source = "kumarvna/mssql-db/azurerm"
221+
version = "1.3.0"
222+
223+
# .... omitted
224+
225+
# Create and initialize a database with custom SQL script
226+
# need sqlcmd utility to run this command
227+
# your desktop public IP must be added to firewall rules to run this command
228+
initialize_sql_script_execution = true
229+
sqldb_init_script_file = "../artifacts/db-init-sample.sql"
230+
231+
# ....omitted
232+
233+
}
234+
```
235+
192236
## Recommended naming and tagging conventions
193237

194238
Applying tags to your Azure resources, resource groups, and subscriptions to logically organize them into a taxonomy. Each tag consists of a name and a value pair. For example, you can apply the name `Environment` and the value `Production` to all the resources in production.
@@ -225,27 +269,31 @@ Name | Description | Type | Default
225269
`database_name`|The name of the SQL database|string|`""`
226270
`admin_username`|The username of the local administrator used for the SQL Server|string|`"azureadmin"`
227271
`admin_password`|The Password which should be used for the local-administrator on this SQL Server|string|`null`
272+
`random_password_length`|The desired length of random password created by this module|number|`32`
273+
`storage_account_name`|The name of the storage account|string|`null`
228274
`sql_database_edition`|The edition of the database to be created. Valid values are: `Basic`, `Standard`, `Premium`, `DataWarehouse`, `Business`, `BusinessCritical`, `Free`, `GeneralPurpose`, `Hyperscale`, `Premium`, `PremiumRS`, `Standard`, `Stretch`, `System`, `System2`, or `Web`|string|`"Standard"`
229275
`sqldb_service_objective_name`|The service objective name for the database. Valid values depend on edition and location and may include `S0`, `S1`, `S2`, `S3`, `P1`, `P2`, `P4`, `P6`, `P11`|string|`"S1"`
230276
`enable_sql_server_extended_auditing_policy`|Manages Extended Audit policy for SQL servers|string|`"true"`
231277
`enable_database_extended_auditing_policy`|Manages Extended Audit policy for SQL database|string|`"false"`
232278
`enable_threat_detection_policy`|Threat detection policy configuration|string|`"false"`
279+
`enable_log_monitoring`|Enable audit events to Azure Monitor?|string|`false`
233280
`log_retention_days`|Specifies the number of days to retain logs for in the storage account|`number`|`30`
234281
`email_addresses_for_alerts`|Account administrators email for alerts|`list(any)`|`""`
235282
`ad_admin_login_name`|The login name of the principal to set as the server administrator|string|`null`
236283
`enable_firewall_rules`|Manages a Firewall Rule for a MySQL Server|string|`"false"`
237284
`firewall_rules`| list of firewall rules to add SQL servers| `list(object({}))`| `[]`
238285
`enable_failover_group`|Create a failover group of databases on a collection of Azure SQL servers|string| `"false"`
239286
`secondary_sql_server_location`|The location of the secondary SQL server (applicable if Failover groups enabled)|string|`"northeurope"`
240-
`enable_private_endpoint`|Azure Private Endpoint is a network interface that connects you privately and securely to a service powered by Azure Private Link|string|`"false"`
241-
`virtual_network_name` | The name of the virtual network|string|`""`
242-
`private_subnet_address_prefix`|A list of subnets address prefixes inside virtual network| list |`[]`
243287
`initialize_sql_script_execution`|enable sqlcmd tool to connect and create database schema|string| `"false"`
244288
`sqldb_init_script_file`|SQL file to execute via sqlcmd utility to create required database schema |string|`""`
245-
`enable_log_monitoring`|Enable audit events to Azure Monitor?|string|`false`
246-
`storage_account_name`|The name of the storage account name|string|`null`
247-
`log_analytics_workspace_name`|The name of log analytics workspace name|string|`null`
248-
`random_password_length`|The desired length of random password created by this module|number|`24`
289+
`enable_private_endpoint`|Manages a Private Endpoint to Azure Container Registry|string|`false`
290+
`virtual_network_name`|The name of the virtual network for the private endpoint creation. conflicts with `existing_vnet_id`and shouldn't use both.|string|`""`
291+
`private_subnet_address_prefix`|Address prefix of the subnet for private endpoint creation. conflicts with `existing_subnet_id` and shouldn't use both|list(string)|`null`
292+
`existing_vnet_id`|The resoruce id of existing Virtual network for private endpoint creation. Conflicts with `virtual_network_name`and shouldn't use both|string|`null`
293+
`existing_subnet_id`|The resource id of existing subnet for private endpoint creation. Conflicts with `private_subnet_address_prefix` and shouldn't use both|string|`null`
294+
`existing_private_dns_zone`|The name of exisging private DNS zone|string|`null`
295+
`log_analytics_workspace_id`|The id of log analytic workspace to send logs and metrics.|string|`"null"`
296+
`storage_account_id`|The id of storage account to send logs and metrics|string|`"null"`
249297
`Tags`|A map of tags to add to all resources|map|`{}`
250298

251299
## Outputs
@@ -286,7 +334,3 @@ Originally created by [Kumaraswamy Vithanala](mailto:[email protected])
286334
* [Azure SQL Database documentation](https://docs.microsoft.com/en-us/azure/sql-database/)
287335

288336
* [Terraform AzureRM Provider Documentation](https://www.terraform.io/docs/providers/azurerm/index.html)
289-
290-
<a href="https://trackgit.com">
291-
<img src="https://us-central1-trackgit-analytics.cloudfunctions.net/token/ping/ksoy6wbtv96k7qirtaks" alt="trackgit-views" />
292-
</a>

0 commit comments

Comments
 (0)