Can I conditionally use the Copy function in ARM Template - azure

Our solution is deployed to multiple environments, Dev, Test and Prod. I conditionally deploy Virtual Networks and other beefy network infrastructure for non-dev environments. The struggle I'm having is with applying Access Restrictions to the web config of an App Service, only when a boolean is true (using copyIndex).
The below works for assigning the subnet access restrictions to the App Service:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"type": "string",
"defaultValue": "ukwest"
}
},
"variables": {
"networkingRequired": true,
"aspName": "xxxMyAppServicePlan",
"siteName": "xxxMySite1",
"vnetName": "superVnetName",
"subnetNames": [
"subnetone",
"subnettwo",
"subnetthree"
]
},
"resources": [
{
"name": "[variables('aspName')]",
"type": "Microsoft.Web/serverfarms",
"kind": "app",
"apiVersion": "2018-02-01",
"location": "[parameters('location')]",
"properties": {},
"sku": {
"name": "S1",
"capacity": 1
}
},
{
"kind": "app",
"name": "[variables('siteName')]",
"type": "Microsoft.Web/sites",
"apiVersion": "2018-02-01",
"location": "[parameters('location')]",
"identity": {
"type": "SystemAssigned"
},
"properties": {
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('aspName'))]",
"siteConfig": {
"clientAffinityEnabled": false,
"httpsOnly": true,
"alwaysOn": true,
"virtualApplications": [
{
"virtualPath": "/",
"physicalPath": "site\\wwwroot",
"preloadEnabled": true
}
],
"copy": [
{
"name": "ipSecurityRestrictions",
"count": "[length(variables('subnetNames'))]",
"input": {
"vnetSubnetResourceId": "[resourceId(resourceGroup().name, 'Microsoft.Network/virtualNetworks/subnets', variables('vnetName'), variables('subnetNames')[copyIndex('ipSecurityRestrictions')])]",
"action": "Allow",
"priority": "1",
"name": "[variables('subnetNames')[copyIndex('ipSecurityRestrictions')]]",
"description": "[concat(variables('subnetNames')[copyIndex('ipSecurityRestrictions')], ' subnet')]"
}
}
]
}
},
"dependsOn": [
"[variables('aspName')]"
]
}
]
}
So what I now need to do is have it respect the variable 'networkingRequired' and only do the "copy" for ipSecurityRestrictions when networking is true.

easiest way of doing this - move the copy to the variables section and use an expression to define the value of ipSecurityRestrictions "on the fly".
"variables": {
"empty": [],
"copy": [you copy goes here]
},
...
"ipSecurityRestrictions": "[if(variables('networkingRequired'), variables('ipSecurityRestrictions'), variables('empty'))]"

Related

ARM template to create a NET 5 app service

