azurerm_subnet

Manages a subnet. Subnets represent network segments within the IP space defined by the virtual network.

Example Usage

resource "azurerm_resource_group" "test" {
  name     = "acceptanceTestResourceGroup1"
  location = "West US"
}

resource "azurerm_virtual_network" "test" {
  name                = "acceptanceTestVirtualNetwork1"
  address_space       = ["10.0.0.0/16"]
  location            = "${azurerm_resource_group.test.location}"
  resource_group_name = "${azurerm_resource_group.test.name}"
}

resource "azurerm_subnet" "test" {
  name                 = "testsubnet"
  resource_group_name  = "${azurerm_resource_group.test.name}"
  virtual_network_name = "${azurerm_virtual_network.test.name}"
  address_prefix       = "10.0.1.0/24"
}

Argument Reference

The following arguments are supported:

  • name - (Required) The name of the subnet. Changing this forces a new resource to be created.

  • resource_group_name - (Required) The name of the resource group in which to create the subnet. Changing this forces a new resource to be created.

  • virtual_network_name - (Required) The name of the virtual network to which to attach the subnet. Changing this forces a new resource to be created.

  • address_prefix - (Required) The address prefix to use for the subnet.

  • network_security_group_id - (Optional) The ID of the Network Security Group to associate with the subnet.

  • route_table_id - (Optional) The ID of the Route Table to associate with the subnet.

  • service_endpoints - (Optional) The list of Service endpoints to associate with the subnet. Possible values include: Microsoft.Storage, Microsoft.Sql.

Attributes Reference

The following attributes are exported:

Import

Subnets can be imported using the resource id, e.g.

terraform import azurerm_subnet.testSubnet /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/Microsoft.Network/virtualNetworks/myvnet1/subnets/mysubnet1

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