From 469cce32f9f2edaf9e423b7676dfff6b53a39df2 Mon Sep 17 00:00:00 2001 From: JFolberth Date: Mon, 21 Dec 2020 14:20:06 -0500 Subject: [PATCH] Adding Example of modules with deploying web application with log analytics (#1200) * added condition example * formatting, adding to index of examples * adding webapp log analytics with modules * Added .json from bicep build of each module * Updated json * removed files meant fo rother branch. * removed reference to invalid example --- .../app-insights.bicep | 20 ++ .../app-insights.json | 43 +++ .../app-service-plan.bicep | 18 + .../app-service-plan.json | 47 +++ .../app-service.bicep | 56 ++++ .../web-app-loganalytics-mod/app-service.json | 91 +++++ .../log-analytics.bicep | 19 ++ .../log-analytics.json | 41 +++ .../201/web-app-loganalytics-mod/main.bicep | 32 ++ .../201/web-app-loganalytics-mod/main.json | 315 ++++++++++++++++++ docs/examples/index.json | 4 + 11 files changed, 686 insertions(+) create mode 100644 docs/examples/201/web-app-loganalytics-mod/app-insights.bicep create mode 100644 docs/examples/201/web-app-loganalytics-mod/app-insights.json create mode 100644 docs/examples/201/web-app-loganalytics-mod/app-service-plan.bicep create mode 100644 docs/examples/201/web-app-loganalytics-mod/app-service-plan.json create mode 100644 docs/examples/201/web-app-loganalytics-mod/app-service.bicep create mode 100644 docs/examples/201/web-app-loganalytics-mod/app-service.json create mode 100644 docs/examples/201/web-app-loganalytics-mod/log-analytics.bicep create mode 100644 docs/examples/201/web-app-loganalytics-mod/log-analytics.json create mode 100644 docs/examples/201/web-app-loganalytics-mod/main.bicep create mode 100644 docs/examples/201/web-app-loganalytics-mod/main.json diff --git a/docs/examples/201/web-app-loganalytics-mod/app-insights.bicep b/docs/examples/201/web-app-loganalytics-mod/app-insights.bicep new file mode 100644 index 00000000000..ea6508a0cec --- /dev/null +++ b/docs/examples/201/web-app-loganalytics-mod/app-insights.bicep @@ -0,0 +1,20 @@ +param location string = resourceGroup().location +param appName string +param logAnalaticsWorkspaceResourceID string + +var appInsightName = toLower('appi-${appName}') + +resource appInsights 'microsoft.insights/components@2020-02-02-preview' = { + name: appInsightName + location: location + kind: 'string' + tags: { + displayName: 'AppInsight' + ProjectName: appName + } + properties: { + Application_Type: 'web' + WorkspaceResourceId: logAnalaticsWorkspaceResourceID + } +} +output APPINSIGHTS_INSTRUMENTATIONKEY string = appInsights.properties.InstrumentationKey diff --git a/docs/examples/201/web-app-loganalytics-mod/app-insights.json b/docs/examples/201/web-app-loganalytics-mod/app-insights.json new file mode 100644 index 00000000000..c5e51cb4546 --- /dev/null +++ b/docs/examples/201/web-app-loganalytics-mod/app-insights.json @@ -0,0 +1,43 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "location": { + "type": "string", + "defaultValue": "[resourceGroup().location]" + }, + "appName": { + "type": "string" + }, + "logAnalaticsWorkspaceResourceID": { + "type": "string" + } + }, + "functions": [], + "variables": { + "appInsightName": "[toLower(format('appi-{0}', parameters('appName')))]" + }, + "resources": [ + { + "type": "Microsoft.Insights/components", + "apiVersion": "2020-02-02-preview", + "name": "[variables('appInsightName')]", + "location": "[parameters('location')]", + "kind": "string", + "tags": { + "displayName": "AppInsight", + "ProjectName": "[parameters('appName')]" + }, + "properties": { + "Application_Type": "web", + "WorkspaceResourceId": "[parameters('logAnalaticsWorkspaceResourceID')]" + } + } + ], + "outputs": { + "APPINSIGHTS_INSTRUMENTATIONKEY": { + "type": "string", + "value": "[reference(resourceId('Microsoft.Insights/components', variables('appInsightName'))).InstrumentationKey]" + } + } +} \ No newline at end of file diff --git a/docs/examples/201/web-app-loganalytics-mod/app-service-plan.bicep b/docs/examples/201/web-app-loganalytics-mod/app-service-plan.bicep new file mode 100644 index 00000000000..12d24bf5439 --- /dev/null +++ b/docs/examples/201/web-app-loganalytics-mod/app-service-plan.bicep @@ -0,0 +1,18 @@ +param skuName string = 'S1' +param skuCapacity int = 1 +param location string = resourceGroup().location +param appName string +var appServicePlanName = toLower('asp-${appName}') +resource appServicePlan 'Microsoft.Web/serverfarms@2020-06-01' = { + name: appServicePlanName // Globally unique storage account name + location: location // Azure Region + sku: { + name: skuName + capacity: skuCapacity + } + tags: { + displayName: 'HostingPlan' + ProjectName: appName + } +} +output appServicePlanID string = appServicePlan.id diff --git a/docs/examples/201/web-app-loganalytics-mod/app-service-plan.json b/docs/examples/201/web-app-loganalytics-mod/app-service-plan.json new file mode 100644 index 00000000000..d4778128e7c --- /dev/null +++ b/docs/examples/201/web-app-loganalytics-mod/app-service-plan.json @@ -0,0 +1,47 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "skuName": { + "type": "string", + "defaultValue": "S1" + }, + "skuCapacity": { + "type": "int", + "defaultValue": 1 + }, + "location": { + "type": "string", + "defaultValue": "[resourceGroup().location]" + }, + "appName": { + "type": "string" + } + }, + "functions": [], + "variables": { + "appServicePlanName": "[toLower(format('asp-{0}', parameters('appName')))]" + }, + "resources": [ + { + "type": "Microsoft.Web/serverfarms", + "apiVersion": "2020-06-01", + "name": "[variables('appServicePlanName')]", + "location": "[parameters('location')]", + "sku": { + "name": "[parameters('skuName')]", + "capacity": "[parameters('skuCapacity')]" + }, + "tags": { + "displayName": "HostingPlan", + "ProjectName": "[parameters('appName')]" + } + } + ], + "outputs": { + "appServicePlanID": { + "type": "string", + "value": "[resourceId('Microsoft.Web/serverfarms', variables('appServicePlanName'))]" + } + } +} \ No newline at end of file diff --git a/docs/examples/201/web-app-loganalytics-mod/app-service.bicep b/docs/examples/201/web-app-loganalytics-mod/app-service.bicep new file mode 100644 index 00000000000..3ab6c0454ed --- /dev/null +++ b/docs/examples/201/web-app-loganalytics-mod/app-service.bicep @@ -0,0 +1,56 @@ +param location string = resourceGroup().location +param appName string +param appServicePlanID string +param APPINSIGHTS_INSTRUMENTATIONKEY string +var webSiteName = toLower('wapp-${appName}') + +resource appService 'Microsoft.Web/sites@2020-06-01' = { + name: webSiteName + location: location + identity: { + type: 'SystemAssigned' + } + tags: { + displayName: 'Website' + ProjectName: appName + } + properties: { + serverFarmId: appServicePlanID + httpsOnly: true + siteConfig: { + minTlsVersion: '1.2' + } + } +} +resource appServiceLogging 'Microsoft.Web/sites/config@2020-06-01' = { + name: '${appService.name}/logs' + properties: { + applicationLogs: { + fileSystem: { + level: 'Warning' + } + } + httpLogs: { + fileSystem: { + retentionInMb: 40 + enabled: true + } + } + failedRequestsTracing: { + enabled: true + } + detailedErrorMessages: { + enabled: true + } + } +} + +resource appServiceAppSettings 'Microsoft.Web/sites/config@2020-06-01' = { + name: '${appService.name}/appsettings' + properties: { + APPINSIGHTS_INSTRUMENTATIONKEY: APPINSIGHTS_INSTRUMENTATIONKEY + } +} +resource appServiceSiteExtension 'Microsoft.Web/sites/siteextensions@2020-06-01' = { + name: '${appService.name}/Microsoft.ApplicationInsights.AzureWebsites' +} diff --git a/docs/examples/201/web-app-loganalytics-mod/app-service.json b/docs/examples/201/web-app-loganalytics-mod/app-service.json new file mode 100644 index 00000000000..7ade43a5b21 --- /dev/null +++ b/docs/examples/201/web-app-loganalytics-mod/app-service.json @@ -0,0 +1,91 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "location": { + "type": "string", + "defaultValue": "[resourceGroup().location]" + }, + "appName": { + "type": "string" + }, + "appServicePlanID": { + "type": "string" + }, + "APPINSIGHTS_INSTRUMENTATIONKEY": { + "type": "string" + } + }, + "functions": [], + "variables": { + "webSiteName": "[toLower(format('wapp-{0}', parameters('appName')))]" + }, + "resources": [ + { + "type": "Microsoft.Web/sites", + "apiVersion": "2020-06-01", + "name": "[variables('webSiteName')]", + "location": "[parameters('location')]", + "identity": { + "type": "SystemAssigned" + }, + "tags": { + "displayName": "Website", + "ProjectName": "[parameters('appName')]" + }, + "properties": { + "serverFarmId": "[parameters('appServicePlanID')]", + "httpsOnly": true, + "siteConfig": { + "minTlsVersion": "1.2" + } + } + }, + { + "type": "Microsoft.Web/sites/config", + "apiVersion": "2020-06-01", + "name": "[format('{0}/logs', variables('webSiteName'))]", + "properties": { + "applicationLogs": { + "fileSystem": { + "level": "Warning" + } + }, + "httpLogs": { + "fileSystem": { + "retentionInMb": 40, + "enabled": true + } + }, + "failedRequestsTracing": { + "enabled": true + }, + "detailedErrorMessages": { + "enabled": true + } + }, + "dependsOn": [ + "[resourceId('Microsoft.Web/sites', variables('webSiteName'))]" + ] + }, + { + "type": "Microsoft.Web/sites/config", + "apiVersion": "2020-06-01", + "name": "[format('{0}/appsettings', variables('webSiteName'))]", + "properties": { + "APPINSIGHTS_INSTRUMENTATIONKEY": "[parameters('APPINSIGHTS_INSTRUMENTATIONKEY')]" + }, + "dependsOn": [ + "[resourceId('Microsoft.Web/sites', variables('webSiteName'))]" + ] + }, + { + "type": "Microsoft.Web/sites/siteextensions", + "apiVersion": "2020-06-01", + "name": "[format('{0}/Microsoft.ApplicationInsights.AzureWebsites', variables('webSiteName'))]", + "dependsOn": [ + "[resourceId('Microsoft.Web/sites', variables('webSiteName'))]" + ] + } + ] +} \ No newline at end of file diff --git a/docs/examples/201/web-app-loganalytics-mod/log-analytics.bicep b/docs/examples/201/web-app-loganalytics-mod/log-analytics.bicep new file mode 100644 index 00000000000..d8f235b627d --- /dev/null +++ b/docs/examples/201/web-app-loganalytics-mod/log-analytics.bicep @@ -0,0 +1,19 @@ +param location string = resourceGroup().location + +param appName string +var logAnalyticsName = toLower('la-${appName}') +resource logAnalyticsWorkspace 'Microsoft.OperationalInsights/workspaces@2020-03-01-preview' = { + name: logAnalyticsName + location: location + tags: { + displayName: 'Log Analytics' + ProjectName: appName + } + properties: { + sku: { + name: 'PerGB2018' + } + retentionInDays: 120 + } +} +output logAnalaticsWorkspaceResourceID string = logAnalyticsWorkspace.id diff --git a/docs/examples/201/web-app-loganalytics-mod/log-analytics.json b/docs/examples/201/web-app-loganalytics-mod/log-analytics.json new file mode 100644 index 00000000000..8da734074b4 --- /dev/null +++ b/docs/examples/201/web-app-loganalytics-mod/log-analytics.json @@ -0,0 +1,41 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "location": { + "type": "string", + "defaultValue": "[resourceGroup().location]" + }, + "appName": { + "type": "string" + } + }, + "functions": [], + "variables": { + "logAnalyticsName": "[toLower(format('la-{0}', parameters('appName')))]" + }, + "resources": [ + { + "type": "Microsoft.OperationalInsights/workspaces", + "apiVersion": "2020-03-01-preview", + "name": "[variables('logAnalyticsName')]", + "location": "[parameters('location')]", + "tags": { + "displayName": "Log Analytics", + "ProjectName": "[parameters('appName')]" + }, + "properties": { + "sku": { + "name": "PerGB2018" + }, + "retentionInDays": 120 + } + } + ], + "outputs": { + "logAnalaticsWorkspaceResourceID": { + "type": "string", + "value": "[resourceId('Microsoft.OperationalInsights/workspaces', variables('logAnalyticsName'))]" + } + } +} \ No newline at end of file diff --git a/docs/examples/201/web-app-loganalytics-mod/main.bicep b/docs/examples/201/web-app-loganalytics-mod/main.bicep new file mode 100644 index 00000000000..3706d67b106 --- /dev/null +++ b/docs/examples/201/web-app-loganalytics-mod/main.bicep @@ -0,0 +1,32 @@ +param appName string = uniqueString(resourceGroup().id) + +module appServicePlanModule './app-service-plan.bicep' = { + name: 'appServicePlanDeploy' + params: { + appName: appName + } +} + +module appServiceModule './app-service.bicep' = { + name: 'appServiceDeploy' + params: { + appName: appName + appServicePlanID: appServicePlanModule.outputs.appServicePlanID + APPINSIGHTS_INSTRUMENTATIONKEY: appInsightsModule.outputs.APPINSIGHTS_INSTRUMENTATIONKEY + } +} + +module appInsightsModule './app-insights.bicep' = { + name: 'appInsightsDeploy' + params: { + appName: appName + logAnalaticsWorkspaceResourceID: logAnalyticsWorkspace.outputs.logAnalaticsWorkspaceResourceID + } +} + +module logAnalyticsWorkspace './log-analytics.bicep' = { + name: 'logAnalyticsWorkspaceDeploy' + params: { + appName: appName + } +} diff --git a/docs/examples/201/web-app-loganalytics-mod/main.json b/docs/examples/201/web-app-loganalytics-mod/main.json new file mode 100644 index 00000000000..b1f130af47d --- /dev/null +++ b/docs/examples/201/web-app-loganalytics-mod/main.json @@ -0,0 +1,315 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "appName": { + "type": "string", + "defaultValue": "[uniqueString(resourceGroup().id)]" + } + }, + "functions": [], + "resources": [ + { + "type": "Microsoft.Resources/deployments", + "apiVersion": "2019-10-01", + "name": "appServicePlanDeploy", + "properties": { + "expressionEvaluationOptions": { + "scope": "inner" + }, + "mode": "Incremental", + "parameters": { + "appName": { + "value": "[parameters('appName')]" + } + }, + "template": { + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "skuName": { + "type": "string", + "defaultValue": "S1" + }, + "skuCapacity": { + "type": "int", + "defaultValue": 1 + }, + "location": { + "type": "string", + "defaultValue": "[resourceGroup().location]" + }, + "appName": { + "type": "string" + } + }, + "functions": [], + "variables": { + "appServicePlanName": "[toLower(format('asp-{0}', parameters('appName')))]" + }, + "resources": [ + { + "type": "Microsoft.Web/serverfarms", + "apiVersion": "2020-06-01", + "name": "[variables('appServicePlanName')]", + "location": "[parameters('location')]", + "sku": { + "name": "[parameters('skuName')]", + "capacity": "[parameters('skuCapacity')]" + }, + "tags": { + "displayName": "HostingPlan", + "ProjectName": "[parameters('appName')]" + } + } + ], + "outputs": { + "appServicePlanID": { + "type": "string", + "value": "[resourceId('Microsoft.Web/serverfarms', variables('appServicePlanName'))]" + } + } + } + } + }, + { + "type": "Microsoft.Resources/deployments", + "apiVersion": "2019-10-01", + "name": "appServiceDeploy", + "properties": { + "expressionEvaluationOptions": { + "scope": "inner" + }, + "mode": "Incremental", + "parameters": { + "appName": { + "value": "[parameters('appName')]" + }, + "appServicePlanID": { + "value": "[reference(extensionResourceId(resourceGroup().id, 'Microsoft.Resources/deployments', 'appServicePlanDeploy'), '2019-10-01').outputs.appServicePlanID.value]" + }, + "APPINSIGHTS_INSTRUMENTATIONKEY": { + "value": "[reference(extensionResourceId(resourceGroup().id, 'Microsoft.Resources/deployments', 'appInsightsDeploy'), '2019-10-01').outputs.APPINSIGHTS_INSTRUMENTATIONKEY.value]" + } + }, + "template": { + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "location": { + "type": "string", + "defaultValue": "[resourceGroup().location]" + }, + "appName": { + "type": "string" + }, + "appServicePlanID": { + "type": "string" + }, + "APPINSIGHTS_INSTRUMENTATIONKEY": { + "type": "string" + } + }, + "functions": [], + "variables": { + "webSiteName": "[toLower(format('wapp-{0}', parameters('appName')))]" + }, + "resources": [ + { + "type": "Microsoft.Web/sites", + "apiVersion": "2020-06-01", + "name": "[variables('webSiteName')]", + "location": "[parameters('location')]", + "identity": { + "type": "SystemAssigned" + }, + "tags": { + "displayName": "Website", + "ProjectName": "[parameters('appName')]" + }, + "properties": { + "serverFarmId": "[parameters('appServicePlanID')]", + "httpsOnly": true, + "siteConfig": { + "minTlsVersion": "1.2" + } + } + }, + { + "type": "Microsoft.Web/sites/config", + "apiVersion": "2020-06-01", + "name": "[format('{0}/logs', variables('webSiteName'))]", + "properties": { + "applicationLogs": { + "fileSystem": { + "level": "Warning" + } + }, + "httpLogs": { + "fileSystem": { + "retentionInMb": 40, + "enabled": true + } + }, + "failedRequestsTracing": { + "enabled": true + }, + "detailedErrorMessages": { + "enabled": true + } + }, + "dependsOn": [ + "[resourceId('Microsoft.Web/sites', variables('webSiteName'))]" + ] + }, + { + "type": "Microsoft.Web/sites/config", + "apiVersion": "2020-06-01", + "name": "[format('{0}/appsettings', variables('webSiteName'))]", + "properties": { + "APPINSIGHTS_INSTRUMENTATIONKEY": "[parameters('APPINSIGHTS_INSTRUMENTATIONKEY')]" + }, + "dependsOn": [ + "[resourceId('Microsoft.Web/sites', variables('webSiteName'))]" + ] + }, + { + "type": "Microsoft.Web/sites/siteextensions", + "apiVersion": "2020-06-01", + "name": "[format('{0}/Microsoft.ApplicationInsights.AzureWebsites', variables('webSiteName'))]", + "dependsOn": [ + "[resourceId('Microsoft.Web/sites', variables('webSiteName'))]" + ] + } + ] + } + }, + "dependsOn": [ + "[extensionResourceId(resourceGroup().id, 'Microsoft.Resources/deployments', 'appInsightsDeploy')]", + "[extensionResourceId(resourceGroup().id, 'Microsoft.Resources/deployments', 'appServicePlanDeploy')]" + ] + }, + { + "type": "Microsoft.Resources/deployments", + "apiVersion": "2019-10-01", + "name": "appInsightsDeploy", + "properties": { + "expressionEvaluationOptions": { + "scope": "inner" + }, + "mode": "Incremental", + "parameters": { + "appName": { + "value": "[parameters('appName')]" + }, + "logAnalaticsWorkspaceResourceID": { + "value": "[reference(extensionResourceId(resourceGroup().id, 'Microsoft.Resources/deployments', 'logAnalyticsWorkspaceDeploy'), '2019-10-01').outputs.logAnalaticsWorkspaceResourceID.value]" + } + }, + "template": { + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "location": { + "type": "string", + "defaultValue": "[resourceGroup().location]" + }, + "appName": { + "type": "string" + }, + "logAnalaticsWorkspaceResourceID": { + "type": "string" + } + }, + "functions": [], + "variables": { + "appInsightName": "[toLower(format('appi-{0}', parameters('appName')))]" + }, + "resources": [ + { + "type": "Microsoft.Insights/components", + "apiVersion": "2020-02-02-preview", + "name": "[variables('appInsightName')]", + "location": "[parameters('location')]", + "kind": "string", + "tags": { + "displayName": "AppInsight", + "ProjectName": "[parameters('appName')]" + }, + "properties": { + "Application_Type": "web", + "WorkspaceResourceId": "[parameters('logAnalaticsWorkspaceResourceID')]" + } + } + ], + "outputs": { + "APPINSIGHTS_INSTRUMENTATIONKEY": { + "type": "string", + "value": "[reference(resourceId('Microsoft.Insights/components', variables('appInsightName'))).InstrumentationKey]" + } + } + } + }, + "dependsOn": [ + "[extensionResourceId(resourceGroup().id, 'Microsoft.Resources/deployments', 'logAnalyticsWorkspaceDeploy')]" + ] + }, + { + "type": "Microsoft.Resources/deployments", + "apiVersion": "2019-10-01", + "name": "logAnalyticsWorkspaceDeploy", + "properties": { + "expressionEvaluationOptions": { + "scope": "inner" + }, + "mode": "Incremental", + "parameters": { + "appName": { + "value": "[parameters('appName')]" + } + }, + "template": { + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "location": { + "type": "string", + "defaultValue": "[resourceGroup().location]" + }, + "appName": { + "type": "string" + } + }, + "functions": [], + "variables": { + "logAnalyticsName": "[toLower(format('la-{0}', parameters('appName')))]" + }, + "resources": [ + { + "type": "Microsoft.OperationalInsights/workspaces", + "apiVersion": "2020-03-01-preview", + "name": "[variables('logAnalyticsName')]", + "location": "[parameters('location')]", + "tags": { + "displayName": "Log Analytics", + "ProjectName": "[parameters('appName')]" + }, + "properties": { + "sku": { + "name": "PerGB2018" + }, + "retentionInDays": 120 + } + } + ], + "outputs": { + "logAnalaticsWorkspaceResourceID": { + "type": "string", + "value": "[resourceId('Microsoft.OperationalInsights/workspaces', variables('logAnalyticsName'))]" + } + } + } + } + } + ] +} \ No newline at end of file diff --git a/docs/examples/index.json b/docs/examples/index.json index 9db272782e7..39d1f7682a9 100644 --- a/docs/examples/index.json +++ b/docs/examples/index.json @@ -351,6 +351,10 @@ "filePath": "201/web-app-loganalytics/main.bicep", "description": "201/web-app-loganalytics" }, + { + "filePath": "201/web-app-loganalytics-mod/main.bicep", + "description": "201/web-app-loganalytics-mod" + }, { "filePath": "201/web-app-sql-database/main.bicep", "description": "201/web-app-sql-database"