I have an ARM template that created an Azure app service, it worked well for .NET Core but I now want to update the template to deploy a NET 5 app service, I'm not having any luck.
Here's the ARM schema: https://learn.microsoft.com/en-us/azure/templates/microsoft.web/sites
Here's an extract from the template, I run this but when I look in the portal the site is created with a .NET Framework version of ASPNET 4.8. How to deploy a NET 5 site with an ARM template?
{
"name": "[variables('apiAppServiceName')]",
"type": "Microsoft.Web/sites",
"apiVersion": "2020-06-01",
"location": "[parameters('location')]",
"dependsOn": [
"[variables('hostingPlanName')]",
"[variables('databaseName')]",
"[variables('storageAccountName')]"
],
"tags": {
"[concat('hidden-related:', resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName')))]": "empty",
"displayName": "Website",
"environment": "[parameters('environment')]"
},
"properties": {
"name": "[variables('apiAppServiceName')]",
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]",
"httpsOnly": true,
"clientAffinityEnabled": false,
"netFrameworkVersion": "net5.0"
},
Looking at template generated by Azure:
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"subscriptionId": {
"type": "string"
},
"name": {
"type": "string"
},
"location": {
"type": "string"
},
"hostingPlanName": {
"type": "string"
},
"serverFarmResourceGroup": {
"type": "string"
},
"alwaysOn": {
"type": "bool"
},
"currentStack": {
"type": "string"
},
"phpVersion": {
"type": "string"
},
"netFrameworkVersion": {
"type": "string"
}
},
"resources": [
{
"apiVersion": "2018-11-01",
"name": "[parameters('name')]",
"type": "Microsoft.Web/sites",
"location": "[parameters('location')]",
"tags": null,
"dependsOn": [],
"properties": {
"name": "[parameters('name')]",
"siteConfig": {
"appSettings": [],
"metadata": [
{
"name": "CURRENT_STACK",
"value": "[parameters('currentStack')]"
}
],
"phpVersion": "[parameters('phpVersion')]",
"netFrameworkVersion": "[parameters('netFrameworkVersion')]",
"alwaysOn": "[parameters('alwaysOn')]"
},
"serverFarmId": "[concat('/subscriptions/', parameters('subscriptionId'),'/resourcegroups/', parameters('serverFarmResourceGroup'), '/providers/Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]",
"clientAffinityEnabled": true
}
}
]
}
and paramaters
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"subscriptionId": {
"value": "someId"
},
"name": {
"value": "testdotnet5"
},
"location": {
"value": "Central US"
},
"hostingPlanName": {
"value": "ServicePlan43e7dac6-ad18"
},
"serverFarmResourceGroup": {
"value": "recruiterly"
},
"alwaysOn": {
"value": false
},
"currentStack": {
"value": "dotnet"
},
"phpVersion": {
"value": "OFF"
},
"netFrameworkVersion": {
"value": "v5.0"
}
}
}
You should use
"netFrameworkVersion": {
"value": "v5.0"
}
On top of the issue with the wrong value, you've also got the netFrameworkVersion in the wrong section, in properties rather than properties->siteconfig. Something like this should sort you out:
{
"name": "[variables('apiAppServiceName')]",
"type": "Microsoft.Web/sites",
"apiVersion": "2020-06-01",
"location": "[parameters('location')]",
"dependsOn": [
"[variables('hostingPlanName')]",
"[variables('databaseName')]",
"[variables('storageAccountName')]"
],
"tags": {
"[concat('hidden-related:', resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName')))]": "empty",
"displayName": "Website",
"environment": "[parameters('environment')]"
},
"properties": {
"name": "[variables('apiAppServiceName')]",
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]",
"httpsOnly": true,
"clientAffinityEnabled": false,
"siteconfig" : {
"netFrameworkVersion": "v5.0"
}
},
The parameter settings mentioned previously did not do it for me. Validation of the ARM template kept bombing out complaining that value for netFrameworkVersion had to be null. Changing it to defaultValue got me passed that.
"netFrameworkVersion": {
"type": "string",
"defaultValue": "v5.0"
},

Azure ARM Template DependentOn FileShare

