2
votes

Hopefully, someone can tell me what I'm doing wrong with this ARM template deployment.

Using the template at the bottom of the question, I can deploy a Function App - with app service plan and storage account - but I get the following error.

STATUS              BadRequest
PROVISIONING STATE  Failed
TIMESTAMP           4/19/2017, 1:33:00 PM
DURATION            1 second
TYPE                Microsoft.Web/sites/config
RESOURCE ID         /subscriptions/blah-blah-blah/resourceGroups/blah/providers/Microsoft.Web/sites/functionname/config/appsettings
STATUSMESSAGE       {
                        "Code": "BadRequest",
                        "Message": "There was a conflict. The remote server returned an error: (400) Bad Request.",
                        "Target": null,
                        "Details": [
                        {
                            "Message": "There was a conflict. The remote server returned an error: (400) Bad Request."
                        },
                        {
                            "Code": "BadRequest"
                        },
                        {
                            "ErrorEntity": {
                                "ExtendedCode": "01020",
                                "MessageTemplate": "There was a conflict. {0}",
                                "Parameters": [
                                    "The remote server returned an error: (400) Bad Request."
                                ],
                                "Code": "BadRequest",
                                "Message": "There was a conflict. The remote server returned an error: (400) Bad Request."
                            }
                        }],
                        "Innererror": null
                    }
RESOURCE            functionname/appsettings

If I remove this AppSetting property from the function app part of the template then the deployment works fine.

"WEBSITE_CONTENTAZUREFILECONNECTIONSTRING": "[concat('DefaultEndpointsProtocol=https;AccountName=',parameters('Storage_Account_Name'),';AccountKey=',listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('Storage_Account_Name')),'2015-05-01-preview').key1)]",

But then when I go to the deployed function app I get this error popup.

Error:

'WEBSITE_CONTENTAZUREFILECONNECTIONSTRING' application setting is missing from your app. This setting contains a connection string for an Azure Storage account that is used to host your functions content. Your app will be completely broken without this setting. You may need to delete and recreate this function app if you no longer have access to the value of that application setting.

I also note that if I try and add that appsetting in the portal manually after this successful deployment, I get the same error as the initial deployment.

So, I don't know if I'm putting it in the template incorrectly, or if something in the Azure Deployment for functions apps is broken.

Where am I going wrong?

