From 9bb3ce6103fc9ef63925f5519603f1300084c8bc Mon Sep 17 00:00:00 2001 From: Jared Dickson Date: Fri, 7 Feb 2020 15:22:51 -0500 Subject: [PATCH] Add storage account name check to Function App update --- .../services/web/resource_arm_function_app.go | 22 ++++++++++++++++++- website/docs/r/function_app.html.markdown | 2 +- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/azurerm/internal/services/web/resource_arm_function_app.go b/azurerm/internal/services/web/resource_arm_function_app.go index fabc21ef00ef..f2acbece9e2a 100644 --- a/azurerm/internal/services/web/resource_arm_function_app.go +++ b/azurerm/internal/services/web/resource_arm_function_app.go @@ -78,7 +78,6 @@ func resourceArmFunctionApp() *schema.Resource { "storage_connection_string": { Type: schema.TypeString, Required: true, - ForceNew: true, Sensitive: true, }, @@ -429,6 +428,16 @@ func resourceArmFunctionAppUpdate(d *schema.ResourceData, meta interface{}) erro } } + if d.HasChange("storage_connection_string") { + oldValue, newValue := d.GetChange("storage_connection_string") + oldAccount := getAccountName(fmt.Sprintf("%s", oldValue)) + newAccount := getAccountName(fmt.Sprintf("%s", newValue)) + + if oldAccount != newAccount { + return fmt.Errorf("Error updating storage_connection_string because the AccountName cannot be changed. To change the storage account the resource must be tainted.") + } + } + future, err := client.CreateOrUpdate(ctx, resGroup, name, siteEnvelope) if err != nil { return err @@ -869,3 +878,14 @@ func flattenFunctionAppSiteCredential(input *web.UserProperties) []interface{} { return append(results, result) } + +func getAccountName(storageConnectionString string) string { + connectionStringArray := strings.SplitN(storageConnectionString, ";", -1) + connectionStringMap := make(map[string]string) + for _, pair := range connectionStringArray { + z := strings.Split(pair, "=") + connectionStringMap[z[0]] = z[1] + } + + return connectionStringMap["AccountName"] +} diff --git a/website/docs/r/function_app.html.markdown b/website/docs/r/function_app.html.markdown index 72ccfc130490..a500d1ab0d37 100644 --- a/website/docs/r/function_app.html.markdown +++ b/website/docs/r/function_app.html.markdown @@ -95,7 +95,7 @@ The following arguments are supported: * `app_service_plan_id` - (Required) The ID of the App Service Plan within which to create this Function App. -* `storage_connection_string` - (Required) The connection string of the backend storage account which will be used by this Function App (such as the dashboard, logs). +* `storage_connection_string` - (Required) The connection string of the backend storage account which will be used by this Function App (such as the dashboard, logs). The access key can be updated, but changing the storage account requires a taint and a recreate to take place. * `app_settings` - (Optional) A key-value pair of App Settings.