I need to create via ARM template storage account --> File share --> Container with mounted fileshare.
The dependency is:
file share depends on storage account
container depends on file share
How to get ReferenceId of Fileshare?
I have the following code:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"storageAccountType": {
"type": "string",
"defaultValue": "Standard_LRS",
"allowedValues": [
"Standard_LRS",
"Standard_GRS"
],
"metadata": {
"description": "Storage account type (SKU)"
}
},
"fileShareName": {
"type": "string",
"minLength": 3,
"maxLength": 63,
"defaultValue": "sftp",
"metadata": {
"description": "Name of the File Share to be created. "
}
}
},
"variables": {
"deploymentLocation": "[resourceGroup().location]",
"storageAccountName": "[concat('sftpstr', uniqueString(resourceGroup().id))]"
},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"name": "[variables('storageAccountName')]",
"apiVersion": "2019-06-01",
"location": "[variables('deploymentLocation')]",
"sku": {
"name": "[parameters('storageAccountType')]"
},
"kind": "StorageV2",
"properties": {
"accessTier": "Hot"
}
},
{
"type": "Microsoft.Storage/storageAccounts/fileServices/shares",
"apiVersion": "2019-06-01",
"properties": {
"accessTier": "Hot"
},
"name": "[concat(variables('storageAccountName'), '/default/', parameters('fileShareName'))]",
"dependsOn": [
"[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))]"
]
},
{
"type": "Microsoft.ContainerInstance/containerGroups",
"name": "sftp-container-group",
"apiVersion": "2018-04-01",
"dependsOn": [
"[resourceId('Microsoft.Storage/storageAccounts/fileServices/shares', ????? )]" //how to get reference to specific Fileshare??? I've tried > [concat(variables('storageAccountName'), '/default/', parameters('fileShareName'))] but it didn't work
],
"properties": {
.......
}
}
]
}
and I don't know how to set dependency on Fileshare:
"dependsOn": [
"[resourceId('Microsoft.Storage/storageAccounts/fileServices/shares', ????? )]" //how to get reference to specific Fileshare???
],
I've tried [concat(variables('storageAccountName'), '/default/', parameters('fileShareName'))] but it didn't work.
Any idea?
Thank you
Use following format:
"dependsOn": [
"[resourceId('Microsoft.Storage/storageAccounts/fileServices/shares', variables('storageAccountName') , 'default', parameters('fileShareName') )]"
],
You could create two separate resources Microsoft.Storage/storageAccounts/fileServices and Microsoft.Storage/storageAccounts/fileServices/shares and try to set dependency on Fileshare like this:
"dependsOn": [
"[resourceId('Microsoft.Storage/storageAccounts/fileServices/shares', variables('storageAccountName'), 'default', parameters('fileShareName') )]"
],
Alternatively, It's recommended to creates a storage account and a file share via azure-CLI in a Container Instance and refer to this quickstart template.
"variables": {
"image": "microsoft/azure-cli",
"cpuCores": "1.0",
"memoryInGb": "1.5",
"containerGroupName": "createshare-containerinstance",
"containerName": "createshare"
},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"name": "[parameters('storageAccountName')]",
"apiVersion": "2019-06-01",
"location": "[parameters('location')]",
"sku": {
"name": "[parameters('storageAccountType')]"
},
"kind": "StorageV2"
},
{
"name": "[variables('containerGroupName')]",
"type": "Microsoft.ContainerInstance/containerGroups",
"apiVersion": "2019-12-01",
"location": "[parameters('containerInstanceLocation')]",
"dependsOn": [
"[resourceId('Microsoft.Storage/storageAccounts/', parameters('storageAccountName'))]"
],
"properties": {
"containers": [
{
"name": "[variables('containerName')]",
"properties": {
"image": "[variables('image')]",
"command": [
"az",
"storage",
"share",
"create",
"--name",
"[parameters('fileShareName')]"
],
"environmentVariables": [
{
"name": "AZURE_STORAGE_KEY",
"value": "[listKeys(parameters('storageAccountName'),'2019-06-01').keys[0].value]"
},
{
"name": "AZURE_STORAGE_ACCOUNT",
"value": "[parameters('storageAccountName')]"
}
],
"resources": {
"requests": {
"cpu": "[variables('cpuCores')]",
"memoryInGb": "[variables('memoryInGb')]"
}
}
}
}
],
"restartPolicy": "OnFailure",
"osType": "Linux"
}
}
]
I found a couple of things that made it work for me:
ACI has to depend on the share otherwise it gets created ahead of volume sometimes
"dependsOn": ["resourceId('Microsoft.Storage/storageAccounts/fileServices/shares',variables('storage-account-name'), 'default', variables('file-share-name'))]"]
For some reason, the share wasn't working as a child resource so I had to make it a full resource
{
"type": "Microsoft.Storage/storageAccounts/fileServices/shares",
"apiVersion": "2021-04-01",
"name": "[concat(variables('storage-account-name'),'/default/',variables('nginx-share-name'))]",
"properties":{
"enabledProtocols": "SMB"
},
"dependsOn": [
"[resourceId('Microsoft.Storage/storageAccounts', variables('storage-account-name'))]"
]
}
Also, I had to pay attention to default part of the resource ID
"name": "[concat(variables('storage-account-name'),'/default/',variables('nginx-share-name'))]"
And finally, ACI wasn't connecting properly unless I explicitly enabled SMB as a protocol
"properties":{
"enabledProtocols": "SMB"
}
This is a template I'm using to spin up NGINX in Azure Container instances with an Azure File Share as a mounted volume.
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"containerGroups_name": {
"defaultValue": "container-app",
"type": "String"
},
"containerGroups_reverse_proxy_name": {
"defaultValue": "app-proxy",
"type": "String"
},
"acrPassword": {
"type": "securestring"
}
},
"variables": {
"nginx-proxy-image": "nginx:stable",
"storage-account-name": "[concat('storage', uniqueString(resourceGroup().name))]",
"nginx-share-name": "nginx-share",
"nginx-volume-name": "nginx-volume"
},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2017-10-01",
"name": "[variables('storage-account-name')]" ,
"location": "[resourceGroup().location]",
"kind": "StorageV2",
"sku": {
"name": "Standard_LRS",
"tier": "Standard"
}
},
{
"type": "Microsoft.Storage/storageAccounts/fileServices/shares",
"apiVersion": "2021-04-01",
"name": "[concat(variables('storage-account-name'),'/default/',variables('nginx-share-name'))]",
"properties":{
"enabledProtocols": "SMB"
},
"dependsOn": [
"[resourceId('Microsoft.Storage/storageAccounts', variables('storage-account-name'))]"
]
},
{
"type": "Microsoft.ContainerInstance/containerGroups",
"apiVersion": "2021-03-01",
"name": "[parameters('containerGroups_name')]",
"location": "[resourceGroup().location]",
"properties": {
"sku": "Standard",
"containers": [
{
"name": "[parameters('containerGroups_reverse_proxy_name')]",
"properties" : {
"image": "[variables('nginx-proxy-image')]",
"ports": [
{
"protocol": "TCP",
"port": 80
},
{
"protocol": "TCP",
"port": 433
}
],
"volumeMounts" : [
{
"name": "[variables('nginx-volume-name')]",
"mountPath": "/etc/nginx"
}
],
"resources": {
"requests":{
"cpu": 1,
"memoryInGB": 1.5
}
}
}
}
],
"initContainers": [],
"restartPolicy": "OnFailure",
"osType": "Linux",
"volumes": [
{
"name": "[variables('nginx-volume-name')]",
"azureFile": {
"shareName": "[variables('nginx-share-name')]",
"storageAccountName": "[variables('storage-account-name')]",
"storageAccountKey": "[listKeys(resourceId('Microsoft.Storage/storageAccounts',variables('storage-account-name')),'2017-10-01').keys[0].value]"
}
}
]
},
"dependsOn": [
"[resourceId('Microsoft.Storage/storageAccounts/fileServices/shares',variables('storage-account-name'), 'default', variables('nginx-share-name'))]"
]
}
]
}

