azurerm_virtual_network

Manages a virtual network including any configured subnets. Each subnet can optionally be configured with a security group to be associated with the subnet.

Example Usage

resource "azurerm_resource_group" "example" {
  name     = "example-resources"
  location = "West Europe"
}

resource "azurerm_network_security_group" "example" {
  name                = "example-security-group"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name
}

resource "azurerm_virtual_network" "example" {
  name                = "example-network"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name
  address_space       = ["10.0.0.0/16"]
  dns_servers         = ["10.0.0.4", "10.0.0.5"]

  subnet {
    name           = "subnet1"
    address_prefix = "10.0.1.0/24"
  }

  subnet {
    name           = "subnet2"
    address_prefix = "10.0.2.0/24"
    security_group = azurerm_network_security_group.example.id
  }

  tags = {
    environment = "Production"
  }
}

Argument Reference

The following arguments are supported:



A ddos_protection_plan block supports the following:


A encryption block supports the following:


The subnet block supports:

Attributes Reference

In addition to the Arguments listed above - the following Attributes are exported:


The subnet block exports:

Timeouts

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

Import

Virtual Networks can be imported using the resource id, e.g.

terraform import azurerm_virtual_network.exampleNetwork /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/Microsoft.Network/virtualNetworks/myvnet1