Template

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "App_Service_Plan_Name": {
            "defaultValue": "aspname",
            "type": "String"
        },
        "Functions_App_Name": {
            "defaultValue": "funcname",
            "type": "String"
        },
        "Storage_Account_Name": {
            "defaultValue": "storagename",
            "type": "String"
        }
    },
    "variables": {},
    "resources": [
        {
            "comments": "Deployed from template",
            "type": "Microsoft.Storage/storageAccounts",
            "name": "[parameters('Storage_Account_Name')]",
            "apiVersion": "2016-01-01",
            "sku": {
                "name": "Standard_LRS"
            },
            "location": "[resourceGroup().location]",
            "kind": "Storage"
        },
        {
            "comments": "Deployed from template",
            "type": "Microsoft.Web/serverfarms",
            "sku": {
                "name": "Y1",
                "tier": "Dynamic",
                "size": "Y1",
                "family": "Y",
                "capacity": 0
            },
            "kind": "functionapp",
            "name": "[parameters('App_Service_Plan_Name')]",
            "apiVersion": "2015-08-01",
            "location": "[resourceGroup().location]",
            "properties": {
                "name": "[parameters('App_Service_Plan_Name')]",
                "numberOfWorkers": 0
            },
            "dependsOn": []
        },
        {
            "comments": "Deployed from template",
            "type": "Microsoft.Web/sites",
            "kind": "functionapp",
            "name": "[parameters('Functions_App_Name')]",
            "apiVersion": "2015-08-01",
            "location": "[resourceGroup().location]",
            "properties": {
                "name": "[parameters('Functions_App_Name')]",
                "hostNames": [
                    "[concat(parameters('Functions_App_Name'),'.azurewebsites.net')]"
                ],
                "enabledHostNames": [
                    "[concat(parameters('Functions_App_Name'),'.azurewebsites.net')]",
                    "[concat(parameters('Functions_App_Name'),'.scm.azurewebsites.net')]"
                ],
                "hostNameSslStates": [
                    {
                        "name": "[concat(parameters('Functions_App_Name'),'.azurewebsites.net')]",
                        "sslState": 0,
                        "thumbprint": null,
                        "ipBasedSslState": 0
                    },
                    {
                        "name": "[concat(parameters('Functions_App_Name'),'.scm.azurewebsites.net')]",
                        "sslState": 0,
                        "thumbprint": null,
                        "ipBasedSslState": 0
                    }
                ],
                "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('App_Service_Plan_Name'))]"
            },
            "dependsOn": [
                "[resourceId('Microsoft.Web/serverfarms', parameters('App_Service_Plan_Name'))]",
                "[resourceId('Microsoft.Storage/storageAccounts', parameters('Storage_Account_Name'))]"
            ],
            "resources": [
                {
                    "apiVersion": "2015-08-01",
                    "name": "appsettings",
                    "type": "config",
                    "dependsOn": [
                        "[resourceId('Microsoft.Web/Sites', parameters('Functions_App_Name'))]",
                        "[resourceId('Microsoft.Storage/storageAccounts', parameters('Storage_Account_Name'))]"
                    ],
                    "properties": {
                        "FUNCTIONS_EXTENSION_VERSION": "~1",
                        "AzureWebJobsDashboard": "[concat('DefaultEndpointsProtocol=https;AccountName=',parameters('Storage_Account_Name'),';AccountKey=',listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('Storage_Account_Name')),'2015-05-01-preview').key1)]",
                        "AzureWebJobsStorage": "[concat('DefaultEndpointsProtocol=https;AccountName=',parameters('Storage_Account_Name'),';AccountKey=',listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('Storage_Account_Name')),'2015-05-01-preview').key1)]",
                        "WEBSITE_CONTENTAZUREFILECONNECTIONSTRING": "[concat('DefaultEndpointsProtocol=https;AccountName=',parameters('Storage_Account_Name'),';AccountKey=',listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('Storage_Account_Name')),'2015-05-01-preview').key1)]",
                        "WEBSITE_CONTENTSHARE": "[concat(parameters('Functions_App_Name'),'_files')]",
                        "WEBSITE_NODE_DEFAULT_VERSION": "6.5.0"
                    }
                },
                {
                    "apiVersion": "2015-08-01",
                    "name": "web",
                    "type": "config",
                    "dependsOn": [
                        "[resourceId('Microsoft.Web/Sites', parameters('Functions_App_Name'))]",
                        "[resourceId('Microsoft.Storage/storageAccounts', parameters('Storage_Account_Name'))]"
                    ],
                    "properties": {
                        "cors": {
                            "allowedOrigins": [
                                "[concat('https://',parameters('Storage_Account_Name'),'.blob.core.windows.net')]"
                            ]
                        }
                    }
                }
            ]
        }
    ]
}
5

5 Answers

13
votes

So typically, after spending a day or so trying to find out what's wrong before breaking down and resorting to asking SO, as soon as I do I find out what's wrong.

The issue is not the WEBSITE_CONTENTAZUREFILECONNECTIONSTRING but the WEBSITE_CONTENTSHARE. This has an underscore in it and underscores are not allowed in the naming convention of Storage Account File shares.

So, mental note, when I see an error like There was a conflict..., think ...with a naming convention, not ...with an existing resource.

I did also have to add the 3 Azure URLs to the CORS AllowedOrigins section

"https://functions.azure.com",
"https://functions-staging.azure.com",
"https://functions-next.azure.com"
1
votes

Not sure if it's directly related to the issue, but I suggest making your template more similar to what the Portal uses by default. To see this:

  • Start the process of creating a new function app in Azure Portal
  • Enter some arbitrary App name and Resource Group
  • Click at the 'Automation options' link at the bottom

You'll get the full strict that it uses. It looks like this:

