Azure Database SQL Server Virtual Machine
This page shows how to write Terraform and Azure Resource Manager for Database SQL Server Virtual Machine and write them securely.
azurerm_mssql_virtual_machine (Terraform)
The SQL Server Virtual Machine in Database can be configured in Terraform with the resource name azurerm_mssql_virtual_machine. The following sections describe 9 examples of how to use the resource and its parameters.
Example Usage from GitHub
resource "azurerm_mssql_virtual_machine" "example" {
virtual_machine_id = azurerm_windows_virtual_machine.database.id
sql_license_type = "PAYG"
r_services_enabled = true
sql_connectivity_port = 1433
sql_connectivity_type = "PRIVATE"
resource "azurerm_mssql_virtual_machine" "mssql_virtual_machine" {
virtual_machine_id = var.virtual_machine_id
sql_license_type = "PAYG"
r_services_enabled = false
sql_connectivity_port = 1433
sql_connectivity_type = "PUBLIC"
resource "azurerm_mssql_virtual_machine" "sqldb1-win-db" {
virtual_machine_id = azurerm_windows_virtual_machine.sqldb1-win.id
sql_license_type = "PAYG"
sql_connectivity_port = 1433
sql_connectivity_type = "PRIVATE"
sql_connectivity_update_password = var.db_admin_pass
resource "azurerm_mssql_virtual_machine" "mssql_on_vm" {
virtual_machine_id = var.virtual_machine_id
sql_license_type = var.sql_license_type
r_services_enabled = var.r_services_enabled
sql_connectivity_port = var.sql_connectivity_port
sql_connectivity_type = var.sql_connectivity_type
resource "azurerm_mssql_virtual_machine" "this" {
r_services_enabled = var.r_services_enabled
sql_connectivity_port = var.sql_connectivity_port
sql_connectivity_type = var.sql_connectivity_type
sql_connectivity_update_password = var.sql_connectivity_update_password
sql_connectivity_update_username = var.sql_connectivity_update_username
resource "azurerm_mssql_virtual_machine" "named_test_resource" {
virtual_machine_id = azurerm_virtual_machine.named_test_resource.id
sql_license_type = "PAYG"
r_services_enabled = true
sql_connectivity_port = 1433
sql_connectivity_type = "PRIVATE"
resource "azurerm_mssql_virtual_machine" "demo" {
virtual_machine_id = azurerm_virtual_machine.demo.id
sql_license_type = "PAYG"
r_services_enabled = true
sql_connectivity_port = 1433
sql_connectivity_type = "PUBLIC"
resource "azurerm_mssql_virtual_machine" "mssql_vm01" {
virtual_machine_id = azurerm_windows_virtual_machine.vm01.id
sql_license_type = "PAYG"
r_services_enabled = true
sql_connectivity_port = 1433
sql_connectivity_type = "PRIVATE"
resource "azurerm_mssql_virtual_machine" "sqlvm" {
virtual_machine_id = azurerm_virtual_machine.sqlvm.id
sql_license_type = "PAYG"
r_services_enabled = true
sql_connectivity_port = 1433
sql_connectivity_type = "PRIVATE"
Parameters
-
idoptional computed - string -
r_services_enabledoptional - bool -
sql_connectivity_portoptional - number -
sql_connectivity_typeoptional - string -
sql_connectivity_update_passwordoptional - string -
sql_connectivity_update_usernameoptional - string -
sql_license_typerequired - string -
tagsoptional - map from string to string -
virtual_machine_idrequired - string -
auto_backuplist block-
encryption_enabledoptional - bool -
encryption_passwordoptional - string -
retention_period_in_daysrequired - number -
storage_account_access_keyrequired - string -
storage_blob_endpointrequired - string -
system_databases_backup_enabledoptional - bool -
manual_schedulelist block-
full_backup_frequencyrequired - string -
full_backup_start_hourrequired - number -
full_backup_window_in_hoursrequired - number -
log_backup_frequency_in_minutesrequired - number
-
-
-
auto_patchinglist block-
day_of_weekrequired - string -
maintenance_window_duration_in_minutesrequired - number -
maintenance_window_starting_hourrequired - number
-
-
key_vault_credentiallist block-
key_vault_urlrequired - string -
namerequired - string -
service_principal_namerequired - string -
service_principal_secretrequired - string
-
-
storage_configurationlist block-
disk_typerequired - string -
storage_workload_typerequired - string -
data_settingslist block-
default_file_pathrequired - string -
lunsrequired - list of number
-
-
log_settingslist block-
default_file_pathrequired - string -
lunsrequired - list of number
-
-
temp_db_settingslist block-
default_file_pathrequired - string -
lunsrequired - list of number
-
-
-
timeoutssingle block
Explanation in Terraform Registry
Manages a Microsoft SQL Virtual Machine
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.SqlVirtualMachine/sqlVirtualMachines (Azure Resource Manager)
The sqlVirtualMachines in Microsoft.SqlVirtualMachine can be configured in Azure Resource Manager with the resource name Microsoft.SqlVirtualMachine/sqlVirtualMachines. The following sections describe how to use the resource and its parameters.
Example Usage from GitHub
{
"contentVersion": "1.0.0.0",
"parameters": {
"workbookDisplayName": {
"type": "string",
{
"contentVersion": "1.0.0.0",
"parameters": {
"workbookDisplayName": {
"type": "string",
{
"contentVersion": "1.0.0.0",
"parameters": {
"workbookDisplayName": {
"type": "string",
{
"contentVersion": "1.0.0.0",
"parameters": {
"workbookDisplayName": {
"type": "string",
Frequently asked questions
What is Azure Database SQL Server Virtual Machine?
Azure Database SQL Server Virtual Machine 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 Machine?
For Terraform, the Shiv4y/terraform_code, jeromev66/jvr_tf_example and tdtheautomator/terraform-azure-2tier source code examples are useful. See the Terraform Example section for further details.
For Azure Resource Manager, the scautomation/Azure-Inventory-Workbook, rb-cloud-guru/Azure_Dashboard and ryanmrestivo/cloud-security-research-and-governance source code examples are useful. See the Azure Resource Manager Example section for further details.