Last active
October 27, 2021 07:57
-
-
Save thepaulmacca/76e91a1580e925e4ebfbeda486b902e9 to your computer and use it in GitHub Desktop.
Bicep - App Service Deployment Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@description('The Azure region into which the resources should be deployed') | |
param location string = resourceGroup().location | |
@description('The type of environment. This must be nonprod or prod') | |
@allowed([ | |
'nonprod' | |
'prod' | |
]) | |
param environmentType string | |
@description('A unique suffix to add to resource names that need to be globally unique') | |
@maxLength(13) | |
param resourceNameSuffix string = uniqueString(resourceGroup().id) | |
var appServiceAppName = 'app-website-${resourceNameSuffix}' | |
var appServicePlanName = 'plan-website-${resourceNameSuffix}' | |
var applicationInsightsInstanceName = 'appi-${resourceNameSuffix}' | |
var storageAccountName = 'stweb${resourceNameSuffix}' | |
// Define the SKUs for each component based on the environment type | |
var environmentConfigurationMap = { | |
nonprod: { | |
appServiceApp: { | |
alwaysOn: false | |
} | |
appServicePlan: { | |
sku: { | |
name: 'F1' | |
capacity: 1 | |
} | |
} | |
storageAccount: { | |
sku: { | |
name: 'Standard_LRS' | |
} | |
} | |
} | |
prod: { | |
appServiceApp: { | |
alwaysOn: true | |
} | |
appServicePlan: { | |
sku: { | |
name: 'S1' | |
capacity: 2 | |
} | |
} | |
storageAccount: { | |
sku: { | |
name: 'Standard_ZRS' | |
} | |
} | |
} | |
} | |
var storageAccountConnectionString = 'DefaultEndpointsProtocol=https;AccountName=${storageAccount.name};EndpointSuffix=${environment().suffixes.storage};AccountKey=${storageAccount.listKeys().keys[0].value}' | |
resource appServicePlan 'Microsoft.Web/serverfarms@2021-02-01' = { | |
name: appServicePlanName | |
location: location | |
sku: environmentConfigurationMap[environmentType].appServicePlan.sku | |
} | |
resource appServiceApp 'Microsoft.Web/sites@2021-02-01' = { | |
name: appServiceAppName | |
location: location | |
properties: { | |
serverFarmId: appServicePlan.id | |
httpsOnly: true | |
siteConfig: { | |
alwaysOn: environmentConfigurationMap[environmentType].appServiceApp.alwaysOn | |
appSettings: [ | |
{ | |
name: 'APPINSIGHTS_INSTRUMENTATIONKEY' | |
value: applicationInsightsInstance.properties.InstrumentationKey | |
} | |
{ | |
name: 'APPLICATIONINSIGHTS_CONNECTION_STRING' | |
value: applicationInsightsInstance.properties.ConnectionString | |
} | |
{ | |
name: 'StorageAccountConnectionString' | |
value: storageAccountConnectionString | |
} | |
] | |
} | |
} | |
} | |
resource applicationInsightsInstance 'Microsoft.Insights/components@2018-05-01-preview' = { | |
name: applicationInsightsInstanceName | |
location: location | |
kind: 'web' | |
properties: { | |
Application_Type: 'web' | |
} | |
} | |
resource storageAccount 'Microsoft.Storage/storageAccounts@2021-06-01' = { | |
name: storageAccountName | |
location: location | |
kind: 'StorageV2' | |
sku: environmentConfigurationMap[environmentType].storageAccount.sku | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment