Skip to content

Commit

Permalink
Merge pull request #10333 from aristosvo/function-app-vnet-integratio…
Browse files Browse the repository at this point in the history
…n-docs

[Docs]`function_app` Regional VNet Integration
  • Loading branch information
tombuildsstuff authored Jan 27, 2021
2 parents bd5af86 + f34181d commit b21be5b
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ 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`.

~> **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
resource "azurerm_resource_group" "example" {
Expand Down Expand Up @@ -66,11 +71,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`).

Expand Down
3 changes: 3 additions & 0 deletions website/docs/r/function_app.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b21be5b

Please sign in to comment.