Azure Database SQL Server Server Extended Auditing Policy
This page shows how to write Terraform and Azure Resource Manager for Database SQL Server Server Extended Auditing Policy and write them securely.
azurerm_mssql_server_extended_auditing_policy (Terraform)
The SQL Server Server Extended Auditing Policy in Database can be configured in Terraform with the resource name azurerm_mssql_server_extended_auditing_policy
. The following sections describe 8 examples of how to use the resource and its parameters.
Example Usage from GitHub
resource "azurerm_mssql_server_extended_auditing_policy" "eap-primary" {
count = var.AuditStorage == true ? 1 : 0
server_id = azurerm_mssql_server.azsqlserver-primary.id
storage_endpoint = var.AuditAccount == null ? azurerm_storage_account.storageaccount[0].primary_blob_endpoint : data.azurerm_storage_account.auditstorage[0].primary_blob_endpoint
storage_account_access_key = var.AuditAccount == null ? azurerm_storage_account.storageaccount[0].primary_access_key : data.azurerm_storage_account.auditstorage[0].primary_access_key
resource "azurerm_mssql_server_extended_auditing_policy" "mssqlaudit" {
server_id = var.sql_server_id
storage_endpoint = var.sql_audit_endpoint
storage_account_access_key = var.sql_audit_access_key
storage_account_access_key_is_secondary = var.sql_audit_access_key_is_2nd
retention_in_days = var.sql_audit_retention
resource "azurerm_mssql_server_extended_auditing_policy" "mssql" {
count = try(var.settings.extended_auditing_policy, null) == null ? 0 : 1
server_id = azurerm_mssql_server.mssql.id
storage_endpoint = data.azurerm_storage_account.mssql_auditing.0.primary_blob_endpoint
storage_account_access_key = data.azurerm_storage_account.mssql_auditing.0.primary_access_key
resource "azurerm_mssql_server_extended_auditing_policy" "mssqldb" {
count = try(var.settings.extended_auditing_policy, null) == null ? 0 : 1
server_id = var.server_id
storage_endpoint = data.azurerm_storage_account.mssqldb_auditing.0.primary_blob_endpoint
storage_account_access_key = data.azurerm_storage_account.mssqldb_auditing.0.primary_access_key
resource "azurerm_mssql_server_extended_auditing_policy" "sqlserver_ext_auditing_policy" {
server_id = azurerm_mssql_server.sql_server.id
storage_endpoint = azurerm_storage_account.sql_storage_account.primary_blob_endpoint
storage_account_access_key = azurerm_storage_account.sql_storage_account.primary_access_key
storage_account_access_key_is_secondary = false
retention_in_days = var.sql_db_log_retensionIn_days
resource "azurerm_mssql_server_extended_auditing_policy" "sqlserver-auditing-policy" {
server_id = azurerm_mssql_server.sql-server.id
storage_endpoint = azurerm_storage_account.storage-account.primary_blob_endpoint
storage_account_access_key = azurerm_storage_account.storage-account.primary_access_key
storage_account_access_key_is_secondary = false
retention_in_days = 6
resource "azurerm_mssql_server_extended_auditing_policy" "sqllogpolicy" {
server_id = azurerm_sql_server.sqlsvr.id
storage_endpoint = azurerm_storage_account.logstg.primary_blob_endpoint
storage_account_access_key = azurerm_storage_account.logstg.primary_access_key
storage_account_access_key_is_secondary = false
retention_in_days = 6
resource "azurerm_mssql_server_extended_auditing_policy" "example" {
server_id = azurerm_sql_server.example.id
storage_endpoint = azurerm_storage_account.example.primary_blob_endpoint
storage_account_access_key = azurerm_storage_account.example.primary_access_key
storage_account_access_key_is_secondary = false
retention_in_days = 6
Parameters
-
id
optional computed - string -
log_monitoring_enabled
optional - bool -
retention_in_days
optional - number -
server_id
required - string -
storage_account_access_key
optional - string -
storage_account_access_key_is_secondary
optional - bool -
storage_endpoint
optional - string -
timeouts
single block
Explanation in Terraform Registry
Manages a Ms Sql Server Extended Auditing Policy.
NOTE: The Server Extended Auditing Policy Can be set inline here as well as with the mssql_server_extended_auditing_policy resource resource. You can only use one or the other and using both will cause a conflict.
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/extendedAuditingSettings (Azure Resource Manager)
The servers/extendedAuditingSettings in Microsoft.Sql can be configured in Azure Resource Manager with the resource name Microsoft.Sql/servers/extendedAuditingSettings
. The following sections describe how to use the resource and its parameters.
Example Usage from GitHub
"type": "Microsoft.Sql/servers/extendedAuditingSettings",
"properties": {
"state": "Disabled",
"storageEndpoint": "",
"retentionDays": 0,
"auditActionsAndGroups": [],
"type": "Microsoft.Sql/servers/extendedAuditingSettings",
"properties": {
"state": "Disabled",
"storageEndpoint": "",
"retentionDays": 0,
"auditActionsAndGroups": [],
"type": "Microsoft.Sql/servers/extendedAuditingSettings",
"properties": {
"state": "Disabled",
"storageEndpoint": "",
"retentionDays": 0,
"auditActionsAndGroups": [],
"type": "Microsoft.Sql/servers/extendedAuditingSettings",
"properties": {
"state": "Enabled",
"storageEndpoint": "https://mystorage.blob.core.windows.net",
"retentionDays": 6,
"storageAccountSubscriptionId": "00000000-1234-0000-5678-000000000000",
"type": "Microsoft.Sql/servers/extendedAuditingSettings",
"properties": {
"state": "Enabled",
"storageEndpoint": "https://mystorage.blob.core.windows.net",
"retentionDays": 6,
"storageAccountSubscriptionId": "00000000-1234-0000-5678-000000000000",
"type": "Microsoft.Sql/servers/extendedAuditingSettings",
"properties": {
"state": "Enabled",
"storageEndpoint": "https://mystorage.blob.core.windows.net",
"retentionDays": 6,
"storageAccountSubscriptionId": "00000000-1234-0000-5678-000000000000",
"type": "Microsoft.Sql/servers/extendedAuditingSettings",
"properties": {
"state": "Disabled",
"storageEndpoint": "",
"retentionDays": 0,
"auditActionsAndGroups": [],
"type": "Microsoft.Sql/servers/extendedAuditingSettings",
"properties": {
"state": "Disabled",
"storageEndpoint": "",
"retentionDays": 0,
"auditActionsAndGroups": [],
"type": "Microsoft.Sql/servers/extendedAuditingSettings",
"properties": {
"state": "Disabled",
"storageEndpoint": "",
"retentionDays": 0,
"auditActionsAndGroups": [],
"type": "Microsoft.Sql/servers/extendedAuditingSettings",
"properties": {
"state": "Enabled",
"storageEndpoint": "https://mystorage.blob.core.windows.net",
"retentionDays": 6,
"storageAccountSubscriptionId": "00000000-1234-0000-5678-000000000000",
Frequently asked questions
What is Azure Database SQL Server Server Extended Auditing Policy?
Azure Database SQL Server Server Extended Auditing Policy 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 Extended Auditing Policy?
For Terraform, the Indunil-Dayaratne/code-samples123, prancer-io/prancer-terramerra and davesee/terraform-caf-rover-breakout source code examples are useful. See the Terraform Example section for further details.
For Azure Resource Manager, the yuncmsft/swagger, assing/alerts-extension and shawns1/shawns1CI source code examples are useful. See the Azure Resource Manager Example section for further details.