Skip to content

Commit

Permalink
Merge pull request #886 from cloudify/745-function_app_site_config
Browse files Browse the repository at this point in the history
Issue #745, adds more options to azurerm_function_app
  • Loading branch information
tombuildsstuff authored Mar 6, 2018
2 parents 42ec5f9 + 5a2b8a4 commit 8fca308
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 4 deletions.
45 changes: 42 additions & 3 deletions azurerm/resource_arm_function_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,16 @@ func resourceArmFunctionApp() *schema.Resource {
Computed: true,
},

"client_affinity_enabled": {
Type: schema.TypeBool,
Optional: true,
Computed: true,

// TODO: (tombuildsstuff) support Update once the API is fixed:
// https://github.com/Azure/azure-rest-api-specs/issues/1697
ForceNew: true,
},

"site_config": {
Type: schema.TypeList,
Optional: true,
Expand All @@ -134,6 +144,16 @@ func resourceArmFunctionApp() *schema.Resource {
Optional: true,
Default: false,
},
"use_32_bit_worker_process": {
Type: schema.TypeBool,
Optional: true,
Default: true,
},
"websockets_enabled": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
},
},
},
Expand All @@ -152,6 +172,7 @@ func resourceArmFunctionAppCreate(d *schema.ResourceData, meta interface{}) erro
kind := "functionapp"
appServicePlanID := d.Get("app_service_plan_id").(string)
enabled := d.Get("enabled").(bool)
clientAffinityEnabled := d.Get("client_affinity_enabled").(bool)
tags := d.Get("tags").(map[string]interface{})
basicAppSettings := getBasicFunctionAppAppSettings(d)
siteConfig := expandFunctionAppSiteConfig(d)
Expand All @@ -162,9 +183,10 @@ func resourceArmFunctionAppCreate(d *schema.ResourceData, meta interface{}) erro
Location: &location,
Tags: expandTags(tags),
SiteProperties: &web.SiteProperties{
ServerFarmID: utils.String(appServicePlanID),
Enabled: utils.Bool(enabled),
SiteConfig: &siteConfig,
ServerFarmID: utils.String(appServicePlanID),
Enabled: utils.Bool(enabled),
ClientAffinityEnabled: utils.Bool(clientAffinityEnabled),
SiteConfig: &siteConfig,
},
}

Expand Down Expand Up @@ -288,6 +310,7 @@ func resourceArmFunctionAppRead(d *schema.ResourceData, meta interface{}) error
d.Set("enabled", props.Enabled)
d.Set("default_hostname", props.DefaultHostName)
d.Set("outbound_ip_addresses", props.OutboundIPAddresses)
d.Set("client_affinity_enabled", props.ClientAffinityEnabled)
}

appSettings := flattenAppServiceAppSettings(appSettingsResp.Properties)
Expand Down Expand Up @@ -394,6 +417,14 @@ func expandFunctionAppSiteConfig(d *schema.ResourceData) web.SiteConfig {
siteConfig.AlwaysOn = utils.Bool(v.(bool))
}

if v, ok := config["use_32_bit_worker_process"]; ok {
siteConfig.Use32BitWorkerProcess = utils.Bool(v.(bool))
}

if v, ok := config["websockets_enabled"]; ok {
siteConfig.WebSocketsEnabled = utils.Bool(v.(bool))
}

return siteConfig
}

Expand All @@ -410,6 +441,14 @@ func flattenFunctionAppSiteConfig(input *web.SiteConfig) []interface{} {
result["always_on"] = *input.AlwaysOn
}

if input.Use32BitWorkerProcess != nil {
result["use_32_bit_worker_process"] = *input.Use32BitWorkerProcess
}

if input.WebSocketsEnabled != nil {
result["websockets_enabled"] = *input.WebSocketsEnabled
}

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

func TestAccAzureRMFunctionApp_3264bit(t *testing.T) {
resourceName := "azurerm_function_app.test"
ri := acctest.RandInt()
rs := strings.ToLower(acctest.RandString(11))
location := testLocation()
config := testAccAzureRMFunctionApp_basic(ri, rs, location)
updatedConfig := testAccAzureRMFunctionApp_64bit(ri, rs, location)

resource.Test(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.use_32_bit_worker_process", "true"),
),
},
{
Config: updatedConfig,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMFunctionAppExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "site_config.0.use_32_bit_worker_process", "false"),
),
},
},
})
}

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

Expand Down Expand Up @@ -589,3 +620,42 @@ resource "azurerm_function_app" "test" {
}
`, rInt, location, rString)
}

func testAccAzureRMFunctionApp_64bit(rInt int, rString string, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}
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 = "acctestASP-%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-%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 {
use_32_bit_worker_process = false
}
}
`, rInt, location, rString, rInt, rInt)
}
9 changes: 8 additions & 1 deletion website/docs/r/function_app.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ The following arguments are supported:

* `enabled` - (Optional) Is the Function App enabled? Changing this forces a new resource to be created.

* `client_affinity_enabled` - (Optional) Should the Function App send session affinity cookies, which route client requests in the same session to the same instance? Changing this forces a new resource to be created.

* `version` - (Optional) The runtime version associated with the Function App. Possible values are `~1` and `beta`. Defaults to `~1`.

* `site_config` - (Optional) A `site_config` object as defined below.
Expand All @@ -87,7 +89,12 @@ The following arguments are supported:

`site_config` supports the following:

* `always_on` - (Optional) Should the app be loaded at all times? Defaults to `false`.
* `always_on` - (Optional) Should the Function App be loaded at all times? Defaults to `false`.
* `use_32_bit_worker_process` - (Optional) Should the Function App run in 32 bit mode, rather than 64 bit mode? Defaults to `true`.

~> **Note:** when using an App Service Plan in the `Free` or `Shared` Tiers `use_32_bit_worker_process` must be set to `true`.

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

## Attributes Reference

Expand Down

0 comments on commit 8fca308

Please sign in to comment.