Skip to content

Commit

Permalink
Allow azurerm_function_app to use upper case names in consumption plan (
Browse files Browse the repository at this point in the history
hashicorp#1835)

* Add repro test case for hashicorp#1765

* Lower-case the content share name to prevent Bad Request

* Add link to the API request as TODO item.
  • Loading branch information
Junyi Yi authored and torresdal committed Aug 31, 2018
1 parent 6d07aeb commit f28d620
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
4 changes: 3 additions & 1 deletion azurerm/resource_arm_function_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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},
Expand Down
66 changes: 66 additions & 0 deletions azurerm/resource_arm_function_app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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" {
Expand Down

0 comments on commit f28d620

Please sign in to comment.