Azure Database SQL Server Virtual Network Rule
This page shows how to write Terraform and Azure Resource Manager for Database SQL Server Virtual Network Rule and write them securely.
azurerm_mssql_virtual_network_rule (Terraform)
The SQL Server Virtual Network Rule in Database can be configured in Terraform with the resource name azurerm_mssql_virtual_network_rule
. The following sections describe 7 examples of how to use the resource and its parameters.
Example Usage from GitHub
resource "azurerm_mssql_virtual_network_rule" "sql_network_rule_services" {
name = "servicesSubnet"
server_id = azurerm_mssql_server.sql_server.id
subnet_id = azurerm_subnet.subnet_services.id
ignore_missing_vnet_service_endpoint = false
}
resource "azurerm_mssql_virtual_network_rule" "network_rule" {
name = azurecaf_name.sql_network_rule.result
server_id = azurerm_mssql_server.database.id
subnet_id = var.subnet_id
}
resource "azurerm_mssql_virtual_network_rule" "network_rules" {
for_each = try(var.settings.network_rules, {})
name = each.value.name
server_id = azurerm_mssql_server.mssql.id
subnet_id = try(each.value.subnet_id, var.vnets[try(var.client_config.landingzone_key, each.value.lz_key)][each.value.vnet_key].subnets[each.value.subnet_key].id)
resource "azurerm_mssql_virtual_network_rule" "network_rules" {
for_each = try(var.settings.network_rules, {})
name = each.value.name
server_id = azurerm_mssql_server.mssql.id
subnet_id = try(each.value.subnet_id, var.vnets[try(var.client_config.landingzone_key, each.value.lz_key)][each.value.vnet_key].subnets[each.value.subnet_key].id)
resource "azurerm_mssql_virtual_network_rule" "db" {
name = "tf-db-vnet"
server_id = azurerm_mssql_server.db.id
subnet_id = azurerm_subnet.vnet.id
}
resource "azurerm_mssql_virtual_network_rule" "network_rules" {
for_each = try(var.settings.network_rules, {})
name = each.value.name
server_id = azurerm_mssql_server.mssql.id
subnet_id = try(each.value.subnet_id, var.vnets[try(var.client_config.landingzone_key, each.value.lz_key)][each.value.vnet_key].subnets[each.value.subnet_key].id)
resource "azurerm_mssql_virtual_network_rule" "network_rules" {
for_each = try(var.settings.network_rules, {})
name = each.value.name
server_id = azurerm_mssql_server.mssql.id
subnet_id = coalesce(
Parameters
-
id
optional computed - string -
ignore_missing_vnet_service_endpoint
optional - bool -
name
required - string -
server_id
required - string -
subnet_id
required - string -
timeouts
single block
Explanation in Terraform Registry
Allows you to manage rules for allowing traffic between an Azure SQL server and a subnet of a virtual network.
Tips: Best Practices for The Other Azure Database Resources
In addition to the azurerm_mariadb_firewall_rule, Azure Database has the other resources that should be configured for security reasons. Please check some examples of those resources and precautions.
azurerm_mariadb_firewall_rule
Ensure database firewalls do not permit public access
It is better to restrict IP address ranges that can access the database by firewall rules. If both start_ip_address and end_ip_address are set to 0.0.0.0, it blocks connections from the Internet and accepts connections from all Azure datacenter IP addresses.
azurerm_mariadb_server
Ensure that access to Azure SQL Database is restricted
It is better to disable public access to the database to avoid unwilling communications with unknown services if not required.
azurerm_mssql_database_extended_auditing_policy
Ensure to configure retention periods of database auditing to enough duration
It is better to configure retention periods of database auditing to enough duration. It would be better to set greater than at least 90 days.
azurerm_mssql_server
Ensure to enable auditing on Azure SQL databases
It is better to enable auditing on Azure SQL databases. It helps you maintain regulatory compliance, monitor the activities indicating unexpected incidents or suspected security violations.
azurerm_mssql_server_security_alert_policy
Ensure to configure at least one email address for threat alerts
It is better to configure at least one email address for threat alerts. SQL Server is able to send alerts for threat detection via emails and it could support us to notice the incident on time.
azurerm_mysql_firewall_rule
Ensure database firewalls do not permit public access
It is better to restrict IP address ranges that can access the database by firewall rules. If both start_ip_address and end_ip_address are set to 0.0.0.0, it blocks connections from the Internet and accepts connections from all Azure datacenter IP addresses.
azurerm_mysql_server
Ensure to disable public access to database
It is better to disable public access to the database to avoid unwilling communications with unknown services if not required.
azurerm_postgresql_firewall_rule
Ensure database firewalls do not permit public access
It is better to restrict IP address ranges that can access the database by firewall rules. If both start_ip_address and end_ip_address are set to 0.0.0.0, it blocks connections from the Internet and accepts connections from all Azure datacenter IP addresses.
azurerm_postgresql_server
Ensure to disable public access to database
It is better to disable public access to the database to avoid unwilling communications with unknown services if not required.
azurerm_sql_firewall_rule
Ensure database firewalls do not permit public access
It is better to restrict IP address ranges that can access the database by firewall rules. If both start_ip_address and end_ip_address are set to 0.0.0.0, it blocks connections from the Internet and accepts connections from all Azure datacenter IP addresses.
azurerm_sql_server
Ensure to enable auditing on Azure SQL databases
It is better to enable auditing on Azure SQL databases. It helps you maintain regulatory compliance, monitor the activities indicating unexpected incidents or suspected security violations.
Microsoft.Sql/servers/virtualNetworkRules (Azure Resource Manager)
The servers/virtualNetworkRules in Microsoft.Sql can be configured in Azure Resource Manager with the resource name Microsoft.Sql/servers/virtualNetworkRules
. The following sections describe how to use the resource and its parameters.
Example Usage from GitHub
"type": "Microsoft.Sql/servers/virtualNetworkRules",
"properties": {
"ignoreMissingVnetServiceEndpoint": false,
"state": "Ready",
"virtualNetworkSubnetId": "/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/Default/providers/Microsoft.Network/virtualNetworks/testvnet/subnets/testsubnet"
}
"type": "Microsoft.Sql/servers/virtualNetworkRules",
"properties": {
"ignoreMissingVnetServiceEndpoint": false,
"state": "Ready",
"virtualNetworkSubnetId": "/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/Default/providers/Microsoft.Network/virtualNetworks/testvnet/subnets/testsubnet"
}
"type": "Microsoft.Sql/servers/virtualNetworkRules",
"properties": {
"ignoreMissingVnetServiceEndpoint": false,
"virtualNetworkSubnetId": "/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/Default/providers/Microsoft.Network/virtualNetworks/testvnet/subnets/testsubnet"
}
}
"type": "Microsoft.Sql/servers/virtualNetworkRules",
"properties": {
"ignoreMissingVnetServiceEndpoint": false,
"state": "Ready",
"virtualNetworkSubnetId": "/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/Default/providers/Microsoft.Network/virtualNetworks/testvnet/subnets/testsubnet"
}
"type": "Microsoft.Sql/servers/virtualNetworkRules",
"properties": {
"ignoreMissingVnetServiceEndpoint": false,
"state": "Ready",
"virtualNetworkSubnetId": "/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/Default/providers/Microsoft.Network/virtualNetworks/testvnet/subnets/testsubnet"
}
"type": "Microsoft.Sql/servers/virtualNetworkRules",
"properties": {
"ignoreMissingVnetServiceEndpoint": false,
"virtualNetworkSubnetId": "/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/Default/providers/Microsoft.Network/virtualNetworks/testvnet/subnets/testsubnet"
}
}
"type": "Microsoft.Sql/servers/virtualNetworkRules",
"properties": {
"ignoreMissingVnetServiceEndpoint": false,
"virtualNetworkSubnetId": "/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/Default/providers/Microsoft.Network/virtualNetworks/testvnet/subnets/testsubnet"
}
}
"type": "Microsoft.Sql/servers/virtualNetworkRules",
"properties": {
"ignoreMissingVnetServiceEndpoint": false,
"virtualNetworkSubnetId": "/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/Default/providers/Microsoft.Network/virtualNetworks/testvnet/subnets/testsubnet"
}
}
"type": "Microsoft.Sql/servers/virtualNetworkRules",
"name": "[concat(parameters('sqlServerName'), '/', parameters('sqlVnetRuleName'))]",
"apiVersion": "2015-05-01-preview",
"scale": null,
"properties": {
"virtualNetworkSubnetId": "[resourceId(parameters('vnetResourceGroupName'), 'Microsoft.Network/virtualNetworks/subnets', parameters('vnetName'), parameters('sqlSubnetName'))]"
"type": "Microsoft.Sql/servers/virtualNetworkRules",
"properties": {
"ignoreMissingVnetServiceEndpoint": false,
"state": "Ready",
"virtualNetworkSubnetId": "/subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/Default/providers/Microsoft.Network/virtualNetworks/testvnet/subnets/testsubnet"
}
Frequently asked questions
What is Azure Database SQL Server Virtual Network Rule?
Azure Database SQL Server Virtual Network Rule is a resource for Database of Microsoft Azure. Settings can be wrote in Terraform.
Where can I find the example code for the Azure Database SQL Server Virtual Network Rule?
For Terraform, the Tricentis/Tosca.CloudTemplates, microsoft/NubesGen and anmoltoppo/Terraform source code examples are useful. See the Terraform Example section for further details.
For Azure Resource Manager, the shawns1/shawns1CI, sanjaypavan/OldAzure-Rest-API and shawns1/shawns1CI source code examples are useful. See the Azure Resource Manager Example section for further details.