Manages an App Service Virtual Network Association for Regional VNet Integration.
This resource can be used for both App Services and Function Apps.
This resource requires the Microsoft.Network/virtualNetworks/subnets/write
permission scope on the subnet.
The resource specific vNet integration requires the Microsoft.Network/virtualNetworks/subnets/join/action
permission scope.
There is a hard limit of one VNet integration per App Service Plan. Multiple apps in the same App Service plan can use the same VNet.
resource "azurerm_resource_group" "example" {
name = "example-resources"
location = "West Europe"
}
resource "azurerm_virtual_network" "example" {
name = "example-virtual-network"
address_space = ["10.0.0.0/16"]
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
}
resource "azurerm_subnet" "example" {
name = "example-subnet"
resource_group_name = azurerm_resource_group.example.name
virtual_network_name = azurerm_virtual_network.example.name
address_prefixes = ["10.0.1.0/24"]
delegation {
name = "example-delegation"
service_delegation {
name = "Microsoft.Web/serverFarms"
actions = ["Microsoft.Network/virtualNetworks/subnets/action"]
}
}
}
resource "azurerm_app_service_plan" "example" {
name = "example-app-service-plan"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
sku {
tier = "Standard"
size = "S1"
}
}
resource "azurerm_app_service" "example" {
name = "example-app-service"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
app_service_plan_id = azurerm_app_service_plan.example.id
}
resource "azurerm_app_service_virtual_network_swift_connection" "example" {
app_service_id = azurerm_app_service.example.id
subnet_id = azurerm_subnet.example.id
}
resource "azurerm_resource_group" "example" {
name = "example-resources"
location = "West Europe"
}
resource "azurerm_virtual_network" "example" {
name = "example-virtual-network"
address_space = ["10.0.0.0/16"]
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
}
resource "azurerm_subnet" "example" {
name = "example-subnet"
resource_group_name = azurerm_resource_group.example.name
virtual_network_name = azurerm_virtual_network.example.name
address_prefixes = ["10.0.1.0/24"]
delegation {
name = "example-delegation"
service_delegation {
name = "Microsoft.Web/serverFarms"
actions = ["Microsoft.Network/virtualNetworks/subnets/action"]
}
}
}
resource "azurerm_app_service_plan" "example" {
name = "example-app-service-plan"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
sku {
tier = "Standard"
size = "S1"
}
}
resource "azurerm_storage_account" "example" {
name = "functionsappexamplesa"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
account_tier = "Standard"
account_replication_type = "LRS"
}
resource "azurerm_function_app" "example" {
name = "example-function-app"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
app_service_plan_id = azurerm_app_service_plan.example.id
storage_account_name = azurerm_storage_account.example.name
storage_account_access_key = azurerm_storage_account.example.primary_access_key
}
resource "azurerm_app_service_virtual_network_swift_connection" "example" {
app_service_id = azurerm_function_app.example.id
subnet_id = azurerm_subnet.example.id
}
The following arguments are supported:
app_service_id
- (Required) The ID of the App Service or Function App to associate to the VNet. Changing this forces a new resource to be created.
subnet_id
- (Required) The ID of the subnet the app service will be associated to (the subnet must have a service_delegation
configured for Microsoft.Web/serverFarms
).
In addition to the Arguments listed above - the following Attributes are exported:
id
- The ID of the App Service Virtual Network AssociationThe timeouts
block allows you to specify timeouts for certain actions:
create
- (Defaults to 30 minutes) Used when creating the App Service Virtual Network Association.update
- (Defaults to 30 minutes) Used when updating the App Service Virtual Network Association.read
- (Defaults to 5 minutes) Used when retrieving the App Service Virtual Network Association.delete
- (Defaults to 30 minutes) Used when deleting the App Service Virtual Network Association.App Service Virtual Network Associations can be imported using the resource id
, e.g.
terraform import azurerm_app_service_virtual_network_swift_connection.myassociation /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/Microsoft.Web/sites/instance1/config/virtualNetwork