3
votes

I'm working on an ARM template to deploy an azure function. My steps are as follows

1) push arm template to blob storage and get the SAS uri 2) push the azure functions to blob storage and get the SAS uri 3) run powershell command New-AzureRmResourceGroup to create my new resource group 4) run powershell command New-AzureRmResourceGroupDeployment to deploy my application via an ARM template.

In my Arm template I'm using a nested template of MSDeploy to send up my azure function via a zip file.

The first deployment will create all of my resources but it will not deploy my Azure functions.

If I deploy via the same process with the same arm template to my freshly created resources and resource group, my azure functions will be deployed. I'm not sure what is going on with this process as both deployment are consider a success.

Here is my azure functions arm template with MSDeploy

{
        "type": "Microsoft.Web/sites",
        "apiVersion": "2015-08-01",
        "name": "[variables('functionsName')]",
        "location": "[resourceGroup().location]",
        "kind": "functionapp",
        "dependsOn": [
            "[resourceId('Microsoft.Web/serverfarms',variables('hostPlanName'))]",
            "[resourceId('Microsoft.Storage/storageAccounts', variables('storageName'))]",
            "[resourceId('Microsoft.Insights/components', variables('appInsightsName'))]"
        ],
        "properties": {
            "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('hostPlanName'))]",
            "name": "[variables('functionsName')]"
        },
        "resources": [ 
            {
                "name": "MSDeploy",
                "type": "extensions",
                "location": "[resourceGroup().location]",
                "apiVersion": "2015-08-01",
                "dependsOn": [
                    "[concat('Microsoft.Web/sites/', variables('functionsName'))]"
                ],
                "properties": {
                    "packageUri": "[concat(parameters('_artifactsLocation'),  parameters('SampleFunctionAppPackageFolder'), '/', parameters('SampleFunctionAppPackageFileName'), parameters('_artifactsLocationSasToken'))]",
                }
            },
            {
                "apiVersion": "2016-03-01",
                "name": "appsettings",
                "type": "config",
                "dependsOn": [
                    "[resourceId('Microsoft.Web/sites', variables('functionsName'))]",
                    "[resourceId('Microsoft.Storage/storageAccounts', variables('storageName'))]",
                    "[concat('Microsoft.Web/sites/', variables('functionsName'), '/Extensions/MSDeploy')]"
                ],
                "properties": {
                   ****  App settings removed *****
                }
            }
        ]
    }
1
So what is the problem you're facing ?Thomas
The first deployment wont deploy the azure functions. I want to try and make a fresh resources that have the azure functions deployed.McFrank
So you ve uploaded your code to a blob storage ?Thomas
yep. its in a zip file as it expects. The uri is good too I have tested it and was able to download my functions zip file. Like stated in the questions. The 2nd deployment to the same resourcegroup will deploy the functions. Just the first deployment does not deploy the functions for some reasonMcFrank
@Thomas We were able to find a solution to this bug, or I guess a work aroundMcFrank

1 Answers

2
votes

It turns out having your appSettings in a different ARM template causes this issue of the azure functions not being deploying on the first run. Moving the AppSettings into the appFunction ARM template such as

"type": "Microsoft.Web/sites",
    "apiVersion": "2015-08-01",
    "name": "[variables('functionsName')]",
    "location": "[resourceGroup().location]",
    "kind": "functionapp",
    "identity": {
        "type": "SystemAssigned"
    },
    "dependsOn": [
        "[resourceId('Microsoft.Web/serverfarms',variables('hostPlanName'))]"
    ],
    "properties": {
        "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('hostPlanName'))]",
        "name": "[variables('functionsName')]",
        "siteConfig": {
            "appSettings": [
                {
                    "name": "key1",
                    "value": "value1"
                }
            ]
        }
    }           
}

I was trying to avoid the deadlocking issue explained here https://blogs.msdn.microsoft.com/hosamshobak/2016/05/26/arm-template-msdeploy-race-condition-issue/

but we saw this bug as a result of those steps. I haven't ran into this deadlocking issue while deploying but it still could be possible as I have no idea if the deadlocking issue has been fixed with MSDeploy.