ARM Template App Service Config - Race Condition / Inconsistent Behavior

Using ARM template below, we enabled diagnostic settings for our app service as well as defining appSettings config under resources element. The issue is that intermittently after deploying our app service from template - the appSettings are not getting assigned, but the diagnostics settings are.
Can someone guide us if there is a better way to define config for logs and appSettings for an app service that provides a more consistent site output? We build and teardown dozens of app services daily for PR builds so this is very apparent.
The appSetting WEBSITE_LOAD_USER_PROFILE will just get randomly dropped when the app service is created. Are we missing a dependsOn or do we need to upgrade apiVersion?
ServerFarm with App Settings + Log Config
{
"$schema": "http://schema.management.azure.com/schemas/2018-05-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"siteName": {
"type": "string"
},
"siteHostingPlanName": {
"type": "string"
},
"resourceLocation": {
"type": "string"
}
},
"resources": [
{
"apiVersion": "2016-09-01",
"name": "[parameters('siteHostingPlanName')]",
"type": "Microsoft.Web/serverfarms",
"location": "[parameters('resourceLocation')]",
"properties": {
"name": "[parameters('siteHostingPlanName')]"
},
"sku": {
"name": "P2V2",
"tier": "PremiumV2",
"capacity": 2
}
},
{
"apiVersion": "2014-11-01",
"name": "[parameters('siteName')]",
"type": "Microsoft.Web/sites",
"location": "[parameters('resourceLocation')]",
"dependsOn": [
"[resourceId('Microsoft.Web/serverfarms', parameters('siteHostingPlanName'))]"
],
"properties": {
"name": "[parameters('siteName')]",
"serverFarm": "[parameters('siteHostingPlanName')]",
"siteConfig": {
"AlwaysOn": true,
"webSocketsEnabled": true,
"http20Enabled": true,
"requestTracingEnabled": true,
"requestTracingExpirationTime": "9999-12-31T23:59:00Z",
"httpLoggingEnabled": true,
"logsDirectorySizeLimit": 100,
"detailedErrorLoggingEnabled": true
}
},
"resources": [
{
"apiVersion": "2014-11-01",
"name": "appsettings",
"type": "config",
"dependsOn": [
"[resourceId('Microsoft.Web/Sites', parameters('siteName'))]"
],
"properties": {
"WEBSITE_LOAD_USER_PROFILE": 1
}
},
{
"apiVersion": "2014-11-01",
"name": "logs",
"type": "config",
"dependsOn": [
"[resourceId('Microsoft.Web/Sites', parameters('siteName'))]"
],
"properties": {
"applicationLogs": {
"fileSystem": {
"level": "Verbose"
}
},
"httpLogs": {
"fileSystem": {
"retentionInMb": 100,
"enabled": true
}
},
"failedRequestsTracing": {
"enabled": true
},
"detailedErrorMessages": {
"enabled": true
}
}
}
]
}
]
}
Instead of defining the settings in a separate resource, you should configure the app settings together with the functionApp Resource. I have used this and defined various app settings and it works fine. Try like the below example.
{
"apiVersion": "[variables('sitesApiVersion')]",
"type": "Microsoft.Web/sites",
"kind": "functionapp",
"location": "[resourceGroup().location]",
"name": "[parameters('functionAppName')]",
"scale": null,
"properties": {
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('functionApp_appServicePlanName'))]",
"siteConfig": {
"appSettings": [
{
"name": "WEBSITE_LOAD_USER_PROFILE",
"value": "1"
}
]
},
"dependsOn": [
"[resourceId('Microsoft.Web/serverfarms', parameters('functionApp_appServicePlanName'))]",
"[resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName'))]"
]
}
}

