Instantly share code, notes, and snippets.

@johndowns johndowns/template.json Secret
Created Jan 16, 2019

Embed
What would you like to do?
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"uniqueResourceNameSuffix": {
"type": "string",
"defaultValue": "[uniqueString(subscription().subscriptionId, resourceGroup().id)]",
"metadata": {
"description": "The suffix to add to resource names that require global uniqueness."
}
},
"applicationInsightsLocation": {
"type": "string",
"defaultValue": "westus2",
"allowedValues": [
"eastus",
"southcentralus",
"westus2",
"northeurope",
"westeurope",
"southeastasia"
],
"metadata": {
"description": "The location in which to deploy Application Insights, since it supports a subset of Azure regions."
}
}
},
"variables": {
"functionsAppServicePlanName": "MonitoringFunctions",
"functionsAppName": "[concat('fn', parameters('uniqueResourceNameSuffix'))]",
"functionsStorageAccountName": "[concat('fn', parameters('uniqueResourceNameSuffix'))]",
"functionsStorageAccountResourceId": "[resourceId('Microsoft.Storage/storageAccounts', variables('functionsStorageAccountName'))]",
"applicationInsightsName": "CustomMetrics"
},
"resources": [
{
"name": "[variables('functionsStorageAccountName')]",
"type": "Microsoft.Storage/storageAccounts",
"location": "[resourceGroup().location]",
"apiVersion": "2018-02-01",
"sku": {
"name": "Standard_LRS"
},
"kind": "StorageV2",
"properties": {
"accessTier": "Hot",
"supportsHttpsTrafficOnly": true,
"encryption": {
"services": {
"blob": {
"enabled": true
}
},
"keySource": "Microsoft.Storage"
}
}
},
{
"name": "[variables('functionsAppServicePlanName')]",
"type": "Microsoft.Web/serverfarms",
"location": "[resourceGroup().location]",
"apiVersion": "2016-09-01",
"sku": {
"name": "Y1",
"tier": "Dynamic",
"size": "Y1",
"family": "Y",
"capacity": 0
},
"kind": "functionapp",
"properties": {
"workerTierName": null,
"adminSiteName": null,
"hostingEnvironmentProfile": null,
"perSiteScaling": false,
"reserved": false,
"targetWorkerCount": 0,
"targetWorkerSizeId": 0
}
},
{
"name": "[variables('functionsAppName')]",
"type": "Microsoft.Web/sites",
"location": "[resourceGroup().location]",
"apiVersion": "2016-08-01",
"kind": "functionapp",
"properties": {
"enabled": true,
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('functionsAppServicePlanName'))]",
"reserved": false,
"siteConfig": {
"ftpsState": "Disabled"
}
},
"identity": {
"type": "SystemAssigned"
},
"resources": [
{
"name": "appsettings",
"type": "config",
"apiVersion": "2014-11-01",
"properties": {
"FUNCTIONS_EXTENSION_VERSION": "~2",
"AzureWebJobsDashboard": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('functionsStorageAccountName'), ';AccountKey=', listKeys(variables('functionsStorageAccountResourceId'),'2015-05-01-preview').key1)]",
"AzureWebJobsStorage": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('functionsStorageAccountName'), ';AccountKey=', listKeys(variables('functionsStorageAccountResourceId'),'2015-05-01-preview').key1)]",
"APPINSIGHTS_INSTRUMENTATIONKEY": "[reference(resourceId('Microsoft.Insights/components', variables('applicationInsightsName')), '2014-04-01').InstrumentationKey]"
},
"dependsOn": [
"[resourceId('Microsoft.Web/sites', variables('functionsAppName'))]",
"[resourceId('Microsoft.Storage/storageAccounts', variables('functionsStorageAccountName'))]",
"[resourceId('Microsoft.Insights/components', variables('applicationInsightsName'))]"
]
},
{
"name": "AddMetric",
"type": "functions",
"apiVersion": "2015-08-01",
"properties": {
"config": {
"bindings": [
{
"name": "timer",
"type": "timerTrigger",
"direction": "in",
"schedule": "0 */5 * * * *"
}
],
"disabled": false
},
"files": {
"run.csx": "using Microsoft.ApplicationInsights;\r\nusing Microsoft.ApplicationInsights.Metrics;\r\nusing Microsoft.Extensions.Logging;\r\n\r\nprivate static TelemetryClient TelemetryClient = new TelemetryClient();\r\nprivate static Random Random = new Random();\r\n\r\npublic static void Run(TimerInfo timer, ILogger log)\r\n{\r\n var randomValue = (int)Random.Next(0, 10);\r\n TelemetryClient.GetMetric(\"My Metric Name\").TrackValue(randomValue);\r\n}\r\n",
"function.proj": "<Project Sdk=\"Microsoft.NET.Sdk\">\r\n <PropertyGroup>\r\n <TargetFramework>netstandard2.0<\/TargetFramework>\r\n <\/PropertyGroup>\r\n <ItemGroup>\r\n <PackageReference Include=\"Microsoft.ApplicationInsights\" Version=\"2.8.1\"\/>\r\n <\/ItemGroup>\r\n<\/Project>\r\n"
}
},
"dependsOn": [
"[resourceId('Microsoft.Web/sites', variables('functionsAppName'))]"
]
}
],
"dependsOn": [
"[resourceId('Microsoft.Web/serverfarms', variables('functionsAppServicePlanName'))]"
]
},
{
"name": "[variables('applicationInsightsName')]",
"type": "Microsoft.Insights/components",
"apiVersion": "2014-04-01",
"location": "[parameters('applicationInsightsLocation')]",
"kind": "other",
"properties": {
"applicationId": "[variables('applicationInsightsName')]"
}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment