azurerm_sql_virtual_network_rule

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

Example Usage

resource "azurerm_resource_group" "example" {
  name     = "example-sql-server-vnet-rule"
  location = "West US"
}

resource "azurerm_virtual_network" "vnet" {
  name                = "example-vnet"
  address_space       = ["10.7.29.0/29"]
  location            = "${azurerm_resource_group.example.location}"
  resource_group_name = "${azurerm_resource_group.example.name}"
}

resource "azurerm_subnet" "subnet" {
  name                 = "example-subnet"
  resource_group_name  = "${azurerm_resource_group.example.name}"
  virtual_network_name = "${azurerm_virtual_network.vnet.name}"
  address_prefix       = "10.7.29.0/29"
  service_endpoints    = ["Microsoft.Sql"]
}

resource "azurerm_sql_server" "sqlserver" {
    name                         = "unqiueazuresqlserver"
    resource_group_name          = "${azurerm_resource_group.example.name}"
    location                     = "${azurerm_resource_group.example.location}"
    version                      = "12.0"
    administrator_login          = "4dm1n157r470r"
    administrator_login_password = "4-v3ry-53cr37-p455w0rd"
}

resource "azurerm_sql_virtual_network_rule" "sqlvnetrule" {
  name                = "sql-vnet-rule"
  resource_group_name = "${azurerm_resource_group.example.name}"
  server_name         = "${azurerm_sql_server.sqlserver.name}"
  subnet_id           = "${azurerm_subnet.subnet.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.
  • resource_group_name - (Required) The name of the resource group where the SQL server resides. Changing this forces a new resource to be created.

  • server_name - (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.

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

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

Attributes Reference

The following attributes are exported:

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

Import

SQL Virtual Network Rules can be imported using the resource id, 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

© 2018 HashiCorp
Licensed under the MPL 2.0 License.
https://www.terraform.io/docs/providers/azurerm/r/sql_virtual_network_rule.html