From 3fb0d8f8980a554d153d9a93d139d60fd64ebce6 Mon Sep 17 00:00:00 2001 From: Junyi Yi Date: Thu, 30 Aug 2018 04:01:55 -0700 Subject: [PATCH] Allow azurerm_function_app to use upper case names in consumption plan (#1835) * Add repro test case for #1765 * Lower-case the content share name to prevent Bad Request * Add link to the API request as TODO item. --- azurerm/resource_arm_function_app.go | 4 +- azurerm/resource_arm_function_app_test.go | 66 +++++++++++++++++++++++ 2 files changed, 69 insertions(+), 1 deletion(-) diff --git a/azurerm/resource_arm_function_app.go b/azurerm/resource_arm_function_app.go index 3183d6e15479..9941e1ca8a3c 100644 --- a/azurerm/resource_arm_function_app.go +++ b/azurerm/resource_arm_function_app.go @@ -510,6 +510,8 @@ func resourceArmFunctionAppDelete(d *schema.ResourceData, meta interface{}) erro } func getBasicFunctionAppAppSettings(d *schema.ResourceData, appServiceTier string) []web.NameValuePair { + // TODO: This is a workaround since there are no public Functions API + // You may track the API request here: https://github.com/Azure/azure-rest-api-specs/issues/3750 dashboardPropName := "AzureWebJobsDashboard" storagePropName := "AzureWebJobsStorage" functionVersionPropName := "FUNCTIONS_EXTENSION_VERSION" @@ -518,7 +520,7 @@ func getBasicFunctionAppAppSettings(d *schema.ResourceData, appServiceTier strin storageConnection := d.Get("storage_connection_string").(string) functionVersion := d.Get("version").(string) - contentShare := d.Get("name").(string) + "-content" + contentShare := strings.ToLower(d.Get("name").(string)) + "-content" basicSettings := []web.NameValuePair{ {Name: &dashboardPropName, Value: &storageConnection}, diff --git a/azurerm/resource_arm_function_app_test.go b/azurerm/resource_arm_function_app_test.go index b7dd2d2197fe..09b26c55c65d 100644 --- a/azurerm/resource_arm_function_app_test.go +++ b/azurerm/resource_arm_function_app_test.go @@ -338,6 +338,35 @@ func TestAccAzureRMFunctionApp_consumptionPlan(t *testing.T) { }) } +func TestAccAzureRMFunctionApp_consumptionPlanUppercaseName(t *testing.T) { + resourceName := "azurerm_function_app.test" + ri := acctest.RandInt() + rs := strings.ToLower(acctest.RandString(11)) + location := testLocation() + config := testAccAzureRMFunctionApp_consumptionPlanUppercaseName(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), + testCheckAzureRMFunctionAppHasContentShare(resourceName), + resource.TestCheckResourceAttr(resourceName, "site_config.0.use_32_bit_worker_process", "true"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func TestAccAzureRMFunctionApp_createIdentity(t *testing.T) { resourceName := "azurerm_function_app.test" ri := acctest.RandInt() @@ -982,6 +1011,43 @@ resource "azurerm_function_app" "test" { `, rInt, location, rString, rInt, rInt) } +func testAccAzureRMFunctionApp_consumptionPlanUppercaseName(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" + resource_group_name = "${azurerm_resource_group.test.name}" + location = "${azurerm_resource_group.test.location}" + kind = "FunctionApp" + + sku { + tier = "Dynamic" + size = "Y1" + } +} + +resource "azurerm_function_app" "test" { + name = "acctest-%d-FuncWithUppercase" + 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}" +} +`, rInt, location, rString, rInt, rInt) +} + func testAccAzureRMFunctionApp_basicIdentity(rInt int, storage string, location string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" {