Deploy Azure Function with ARM template

I am trying to deploy Azure Function with ARM template , but I am not able to create the function itself. Is it possible to create the actual function using ARM template?
I have zipped the source code for the function and placed it in a public location, I have added the MSBuild section to the template and although the deployment finished successfully - the App function was created but not the function itself
here is the template
{
"parameters": {
"name": {
"type": "string"
},
"storageName": {
"type": "string"
},
"location": {
"type": "string"
},
"subscriptionId": {
"type": "string"
},
"storage_account_endpoint": {
"type": "string"
}
},
"resources": [
{
"apiVersion": "2016-03-01",
"name": "[parameters('name')]",
"type": "Microsoft.Web/sites",
"properties": {
"name": "[parameters('name')]",
"siteConfig": {
"appSettings": [
{
"name": "FUNCTIONS_WORKER_RUNTIME",
"value": "node"
},
{
"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": "~2"
},
{
"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')), 'bd58')]"
},
{
"name": "WEBSITE_NODE_DEFAULT_VERSION",
"value": "8.11.1"
},
{
"name": "storage_account_connection",
"value": "[parameters('storage_account_endpoint')]"
}
]
},
"clientAffinityEnabled": false,
"reserved": false
},
"dependsOn": [
"[resourceId('Microsoft.Storage/storageAccounts', parameters('storageName'))]"
],
"resources": [
{
"name": "MSDeploy",
"type": "Extensions",
"apiVersion": "2015-02-01",
"dependsOn": [
"[resourceId('Microsoft.Web/Sites', parameters('name'))]"
],
"properties": {
"packageUri": "<URL to zip>"
}
}
],
"location": "[parameters('location')]",
"identity": {
"type": "SystemAssigned"
},
"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"
}
In short No - ARM can only create the infrastructure for you but not deploy the code (**see comment).
But as always there is a way. A while back MS release a new feature 'Run from ZIP' on web apps (including Function Apps). All you need is the actual project (code published as ZIP) to be in a location where the function app can access it.
We use VSTS (Azure Dev Ops) for CI/CD. So we build the solution add the ZIP to the artifact. Then in the Release we copy the ZIP to blob storage, create a SAS Token and pass the location of the blob Container with the SAS Token to ARM. In the ARM template we build the connection string to the ZIP, using input parameter. As soon as ARM is done then the Function is up and running.
Eg.
{
"parameters": {
"name": {
"type": "string"
},
"storageName": {
"type": "string"
},
"location": {
"type": "string"
},
"subscriptionId": {
"type": "string"
},
"storage_account_endpoint": {
"type": "string"
},
"artifactsUri": {
"type": "string"
},
"artifactsBlobContainer": {
"type": "string"
},
"artifactsLocationSasToken": {
"type": "string"
}
},
"resources": [
{
"apiVersion": "2016-03-01",
"name": "[parameters('name')]",
"type": "Microsoft.Web/sites",
"properties": {
"name": "[parameters('name')]",
"siteConfig": {
"appSettings": [
{
"name": "FUNCTIONS_WORKER_RUNTIME",
"value": "node"
},
{
"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": "~2"
},
{
"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')), 'bd58')]"
},
{
"name": "WEBSITE_NODE_DEFAULT_VERSION",
"value": "8.11.1"
},
{
"name": "storage_account_connection",
"value": "[parameters('storage_account_endpoint')]"
},
{
"name": "WEBSITE_RUN_FROM_ZIP",
"value": "[concat(parameters('artifactsUri'), '/', parameters('artifactsBlobContainer'),'/','blahbla.FA.zip',parameters('artifactsLocationSasToken'))]"
}
]
},
"clientAffinityEnabled": false,
"reserved": false
},
"dependsOn": [
"[resourceId('Microsoft.Storage/storageAccounts', parameters('storageName'))]"
],
"resources": [
{
"name": "MSDeploy",
"type": "Extensions",
"apiVersion": "2015-02-01",
"dependsOn": [
"[resourceId('Microsoft.Web/Sites', parameters('name'))]"
],
"properties": {
"packageUri": "<URL to zip>"
}
}
],
"location": "[parameters('location')]",
"identity": {
"type": "SystemAssigned"
},
"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"
}
'Run from ZIP' is achieved with the 'WEBSITE_RUN_FROM_ZIP' app setting.
Hope this helps
I just use this FunctionWebDeploy.json template. I download the app content(zip file)from the existing function app and upload it to the public address. Finally I can deploy function app including code.
Go to Azure portal portal.azure.com, and create a new Azure Function.
2.Go to Resource Group.
3.Go to Export template.
4.You will see something like this.
This is the ARM Template for all resources/componets.

Attach an existing Web Service plan to a new Website using Azure Resource Manager templates

I am trying to automate website deployment using the Azure Resource Manager. Website creation and code deployment is working fine, but I am unable to attach the new site to an existing Web Hosting plan.
I am using the 2015-08-01 API and from different examples I think that this template should work (it does not...):
The deployment fails at "Microsoft.Web/sites/config" and the site is beeing assigned a new default free hosting plan.
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"siteName": {
"type": "string"
},
"subscriptionId": {
"type": "string"
},
"setting1": {
"type": "string"
},
"setting2": {
"type": "string"
}
},
"resources": [
{
"apiVersion": "2015-08-01",
"type": "Microsoft.Web/sites",
"name": "[parameters('siteName')]",
"location": "[resourceGroup().location]",
"properties": {
"serverFarmId ": "/subscriptions/xxxxxx/resourceGroups/xxxxxx/providers/Microsoft.Web/serverfarms/xxxxxx"
},
"resources": [
{
"apiVersion": "2015-08-01",
"name": "web",
"type": "config",
"dependsOn": [
"[resourceId('Microsoft.Web/Sites', parameters('siteName'))]"
],
"properties": {
"phpVersion": "off",
"netFrameworkVersion": "v4.6",
"use32BitWorkerProcess": false,
"webSocketsEnabled": true,
"alwaysOn": true,
"requestTracingEnabled": false,
"httpLoggingEnabled": false,
"logsDirectorySizeLimit": 40,
"detailedErrorLoggingEnabled": false,
"appSettings": [
{
"Name": "setting1",
"Value": "Value1"
},
{
"Name": "setting2",
"Value": "Value2"
}
]
}
},
{
"apiVersion": "2015-08-01",
"type": "extensions",
"name": "MSDeploy",
"dependsOn": [
"[resourceId('Microsoft.Web/sites', parameters('siteName'))]"
],
"properties": {
"packageUri": "xxxxxxxx",
"dbType": "None",
"connectionString": ""
}
}
]
}
],
"outputs": {
"siteUri": {
"type": "string",
"value": "[concat('http://',reference(resourceId('Microsoft.Web/sites', parameters('siteName'))).hostNames[0])]"
}
}
}
I ended up falling back to the 2014-06-01 API and with some adjustments to the script, was able to do what I wanted.
Providing the script for future references.
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"siteName": {
"type": "string"
},
"subscriptionId": {
"type": "string"
},
"hostingPlanName": {
"type": "string"
},
"setting1": {
"type": "string"
},
"setting2": {
"type": "string"
}
},
"resources": [
{
"apiVersion": "2014-06-01",
"type": "Microsoft.Web/sites",
"name": "[parameters('siteName')]",
"location": "[resourceGroup().location]",
"dependsOn": [
],
"properties": {
"name": "[parameters('siteName')]",
"serverFarm": "[parameters('hostingPlanName')]"
},
"resources": [
{
"apiVersion": "2014-06-01",
"name": "web",
"type": "config",
"dependsOn": [
"[resourceId('Microsoft.Web/Sites', parameters('siteName'))]",
"[concat('Microsoft.Web/Sites/', parameters('siteName'), '/Extensions/MSDeploy')]"
],
"properties": {
"phpVersion": "off",
"netFrameworkVersion": "v4.6",
"use32BitWorkerProcess": false,
"webSocketsEnabled": true,
"alwaysOn": true,
"requestTracingEnabled": false,
"httpLoggingEnabled": false,
"logsDirectorySizeLimit": 40,
"detailedErrorLoggingEnabled": false
}
},
{
"apiVersion": "2014-11-01",
"name": "appsettings",
"type": "config",
"dependsOn": [
"[resourceId('Microsoft.Web/Sites', parameters('siteName'))]",
"[concat('Microsoft.Web/Sites/', parameters('siteName'), '/Extensions/MSDeploy')]"
],
"properties": {
"Setting1": "[parameters('setting1')]",
"Setting2": "[parameters('setting2')]"
}
},
{
"apiVersion": "2015-08-01",
"type": "extensions",
"name": "MSDeploy",
"dependsOn": [
"[resourceId('Microsoft.Web/Sites', parameters('siteName'))]"
],
"properties": {
"packageUri": "https://xxxxx.zip",
"dbType": "None",
"connectionString": ""
}
}
]
}
]
}

Resources