Azure Database PostgreSQL Virtual Network Rule
This page shows how to write Terraform and Azure Resource Manager for Database PostgreSQL Virtual Network Rule and write them securely.
azurerm_postgresql_virtual_network_rule (Terraform)
The PostgreSQL Virtual Network Rule in Database can be configured in Terraform with the resource name azurerm_postgresql_virtual_network_rule
. The following sections describe 10 examples of how to use the resource and its parameters.
Example Usage from GitHub
resource "azurerm_postgresql_virtual_network_rule" "azure_postgres_vnr" {
name = "postgresql-vnet-rule"
resource_group_name = azurerm_resource_group.workload_webapp.name
server_name = azurerm_postgresql_server.django-db.name
subnet_id = azurerm_subnet.postgres-subnet.id
ignore_missing_vnet_service_endpoint = true
resource "azurerm_postgresql_virtual_network_rule" "demo-database-subnet-vnet-rule" {
name = "mypostgressql-vnet-rule"
resource_group_name = azurerm_resource_group.local_resource_group.name
server_name = azurerm_postgresql_server.demo.name
subnet_id = azurerm_subnet.local_subnet_2.id
}
resource "azurerm_postgresql_virtual_network_rule" "postgresql_vnet_rules" {
for_each = try(var.settings.postgresql_vnet_rules, {})
name = each.value.name
resource_group_name = var.resource_group_name
server_name = azurerm_postgresql_server.postgresql.name
subnet_id = var.subnet_id
resource "azurerm_postgresql_virtual_network_rule" "postgresql_vnet_rules" {
for_each = try(var.settings.postgresql_vnet_rules, {})
name = each.value.name
resource_group_name = var.resource_group_name
server_name = azurerm_postgresql_server.postgresql.name
subnet_id = var.subnet_id
resource "azurerm_postgresql_virtual_network_rule" "projcore_vnet_rule" {
# name = format("%s-%s", azurerm_postgresql_server.app_postgres.name, "vnet-rule")
name = "worker"
resource_group_name = var.app_rg_name
server_name = azurerm_postgresql_server.app_postgres.name
subnet_id = var.projcore_sn_worker_id #"/subscriptions/8655985a-2f87-44d7-a541-0be9a8c2779d/resourceGroups/s118d01-ProjectCore/providers/Microsoft.Network/virtualNetworks/s118d01-ProjectCore-wkrvn/subnets/worker"
resource "azurerm_postgresql_virtual_network_rule" "default" {
count = var.postgres_sql_enabled ? 1 : 0
name = var.environment_name
resource_group_name = azurerm_resource_group.cluster.name
server_name = azurerm_postgresql_server.default[count.index].name
resource "azurerm_postgresql_virtual_network_rule" "postgresql_vnet_rules" {
for_each = try(var.settings.postgresql_vnet_rules, {})
name = each.value.name
resource_group_name = var.resource_group_name
server_name = azurerm_postgresql_server.postgresql.name
subnet_id = var.subnet_id
resource "azurerm_postgresql_virtual_network_rule" "postgres" {
name = "postgresql-vnet-rule"
resource_group_name = azurerm_resource_group.wms.name
server_name = azurerm_postgresql_server.main.name
subnet_id = azurerm_subnet.databases.id
ignore_missing_vnet_service_endpoint = true
resource "azurerm_postgresql_virtual_network_rule" "pg_rule" {
name = "postgresql-vnet-rule"
resource_group_name = data.azurerm_resource_group.rg.name
server_name = azurerm_postgresql_server.care.name
subnet_id = azurerm_subnet.postgres-subnet.id
ignore_missing_vnet_service_endpoint = true
resource "azurerm_postgresql_virtual_network_rule" "this" {
name = "allow-aks"
resource_group_name = azurerm_postgresql_server.this.resource_group_name
server_name = azurerm_postgresql_server.this.name
subnet_id = azurerm_subnet.aks_pods_subnet.id
ignore_missing_vnet_service_endpoint = true
Parameters
-
id
optional computed - string -
ignore_missing_vnet_service_endpoint
optional - bool -
name
required - string -
resource_group_name
required - string -
server_name
required - string -
subnet_id
required - string -
timeouts
single block
Explanation in Terraform Registry
Manages a PostgreSQL Virtual Network Rule. -> NOTE: PostgreSQL Virtual Network Rules can only be used with SKU Tiers of
GeneralPurpose
orMemoryOptimized
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.DBforPostgreSQL/servers/virtualNetworkRules (Azure Resource Manager)
The servers/virtualNetworkRules in Microsoft.DBforPostgreSQL can be configured in Azure Resource Manager with the resource name Microsoft.DBforPostgreSQL/servers/virtualNetworkRules
. The following sections describe how to use the resource and its parameters.
Example Usage from GitHub
An example could not be found in GitHub.
Frequently asked questions
What is Azure Database PostgreSQL Virtual Network Rule?
Azure Database PostgreSQL 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 PostgreSQL Virtual Network Rule?
For Terraform, the gu9/DjangoappAzure, MrDede06/Demo_DevOps and davesee/terraform-caf-rover-breakout source code examples are useful. See the Terraform Example section for further details.