Azure Database MariaDB Virtual Network Rule

This page shows how to write Terraform for Database MariaDB Virtual Network Rule and write them securely.

azurerm_mariadb_virtual_network_rule (Terraform)

The MariaDB Virtual Network Rule in Database can be configured in Terraform with the resource name azurerm_mariadb_virtual_network_rule. The following sections describe 9 examples of how to use the resource and its parameters.

Example Usage from GitHub

network_rule.tf#L1
resource "azurerm_mariadb_virtual_network_rule" "mariadb_vnet_rules" {
  for_each            = try(var.settings.mariadb_vnet_rules, {})
  name                = each.value.name
  resource_group_name = var.resource_group_name
  server_name         = azurerm_mariadb_server.mariadb.name
  subnet_id           = var.subnet_id
network_rule.tf#L1
resource "azurerm_mariadb_virtual_network_rule" "mariadb_vnet_rules" {
  for_each            = try(var.settings.mariadb_vnet_rules, {})
  name                = each.value.name
  resource_group_name = var.resource_group_name
  server_name         = azurerm_mariadb_server.mariadb.name
  subnet_id           = var.subnet_id
network_rule.tf#L1
resource "azurerm_mariadb_virtual_network_rule" "mariadb_vnet_rules" {
  for_each            = try(var.settings.mariadb_vnet_rules, {})
  name                = each.value.name
  resource_group_name = var.resource_group_name
  server_name         = azurerm_mariadb_server.mariadb.name
  subnet_id           = var.subnet_id
network_rule.tf#L1
resource "azurerm_mariadb_virtual_network_rule" "mariadb_vnet_rules" {
  for_each            = try(var.settings.mariadb_vnet_rules, {})
  name                = each.value.name
  resource_group_name = var.resource_group_name
  server_name         = azurerm_mariadb_server.mariadb.name
  subnet_id           = var.subnet_id
main.tf#L1
resource "azurerm_mariadb_virtual_network_rule" "example" {
  name                = var.name
  resource_group_name = module.resource_group.azurerm_resource_group.example.name
  server_name         = module.server.azurerm_mariadb_server.example.name
  subnet_id           = module.subnet.azurerm_subnet.example.id
}
maria-vnetrules.tf#L1
resource "azurerm_mariadb_virtual_network_rule" "vnet_rules" {
  for_each            = var.vnet_rules
  name                = each.key
  resource_group_name = var.resource_group_name
  server_name         = azurerm_mariadb_server.mariadb_server.name
  subnet_id           = each.value
main.tf#L7
resource "azurerm_mariadb_virtual_network_rule" "this" {
  name                = var.name
  resource_group_name = var.resource_group_name
  server_name         = var.server_name
  subnet_id           = var.subnet_id

main.tf#L7
resource "azurerm_mariadb_virtual_network_rule" "this" {
  name                = var.name
  resource_group_name = var.resource_group_name
  server_name         = var.server_name
  subnet_id           = var.subnet_id

network_rule.tf#L1
resource "azurerm_mariadb_virtual_network_rule" "mariadb_vnet_rules" {
  for_each            = try(var.settings.mariadb_vnet_rules, {})
  name                = each.value.name
  resource_group_name = var.resource_group_name
  server_name         = azurerm_mariadb_server.mariadb.name
  subnet_id           = var.subnet_id

Review your Terraform file for Azure best practices

Shisho Cloud, our free checker to make sure your Terraform configuration follows best practices, is available (beta).

Parameters

Explanation in Terraform Registry

Manages a MariaDB Virtual Network Rule. -> NOTE: MariaDB Virtual Network Rules can only be used with SKU Tiers of GeneralPurpose or MemoryOptimized

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.

risk-label

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.

risk-label

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.

risk-label

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.

risk-label

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.

risk-label

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.

risk-label

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.

risk-label

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.

risk-label

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.

risk-label

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.

risk-label

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.

risk-label

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.

Review your Azure Database settings

In addition to the above, there are other security points you should be aware of making sure that your .tf files are protected in Shisho Cloud.

Azure Resource Manager Example

Azure Resource Manager code does not have the related resource.

Frequently asked questions

What is Azure Database MariaDB Virtual Network Rule?

Azure Database MariaDB 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 MariaDB Virtual Network Rule?

For Terraform, the anmoltoppo/Terraform, aztfmod/terraform-azurerm-caf and pkhuntia/aztfmod source code examples are useful. See the Terraform Example section for further details.