{
  "parameters": {
    "name": {
      "type": "string"
    },
    "storageName": {
      "type": "string"
    },
    "location": {
      "type": "string"
    },
    "subscriptionId": {
      "type": "string"
    }
  },
  "resources": [
    {
      "apiVersion": "2016-03-01",
      "name": "[parameters('name')]",
      "type": "Microsoft.Web/sites",
      "properties": {
        "name": "[parameters('name')]",
        "siteConfig": {
          "appSettings": [
            {
              "name": "AzureWebJobsDashboard",
              "value": "[concat('DefaultEndpointsProtocol=https;AccountName=',parameters('storageName'),';AccountKey=',listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('storageName')), '2015-05-01-preview').key1)]"
            },
            {
              "name": "AzureWebJobsStorage",
              "value": "[concat('DefaultEndpointsProtocol=https;AccountName=',parameters('storageName'),';AccountKey=',listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('storageName')), '2015-05-01-preview').key1)]"
            },
            {
              "name": "FUNCTIONS_EXTENSION_VERSION",
              "value": "~1"
            },
            {
              "name": "WEBSITE_CONTENTAZUREFILECONNECTIONSTRING",
              "value": "[concat('DefaultEndpointsProtocol=https;AccountName=',parameters('storageName'),';AccountKey=',listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('storageName')), '2015-05-01-preview').key1)]"
            },
            {
              "name": "WEBSITE_CONTENTSHARE",
              "value": "[concat(toLower(parameters('name')), 'a66e')]"
            },
            {
              "name": "WEBSITE_NODE_DEFAULT_VERSION",
              "value": "6.5.0"
            }
          ]
        },
        "clientAffinityEnabled": false
      },
      "dependsOn": [
        "[resourceId('Microsoft.Storage/storageAccounts', parameters('storageName'))]"
      ],
      "location": "[parameters('location')]",
      "kind": "functionapp"
    },
    {
      "apiVersion": "2015-05-01-preview",
      "type": "Microsoft.Storage/storageAccounts",
      "name": "[parameters('storageName')]",
      "location": "[parameters('location')]",
      "properties": {
        "accountType": "Standard_LRS"
      }
    }
  ],
  "$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0"
}
0
votes

My Azure Deployment especially for the Function App also fails due to these appsettings. Here is an excerpt of my ARM script.

"siteConfig": {
   "appsettings": [
   {
     "name": "AzureWebJobsDashboard",
     "value": "[Concat('DefaultEndpointsProtocol=https;AccountName=',variables('StorageAccountName'),';AccountKey=',listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('StorageAccountName')), providers('Microsoft.Storage', 'storageAccounts').apiVersions[0]).keys[0].value)]"
   },
 ]

The value is used for the following settings: AzureWebJobsDashboard, AzureWebJobsStorage, WEBSITE_CONTENTAZUREFILECONNECTIONSTRING. Depends on for my storage account is also set in the ARM script.

I'm starting the deployment via Visual Studio Team Services. Here I get my mistake. I get the error message directly from Azure.

  • Resource: Azure-Function-Dev
  • Type: Microsoft.Web/sites
  • Status: BadRequest

    { "error": { "code": "InternalServerError", "message": "There was an unexpected InternalServerError. Please try again later. x-ms-correlation-request-id: 44444-4444..." } }

If the Function App is redeployed again - without any changes - the deployment always works. Strange behaviour.

I then set my value to a fixed value using my parameters. Since then the deployment runs without problems. This may not be a technically clean solution, but the error can be analyzed

"siteConfig": {
      "appsettings": [
        {
          "name": "AzureWebJobsStorage",
          "value": "[parameters('AzureWebJobsStorage')]"
        }, ]
0
votes

TLDR;

Check if the storage account name is correct & only in lowercase letters.

Longer version

github issue - https://github.com/Azure/azure-cli/issues/14518#issuecomment-665255337

In my scenario I was setting up a new Resource Group, new App Service Plan & new Function - however with existing Storage Account and ran into this issue There was a conflict. The remote server returned an error: (400) Bad Request.

My issue was with my parameter file that had a casing issue in the Storage Account name. myownstorageaccountTest instead of myownstorageaccounttest

The ARM template deployment was attempting to create a new storage account with this name myownstorageaccountTest when this myownstorageaccounttest already exists. Storage account names need to be unique across azure.

Storage Account Name requirement: The name must be unique across all existing storage account names in Azure. It must be 3 to 24 characters long, and can contain only lowercase letters and numbers.

0
votes

TL;DR: Function App name must be 59 chars or less

Because these names form a hostname, I typically append random digits to fill out to the max of whatever the limit is, which I believe is documented to be 60 characters.

During the Function App creation wizard, entering a name of 61 characters properly rejects the name right in the form: Function app with 61 chars The error message of "Must be fewer than 60" is the same as "59 or less", but entering exactly 60 - which I've seen elsewhere - allows the process to continue: Function app with 60 chars Continuing to create the Function App eventually fails with this error:

{
  "code": "DeploymentFailed",
  "message": "At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/DeployOperations for usage details.",
  "details": [
    {
      "message": "There was a conflict. The remote server returned an error: (400) Bad Request."
    }
  ]
}

Using a name of 59 chars creates OK.

This feels like a fencepost error in the form, where it accepts entry of a name that's one character larger than downstream processes will accept.