From a48ff98d67cc5ca688ba3692a3feb949117a54b3 Mon Sep 17 00:00:00 2001 From: Aris van Ommeren Date: Wed, 27 Jan 2021 15:33:18 +0100 Subject: [PATCH 1/2] Function App Regional VNet Integration documented and tested --- ..._network_swift_connection_resource_test.go | 88 +++++++++++++++++++ ...ual_network_swift_connection.html.markdown | 72 ++++++++++++++- website/docs/r/function_app.html.markdown | 3 + 3 files changed, 160 insertions(+), 3 deletions(-) diff --git a/azurerm/internal/services/web/app_service_virtual_network_swift_connection_resource_test.go b/azurerm/internal/services/web/app_service_virtual_network_swift_connection_resource_test.go index 932c34c7b0d1..851e840e7b93 100644 --- a/azurerm/internal/services/web/app_service_virtual_network_swift_connection_resource_test.go +++ b/azurerm/internal/services/web/app_service_virtual_network_swift_connection_resource_test.go @@ -120,6 +120,22 @@ func (t AppServiceVirtualNetworkSwiftConnectionResource) disappears(ctx context. return nil } +func TestAccAppServiceVirtualNetworkSwiftConnection_functionAppBasic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_app_service_virtual_network_swift_connection", "test") + r := AppServiceVirtualNetworkSwiftConnectionResource{} + + data.ResourceTest(t, r, []resource.TestStep{ + { + Config: r.functionAppBasic(data), + Check: resource.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("subnet_id").Exists(), + ), + }, + data.ImportStep(), + }) +} + func (AppServiceVirtualNetworkSwiftConnectionResource) base(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { @@ -228,3 +244,75 @@ resource "azurerm_app_service_virtual_network_swift_connection" "import" { } `, template) } + +func (AppServiceVirtualNetworkSwiftConnectionResource) functionAppBasic(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-appservice-%d" + location = "%s" +} + +resource "azurerm_virtual_network" "test" { + name = "acctest-VNET-%d" + address_space = ["10.0.0.0/16"] + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + lifecycle { + ignore_changes = [ddos_protection_plan] + } +} + +resource "azurerm_subnet" "test" { + name = "acctestSubnet" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name + address_prefix = "10.0.1.0/24" + + delegation { + name = "acctestdelegation" + + service_delegation { + name = "Microsoft.Web/serverFarms" + actions = ["Microsoft.Network/virtualNetworks/subnets/action"] + } + } +} + +resource "azurerm_storage_account" "test" { + name = "acctestsa%s" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + account_tier = "Standard" + account_replication_type = "LRS" +} + +resource "azurerm_app_service_plan" "test" { + name = "acctest-ASP-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + + sku { + tier = "Standard" + size = "S1" + } +} + +resource "azurerm_function_app" "test" { + name = "acctest-FA-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + app_service_plan_id = azurerm_app_service_plan.test.id + storage_account_name = azurerm_storage_account.test.name + storage_account_access_key = azurerm_storage_account.test.primary_access_key +} + +resource "azurerm_app_service_virtual_network_swift_connection" "test" { + app_service_id = azurerm_function_app.test.id + subnet_id = azurerm_subnet.test.id +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomString, data.RandomInteger, data.RandomInteger) +} diff --git a/website/docs/r/app_service_virtual_network_swift_connection.html.markdown b/website/docs/r/app_service_virtual_network_swift_connection.html.markdown index 73aa3a863c87..9da936b1aa76 100644 --- a/website/docs/r/app_service_virtual_network_swift_connection.html.markdown +++ b/website/docs/r/app_service_virtual_network_swift_connection.html.markdown @@ -9,9 +9,11 @@ description: |- # azurerm_app_service_virtual_network_swift_connection -Manages an App Service Virtual Network Association (this is for the [Regional VNet Integration](https://docs.microsoft.com/en-us/azure/app-service/web-sites-integrate-with-vnet#regional-vnet-integration) which is still in preview). +Manages an App Service Virtual Network Association (this is for the [Regional VNet Integration](https://docs.microsoft.com/en-us/azure/app-service/web-sites-integrate-with-vnet#regional-vnet-integration)). -## Example Usage +~> **Note:** This resource can be used for both `azurerm_app_service` and `azurerm_function_app`. + +## Example Usage (with App Service) ```hcl resource "azurerm_resource_group" "example" { @@ -66,11 +68,75 @@ resource "azurerm_app_service_virtual_network_swift_connection" "example" { } ``` +## Example Usage (with Function App) +```hcl +esource "azurerm_resource_group" "example" { + name = "example-resources" + location = "uksouth" +} + +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 +} +``` + ## Argument Reference The following arguments are supported: -* `app_service_id` - (Required) The ID of the App Service to associate to the VNet. Changing this forces a new resource to be created. +* `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`). diff --git a/website/docs/r/function_app.html.markdown b/website/docs/r/function_app.html.markdown index ff5463821c32..3e1431d9cddd 100644 --- a/website/docs/r/function_app.html.markdown +++ b/website/docs/r/function_app.html.markdown @@ -11,6 +11,9 @@ description: |- Manages a Function App. +~> **Note:** To connect an Azure Function App and a subnet within the same region `azurerm_app_service_virtual_network_swift_connection` can be used. +For an example, check the `azurerm_app_service_virtual_network_swift_connection` documentation. + ## Example Usage (with App Service Plan) ```hcl From f34181d4fa54fb38853c981c67dca6917706b9a6 Mon Sep 17 00:00:00 2001 From: Aris van Ommeren Date: Wed, 27 Jan 2021 15:44:14 +0100 Subject: [PATCH 2/2] Docs for one VNet integration per App Svc Plan --- .../app_service_virtual_network_swift_connection.html.markdown | 3 +++ 1 file changed, 3 insertions(+) diff --git a/website/docs/r/app_service_virtual_network_swift_connection.html.markdown b/website/docs/r/app_service_virtual_network_swift_connection.html.markdown index 9da936b1aa76..0c901b275390 100644 --- a/website/docs/r/app_service_virtual_network_swift_connection.html.markdown +++ b/website/docs/r/app_service_virtual_network_swift_connection.html.markdown @@ -13,6 +13,9 @@ Manages an App Service Virtual Network Association (this is for the [Regional VN ~> **Note:** This resource can be used for both `azurerm_app_service` and `azurerm_function_app`. +~> **Note:** There is a hard limit of [one VNet integration per App Service Plan](https://docs.microsoft.com/en-us/azure/app-service/web-sites-integrate-with-vnet#regional-vnet-integration). +Multiple apps in the same App Service plan can use the same VNet. + ## Example Usage (with App Service) ```hcl