Skip to content

Commit

Permalink
[resource_arm_function_app] Add missing vnet_name property (#4078)
Browse files Browse the repository at this point in the history
  • Loading branch information
lawrencegripper authored and katbyte committed Aug 13, 2019
1 parent 51941d0 commit 897fc67
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
14 changes: 14 additions & 0 deletions azurerm/resource_arm_function_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ func resourceArmFunctionApp() *schema.Resource {
Optional: true,
Computed: true,
},
"virtual_network_name": {
Type: schema.TypeString,
Optional: true,
Computed: false,
},
"cors": azure.SchemaWebCorsSettings(),
},
},
Expand Down Expand Up @@ -360,6 +365,7 @@ func resourceArmFunctionAppUpdate(d *schema.ResourceData, meta interface{}) erro
}
basicAppSettings := getBasicFunctionAppAppSettings(d, appServiceTier)
siteConfig := expandFunctionAppSiteConfig(d)

siteConfig.AppSettings = &basicAppSettings

siteEnvelope := web.Site{
Expand Down Expand Up @@ -688,6 +694,10 @@ func expandFunctionAppSiteConfig(d *schema.ResourceData) web.SiteConfig {
siteConfig.Cors = &expand
}

if v, ok := config["virtual_network_name"]; ok {
siteConfig.VnetName = utils.String(v.(string))
}

return siteConfig
}

Expand Down Expand Up @@ -716,6 +726,10 @@ func flattenFunctionAppSiteConfig(input *web.SiteConfig) []interface{} {
result["linux_fx_version"] = *input.LinuxFxVersion
}

if input.VnetName != nil {
result["virtual_network_name"] = *input.VnetName
}

result["cors"] = azure.FlattenWebCorsSettings(input.Cors)

results = append(results, result)
Expand Down
68 changes: 68 additions & 0 deletions azurerm/resource_arm_function_app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,34 @@ func TestAccAzureRMFunctionApp_corsSettings(t *testing.T) {
})
}

func TestAccAzureRMFunctionApp_vnetName(t *testing.T) {
resourceName := "azurerm_function_app.test"
ri := tf.AccRandTimeInt()
rs := strings.ToLower(acctest.RandString(11))
vnetName := strings.ToLower(acctest.RandString(11))
config := testAccAzureRMFunctionApp_vnetName(ri, rs, testLocation(), vnetName)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMFunctionAppDestroy,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMFunctionAppExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "site_config.0.virtual_network_name", vnetName),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testCheckAzureRMFunctionAppDestroy(s *terraform.State) error {
client := testAccProvider.Meta().(*ArmClient).web.AppServicesClient

Expand Down Expand Up @@ -1605,3 +1633,43 @@ resource "azurerm_function_app" "test" {
}
`, rInt, location, storage)
}

func testAccAzureRMFunctionApp_vnetName(rInt int, storage, location, vnetName string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%[1]d"
location = "%[2]s"
}
resource "azurerm_storage_account" "test" {
name = "acctestsa%[3]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 = "acctestASP-%[1]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-%[1]d-func"
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_connection_string = "${azurerm_storage_account.test.primary_connection_string}"
site_config {
virtual_network_name = "%[4]s"
}
}
`, rInt, location, storage, vnetName)
}
2 changes: 2 additions & 0 deletions website/docs/r/function_app.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ The following arguments are supported:

* `websockets_enabled` - (Optional) Should WebSockets be enabled?

* `virtual_network_name` - (Optional) The name of the Virtual Network which this App Service should be attached to.

* `linux_fx_version` - (Optional) Linux App Framework and version for the AppService, e.g. `DOCKER|(golang:latest)`.

* `cors` - (Optional) A `cors` block as defined below.
Expand Down

0 comments on commit 897fc67

Please sign in to comment.