Skip to content

azurermSqlVirtualNetworkRule

Allows you to add, update, or remove an Azure SQL server to a subnet of a virtual network.

-> Note: The azurermSqlVirtualNetworkRule resource is deprecated in version 3.0 of the AzureRM provider and will be removed in version 4.0. Please use the azurermMssqlVirtualNetworkRule resource instead.

Example Usage

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as azurerm from "./.gen/providers/azurerm";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: azurerm.
For a more precise conversion please use the --provider flag in convert.*/
const azurermResourceGroupExample = new azurerm.resourceGroup.ResourceGroup(
  this,
  "example",
  {
    location: "West Europe",
    name: "example-sql-server-vnet-rule",
  }
);
const azurermSqlServerSqlserver = new azurerm.sqlServer.SqlServer(
  this,
  "sqlserver",
  {
    administrator_login: "4dm1n157r470r",
    administrator_login_password: "4-v3ry-53cr37-p455w0rd",
    location: azurermResourceGroupExample.location,
    name: "uniqueazuresqlserver",
    resource_group_name: azurermResourceGroupExample.name,
    version: "12.0",
  }
);
const azurermVirtualNetworkVnet = new azurerm.virtualNetwork.VirtualNetwork(
  this,
  "vnet",
  {
    address_space: ["10.7.29.0/29"],
    location: azurermResourceGroupExample.location,
    name: "example-vnet",
    resource_group_name: azurermResourceGroupExample.name,
  }
);
const azurermSubnetSubnet = new azurerm.subnet.Subnet(this, "subnet", {
  address_prefixes: ["10.7.29.0/29"],
  name: "example-subnet",
  resource_group_name: azurermResourceGroupExample.name,
  service_endpoints: ["Microsoft.Sql"],
  virtual_network_name: azurermVirtualNetworkVnet.name,
});
new azurerm.sqlVirtualNetworkRule.SqlVirtualNetworkRule(this, "sqlvnetrule", {
  name: "sql-vnet-rule",
  resource_group_name: azurermResourceGroupExample.name,
  server_name: azurermSqlServerSqlserver.name,
  subnet_id: azurermSubnetSubnet.id,
});

Argument Reference

The following arguments are supported:

  • name - (Required) The name of the SQL virtual network rule. Changing this forces a new resource to be created. Cannot be empty and must only contain alphanumeric characters and hyphens. Cannot start with a number, and cannot start or end with a hyphen.

\~> NOTE: name must be between 1-64 characters long and must satisfy all of the requirements below:

  1. Contains only alphanumeric and hyphen characters
  2. Cannot start with a number or hyphen
  3. Cannot end with a hyphen

  4. resourceGroupName - (Required) The name of the resource group where the SQL server resides. Changing this forces a new resource to be created.

  5. serverName - (Required) The name of the SQL Server to which this SQL virtual network rule will be applied to. Changing this forces a new resource to be created.

  6. subnetId - (Required) The ID of the subnet that the SQL server will be connected to.

  7. ignoreMissingVnetServiceEndpoint - (Optional) Create the virtual network rule before the subnet has the virtual network service endpoint enabled. The default value is false.

\~> NOTE: If ignoreMissingVnetServiceEndpoint is false, and the target subnet does not contain the microsoftSql endpoint in the serviceEndpoints array, the deployment will fail when it tries to create the SQL virtual network rule.

Attributes Reference

The following attributes are exported:

  • id - The ID of the SQL virtual network rule.

Timeouts

The timeouts block allows you to specify timeouts for certain actions:

  • create - (Defaults to 30 minutes) Used when creating the SQL Virtual Network Rule.
  • update - (Defaults to 30 minutes) Used when updating the SQL Virtual Network Rule.
  • read - (Defaults to 5 minutes) Used when retrieving the SQL Virtual Network Rule.
  • delete - (Defaults to 30 minutes) Used when deleting the SQL Virtual Network Rule.

Import

SQL Virtual Network Rules can be imported using the resourceId, e.g.

terraform import azurerm_sql_virtual_network_rule.rule1 /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myresourcegroup/providers/Microsoft.Sql/servers/myserver/virtualNetworkRules/vnetrulename