Skip to content

Instantly share code, notes, and snippets.

@ThomasPe
Created July 20, 2023 09:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ThomasPe/8a056ebe3d29a5b30884864a74b3976c to your computer and use it in GitHub Desktop.
Save ThomasPe/8a056ebe3d29a5b30884864a74b3976c to your computer and use it in GitHub Desktop.
Switch Azure Functions plan between Consumption and Premium
param isPremium bool = false
param location string = resourceGroup().location
var storageAccountName = storageaccountname'
var functionAppName = 'functionappname'
var hostingPlanName = 'functionapphostingplanname'
resource storageAccount 'Microsoft.Storage/storageAccounts@2022-09-01' = {
name: storageAccountName
location: location
kind: 'StorageV2'
sku: {
name: 'Standard_LRS'
}
}
resource hostingPlan 'Microsoft.Web/serverfarms@2022-09-01' = {
name: hostingPlanName
location: location
sku: {
name: isPremium ? 'EP1' : 'Y1'
capacity: isPremium ? 6 : 0 // must be smaller or equal to maximumElasticWorkerCount
}
properties: {
maximumElasticWorkerCount: 6 // "Maximum Burst", ignored for Y1 as consumption apps scale independently
elasticScaleEnabled: isPremium
}
}
resource functionApp 'Microsoft.Web/sites@2022-09-01' = {
name: functionAppName
location: location
kind: 'functionapp'
identity: {
type: 'SystemAssigned'
}
properties: {
serverFarmId: hostingPlan.id
siteConfig: {
appSettings: [
{
name: 'AzureWebJobsStorage'
value: 'DefaultEndpointsProtocol=https;AccountName=${storageAccountName};EndpointSuffix=${environment().suffixes.storage};AccountKey=${storageAccount.listKeys().keys[0].value}'
}
{
name: 'WEBSITE_CONTENTAZUREFILECONNECTIONSTRING'
value: 'DefaultEndpointsProtocol=https;AccountName=${storageAccountName};EndpointSuffix=${environment().suffixes.storage};AccountKey=${storageAccount.listKeys().keys[0].value}'
}
{
name: 'WEBSITE_CONTENTSHARE'
value: toLower(functionAppName)
}
{
name: 'FUNCTIONS_EXTENSION_VERSION'
value: '~4'
}
{
name: 'WEBSITE_NODE_DEFAULT_VERSION'
value: '~18'
}
{
name: 'FUNCTIONS_WORKER_RUNTIME'
value: 'node'
}
]
functionAppScaleLimit: 7 // only for consumption
}
httpsOnly: true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment