Skip to content

Commit

Permalink
Add storage account name check to Function App update
Browse files Browse the repository at this point in the history
  • Loading branch information
kraihn committed Feb 7, 2020
1 parent cc274d5 commit 9bb3ce6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
22 changes: 21 additions & 1 deletion azurerm/internal/services/web/resource_arm_function_app.go
Expand Up @@ -78,7 +78,6 @@ func resourceArmFunctionApp() *schema.Resource {
"storage_connection_string": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Sensitive: true,
},

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"]
}
2 changes: 1 addition & 1 deletion website/docs/r/function_app.html.markdown
Expand Up @@ -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.

Expand Down

0 comments on commit 9bb3ce6

Please sign in to comment.