Skip to content

Instantly share code, notes, and snippets.

@MarcusFelling
Created April 12, 2021 23:09
Show Gist options
  • Save MarcusFelling/bd8103be11f033f4090207679e539645 to your computer and use it in GitHub Desktop.
Save MarcusFelling/bd8103be11f033f4090207679e539645 to your computer and use it in GitHub Desktop.
// The following will create an Azure Function app on
// a consumption plan, along with a storage account
// and application insights.
param location string = resourceGroup().location
param appNamePrefix string = uniqueString(resourceGroup().id)
param workspaceResourceId string
var functionAppName = '${appNamePrefix}-functionapp'
var appServiceName = '${appNamePrefix}-appservice'
var appInsightsName = '${appNamePrefix}-appinsights'
// remove dashes for storage account name
var storageAccountName = format('{0}sta', replace(appNamePrefix, '-', ''))
var appTags = {
AppID: 'myfunc'
AppName: 'My Function App'
}
// Storage Account
resource storageAccount 'Microsoft.Storage/storageAccounts@2019-06-01' = {
name: storageAccountName
location: location
sku: {
name: 'Standard_LRS'
tier: 'Standard'
}
kind: 'StorageV2'
properties: {
supportsHttpsTrafficOnly: true
encryption: {
services: {
file: {
keyType: 'Account'
enabled: true
}
blob: {
keyType: 'Account'
enabled: true
}
}
keySource: 'Microsoft.Storage'
}
accessTier: 'Hot'
}
tags: appTags
// Blob Services for Storage Account
resource blobServices 'blobServices@2019-06-01' = {
name: 'default'
properties: {
cors: {
corsRules: []
}
deleteRetentionPolicy: {
enabled: true
days: 7
}
}
}
}
// App Insights resource
resource appInsights 'Microsoft.Insights/components@2020-02-02-preview' = {
name: appInsightsName
location: location
kind: 'web'
properties: {
Application_Type: 'web'
WorkspaceResourceId: workspaceResourceId
publicNetworkAccessForIngestion: 'Enabled'
publicNetworkAccessForQuery: 'Enabled'
}
tags: appTags
}
// App Service
resource appService 'Microsoft.Web/serverFarms@2020-06-01' = {
name: appServiceName
location: location
kind: 'functionapp'
sku: {
name: 'Y1'
tier: 'Dynamic'
size: 'Y1'
family: 'Y'
capacity: 0
}
properties: {
perSiteScaling: false
maximumElasticWorkerCount: 1
isSpot: false
reserved: false
isXenon: false
hyperV: false
targetWorkerCount: 0
targetWorkerSizeId: 0
}
tags: appTags
}
// Function App
resource functionApp 'Microsoft.Web/sites@2020-06-01' = {
name: functionAppName
location: location
kind: 'functionapp'
properties: {
enabled: true
hostNameSslStates: [
{
name: '${functionAppName}.azurewebsites.net'
sslState: 'Disabled'
hostType: 'Standard'
}
{
name: '${functionAppName}.scm.azurewebsites.net'
sslState: 'Disabled'
hostType: 'Standard'
}
]
serverFarmId: appService.id
reserved: false
isXenon: false
hyperV: false
siteConfig: {
appSettings: [
{
name: 'AzureWebJobsStorage'
value: 'DefaultEndpointsProtocol=https;AccountName=${storageAccount.name};EndpointSuffix=${environment().suffixes.storage};AccountKey=${listKeys(storageAccount.id, storageAccount.apiVersion).keys[0].value}'
}
{
name: 'WEBSITE_CONTENTAZUREFILECONNECTIONSTRING'
value: 'DefaultEndpointsProtocol=https;AccountName=${storageAccount.name};EndpointSuffix=${environment().suffixes.storage};AccountKey=${listKeys(storageAccount.id, storageAccount.apiVersion).keys[0].value}'
}
{
name: 'APPINSIGHTS_INSTRUMENTATIONKEY'
value: appInsights.properties.InstrumentationKey
}
{
name: 'APPLICATIONINSIGHTS_CONNECTION_STRING'
value: 'InstrumentationKey=${appInsights.properties.InstrumentationKey}'
}
{
name: 'FUNCTIONS_WORKER_RUNTIME'
value: 'dotnet'
}
{
name: 'FUNCTIONS_EXTENSION_VERSION'
value: '~3'
}
]
}
scmSiteAlsoStopped: false
clientAffinityEnabled: false
clientCertEnabled: false
hostNamesDisabled: false
dailyMemoryTimeQuota: 0
httpsOnly: true
redundancyMode: 'None'
}
tags: appTags
// Function App Config
resource functionAppConfig 'config@2020-06-01' = {
name: 'web'
properties: {
numberOfWorkers: -1
defaultDocuments: [
'Default.htm'
'Default.html'
'Default.asp'
'index.htm'
'index.html'
'iisstart.htm'
'default.aspx'
'index.php'
'hostingstart.html'
]
netFrameworkVersion: 'v4.0'
phpVersion: '5.6'
requestTracingEnabled: false
remoteDebuggingEnabled: false
httpLoggingEnabled: false
logsDirectorySizeLimit: 35
detailedErrorLoggingEnabled: false
publishingUsername: '$${functionAppName}'
scmType: 'None'
use32BitWorkerProcess: true
webSocketsEnabled: false
alwaysOn: false
managedPipelineMode: 'Integrated'
virtualApplications: [
{
virtualPath: '/'
physicalPath: 'site\\wwwroot'
preloadEnabled: true
}
]
loadBalancing: 'LeastRequests'
experiments: {
rampUpRules: []
}
autoHealEnabled: false
cors: {
allowedOrigins: [
'https://functions.azure.com'
'https://functions-staging.azure.com'
'https://functions-next.azure.com'
]
supportCredentials: false
}
localMySqlEnabled: false
ipSecurityRestrictions: [
{
ipAddress: 'Any'
action: 'Allow'
priority: 1
name: 'Allow all'
description: 'Allow all access'
}
]
scmIpSecurityRestrictions: [
{
ipAddress: 'Any'
action: 'Allow'
priority: 1
name: 'Allow all'
description: 'Allow all access'
}
]
scmIpSecurityRestrictionsUseMain: false
http20Enabled: true
minTlsVersion: '1.2'
ftpsState: 'AllAllowed'
preWarmedInstanceCount: 0
}
}
// Function App Binding
resource functionAppBinding 'hostNameBindings@2020-06-01' = {
name: '${functionApp.name}.azurewebsites.net'
properties: {
siteName: functionApp.name
hostNameType: 'Verified'
}
}
}
output appSettings array = functionApp.properties.siteConfig.appSettings
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment