Azure Database SQL Server Server
This page shows how to write Terraform and Azure Resource Manager for Database SQL Server Server and write them securely.
azurerm_mssql_server (Terraform)
The SQL Server Server in Database can be configured in Terraform with the resource name azurerm_mssql_server
. The following sections describe 10 examples of how to use the resource and its parameters.
Example Usage from GitHub
resource "azurerm_mssql_server" "allowed" {
extended_auditing_policy {
retention_in_days = 90
}
}
resource "azurerm_mssql_server" "allowed" {
extended_auditing_policy {
}
}
resource "azurerm_mssql_server" "denied" {
resource "azurerm_mssql_server" "sqldb_server" {
name = var.name
resource_group_name = var.rg_name
location = var.location
version = "12.0"
resource "azurerm_mssql_server" "this" {
name = var.sql_server_name
resource_group_name = var.resource_group_name
location = var.location
version = "12.0"
administrator_login = "idrugalea"
resource "azurerm_mssql_server" "main" {
name = var.mssql_server_name
resource_group_name = var.rg_name
location = var.rg_location
version = "12.0"
minimum_tls_version = "1.2"
resource "azurerm_mssql_server" "sqlserver" {
name = "taterraformsqlserver"
resource_group_name = azurerm_resource_group.rg.name
location = azurerm_resource_group.rg.location
version = "12.0"
administrator_login = "missadministrator"
resource "azurerm_mssql_server" "MsSqlServer" {
name = var.sql_server_name
resource_group_name = azurerm_resource_group.myRG.name
location = azurerm_resource_group.myRG.location
version = var.sql_version
administrator_login = var.admin_name
resource "azurerm_mssql_server" "failure" {
name = "mssqlserver"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
version = "12.0"
administrator_login = "mradministrator"
resource "azurerm_mssql_server" "this" {
name = var.server_name
administrator_login = random_password.admin_login.result
administrator_login_password = random_password.admin_password.result
location = var.region
resource_group_name = var.resource_group
resource "azurerm_mssql_server" "ss-sqlserver" {
name = var.server_name
resource_group_name = var.resource_group.name
location = var.resource_group.location
version = "12.0"
administrator_login = "llopez7"
Security Best Practices for azurerm_mssql_server
There are 3 settings in azurerm_mssql_server that should be taken care of for security reasons. The following section explain an overview and example code.
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.
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.
Ensure to configure the most modern TLS policies available
It is better to use the latest TLS version for database connections.
Parameters
-
administrator_login
required - string -
administrator_login_password
required - string -
connection_policy
optional - string -
extended_auditing_policy
optional computed - list of object-
log_monitoring_enabled
- bool -
retention_in_days
- number -
storage_account_access_key
- string -
storage_account_access_key_is_secondary
- bool -
storage_endpoint
- string
-
-
fully_qualified_domain_name
optional computed - string -
id
optional computed - string -
location
required - string -
minimum_tls_version
optional - string -
name
required - string -
public_network_access_enabled
optional - bool -
resource_group_name
required - string -
restorable_dropped_database_ids
optional computed - list of string -
tags
optional - map from string to string -
version
required - string -
azuread_administrator
list block-
login_username
required - string -
object_id
required - string -
tenant_id
optional computed - string
-
-
identity
list block-
principal_id
optional computed - string -
tenant_id
optional computed - string -
type
required - string
-
-
timeouts
single block
Explanation in Terraform Registry
Manages a Microsoft SQL Azure Database Server.
Note: All arguments including the administrator login and password will be stored in the raw state as plain-text. Read more about sensitive data in state.
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_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 (Azure Resource Manager)
The servers in Microsoft.Sql can be configured in Azure Resource Manager with the resource name Microsoft.Sql/servers
. The following sections describe how to use the resource and its parameters.
Example Usage from GitHub
"type": "Microsoft.Sql/servers",
"apiVersion": "2019-06-01-preview",
"name": "machinessql",
"location": "eastus",
"kind": "v12.0",
"properties": {
"type": "Microsoft.Sql/servers",
"apiVersion": "2021-02-01-preview",
"name": "sportplannersqlserver",
"location": "westeurope",
"kind": "v12.0",
"properties": {
"type": "Microsoft.Sql/servers",
"apiVersion": "2019-06-01-preview",
"name": "[parameters('servers_se010server_name')]",
"location": "southeastasia",
"kind": "v12.0",
"properties": {
"ResourceType": "Microsoft.Sql/servers",
"Kind": "v12.0",
"ResourceGroupName": "test-rg",
"Location": "region",
"SubscriptionId": "00000000-0000-0000-0000-000000000000",
"Tags": null,
"type": "Microsoft.Sql/servers",
"apiVersion": "2019-06-01-preview",
"name": "machinessql",
"location": "eastus",
"kind": "v12.0",
"properties": {
"type": "Microsoft.Sql/servers",
"apiVersion": "2019-06-01-preview",
"name": "[parameters('servers_machinessql_name')]",
"location": "eastus",
"kind": "v12.0",
"properties": {
"type": "Microsoft.Sql/servers",
"apiVersion": "2019-06-01-preview",
"name": "[parameters('servers_machinessql_name')]",
"location": "eastus",
"kind": "v12.0",
"properties": {
"type": "Microsoft.Sql/servers",
"apiVersion": "2019-06-01-preview",
"name": "[parameters('servers_felyx_sql_name')]",
"location": "westeurope",
"tags": {
"db": "sql"
"type": "Microsoft.Sql/servers",
"apiVersion": "2019-06-01-preview",
"name": "[parameters('servers_serverm13_name')]",
"location": "eastus",
"kind": "v12.0",
"properties": {
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"servers_se010server_name": {
Parameters
apiVersion
required - stringlocation
required - stringResource location.
name
required - stringThe name of the server.
properties
requiredadministratorLogin
optional - stringAdministrator username for the server. Can only be specified when the server is being created (and is required for creation).
administratorLoginPassword
optional - stringThe administrator login password (required for server creation).
version
optional - stringThe version of the server.
tags
optional - stringResource tags.
type
required - string
Frequently asked questions
What is Azure Database SQL Server Server?
Azure Database SQL Server Server 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 Server?
For Terraform, the snyk-labs/infrastructure-as-code-goof, snyk-labs/infrastructure-as-code-goof and badgerowluke/swo-newnextjuly2021 source code examples are useful. See the Terraform Example section for further details.
For Azure Resource Manager, the AmirEliav/Machines, matlij/SportPlanner and deshanjali/ARM-Templates-se010 source code examples are useful. See the Azure Resource Manager Example section for further details.