Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add doc and test to support function app slot vnet connetion - "azurerm_app_service_slot_virtual_network_swift_connection" #8111

Merged
merged 3 commits into from
Aug 24, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import (

"github.com/Azure/azure-sdk-for-go/services/web/mgmt/2019-08-01/web"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/locks"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network"
subnetParse "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network/parse"
networkValidate "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network/validate"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/web/parse"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/web/validate"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts"
Expand Down Expand Up @@ -40,12 +40,12 @@ func resourceArmAppServiceSlotVirtualNetworkSwiftConnection() *schema.Resource {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: azure.ValidateResourceID,
ValidateFunc: validate.AppServiceID,
},
"subnet_id": {
Type: schema.TypeString,
Required: true,
ValidateFunc: azure.ValidateResourceID,
ValidateFunc: networkValidate.SubnetID,
},
"slot_name": {
Type: schema.TypeString,
Expand All @@ -62,15 +62,8 @@ func resourceArmAppServiceSlotVirtualNetworkSwiftConnectionCreateUpdate(d *schem
ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d)
defer cancel()

appID, err := parse.AppServiceID(d.Get("app_service_id").(string))
if err != nil {
return fmt.Errorf("Error parsing Azure Resource ID %q", appID)
}

subnetID, err := subnetParse.SubnetID(d.Get("subnet_id").(string))
if err != nil {
return fmt.Errorf("Error parsing Azure Resource ID %q", subnetID)
}
appID, _ := parse.AppServiceID(d.Get("app_service_id").(string))
subnetID, _ := subnetParse.SubnetID(d.Get("subnet_id").(string))
njuCZ marked this conversation as resolved.
Show resolved Hide resolved

resourceGroup := appID.ResourceGroup
name := appID.Name
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
package tests

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance"
)

func TestAccAzureRMFunctionAppSlotVirtualNetworkSwiftConnection_basic(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_app_service_slot_virtual_network_swift_connection", "test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckAzureRMAppServiceSlotVirtualNetworkSwiftConnectionDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMFunctionAppSlotVirtualNetworkSwiftConnection_basic(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMAppServiceSlotVirtualNetworkSwiftConnectionExists(data.ResourceName),
),
},
data.ImportStep(),
},
})
}

func TestAccAzureRMFunctionAppSlotVirtualNetworkSwiftConnection_requiresImport(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_app_service_slot_virtual_network_swift_connection", "test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckAzureRMAppServiceSlotVirtualNetworkSwiftConnectionDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMFunctionAppSlotVirtualNetworkSwiftConnection_basic(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMAppServiceVirtualNetworkSwiftConnectionExists(data.ResourceName),
),
},
data.RequiresImportErrorStep(testAccAzureRMFunctionAppSlotVirtualNetworkSwiftConnection_requiresImport),
},
})
}

func TestAccAzureRMFunctionAppSlotVirtualNetworkSwiftConnection_update(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_app_service_slot_virtual_network_swift_connection", "test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckAzureRMAppServiceSlotVirtualNetworkSwiftConnectionDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMFunctionAppSlotVirtualNetworkSwiftConnection_basic(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMAppServiceSlotVirtualNetworkSwiftConnectionExists(data.ResourceName),
),
},
{
Config: testAccAzureRMFunctionAppSlotVirtualNetworkSwiftConnection_update(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMAppServiceSlotVirtualNetworkSwiftConnectionExists(data.ResourceName),
),
},
},
})
}

func TestAccAzureRMFunctionAppSlotVirtualNetworkSwiftConnection_disappears(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_app_service_slot_virtual_network_swift_connection", "test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckAzureRMAppServiceSlotVirtualNetworkSwiftConnectionDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMAppServiceSlotVirtualNetworkSwiftConnection_basic(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMAppServiceSlotVirtualNetworkSwiftConnectionExists(data.ResourceName),
testCheckAzureRMAppServiceSlotVirtualNetworkSwiftConnectionDisappears(data.ResourceName),
),
ExpectNonEmptyPlan: true,
},
},
})
}

func testAccAzureRMFunctionAppSlotVirtualNetworkSwiftConnection_base(data acceptance.TestData) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-functionapp-%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" "test1" {
name = "acctestSubnet1"
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_subnet" "test2" {
name = "acctestSubnet2"
resource_group_name = azurerm_resource_group.test.name
virtual_network_name = azurerm_virtual_network.test.name
address_prefix = "10.0.2.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"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
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_function_app_slot" "test-staging" {
name = "acctest-FA-%d-staging"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
app_service_plan_id = azurerm_app_service_plan.test.id
function_app_name = azurerm_function_app.test.name
storage_account_name = azurerm_storage_account.test.name
storage_account_access_key = azurerm_storage_account.test.primary_access_key
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomString, data.RandomInteger, data.RandomInteger, data.RandomInteger)
}

func testAccAzureRMFunctionAppSlotVirtualNetworkSwiftConnection_basic(data acceptance.TestData) string {
template := testAccAzureRMFunctionAppSlotVirtualNetworkSwiftConnection_base(data)
return fmt.Sprintf(`
%s

resource "azurerm_app_service_slot_virtual_network_swift_connection" "test" {
slot_name = azurerm_function_app_slot.test-staging.name
app_service_id = azurerm_function_app.test.id
subnet_id = azurerm_subnet.test1.id
}
`, template)
}

func testAccAzureRMFunctionAppSlotVirtualNetworkSwiftConnection_update(data acceptance.TestData) string {
template := testAccAzureRMFunctionAppSlotVirtualNetworkSwiftConnection_base(data)
return fmt.Sprintf(`
%s

resource "azurerm_app_service_slot_virtual_network_swift_connection" "test" {
slot_name = azurerm_function_app_slot.test-staging.name
app_service_id = azurerm_function_app.test.id
subnet_id = azurerm_subnet.test2.id
}
`, template)
}

func testAccAzureRMFunctionAppSlotVirtualNetworkSwiftConnection_requiresImport(data acceptance.TestData) string {
template := testAccAzureRMFunctionAppSlotVirtualNetworkSwiftConnection_basic(data)
return fmt.Sprintf(`
%s

resource "azurerm_app_service_slot_virtual_network_swift_connection" "import" {
slot_name = azurerm_app_service_slot_virtual_network_swift_connection.test.slot_name
app_service_id = azurerm_app_service_slot_virtual_network_swift_connection.test.app_service_id
subnet_id = azurerm_app_service_slot_virtual_network_swift_connection.test.subnet_id
}
`, template)
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ resource "azurerm_app_service_slot_virtual_network_swift_connection" "example" {

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.

* `slot_name` - (Required) The name of the App Service Slot. Changing this forces a new resource to be created.
* `slot_name` - (Required) The name of the App Service Slot or Function App Slot. Changing this forces a new resource to be created.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whilst these are shared today - longer-term we'll likely want to introduce an alias for the function app resources

this isn't a big deal right now, and these do technically work - but we'll probably look to add aliases for these resources in 3.0 - since (based on Github issues) folks appear to be unaware these are the same thing


* `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