Skip to content

Commit

Permalink
Adding Example of modules with deploying web application with log ana…
Browse files Browse the repository at this point in the history
…lytics (#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
  • Loading branch information
JFolberth committed Dec 21, 2020
1 parent 460b88e commit 469cce3
Show file tree
Hide file tree
Showing 11 changed files with 686 additions and 0 deletions.
20 changes: 20 additions & 0 deletions 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
43 changes: 43 additions & 0 deletions 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]"
}
}
}
18 changes: 18 additions & 0 deletions 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
47 changes: 47 additions & 0 deletions 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'))]"
}
}
}
56 changes: 56 additions & 0 deletions 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'
}
91 changes: 91 additions & 0 deletions 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'))]"
]
}
]
}
19 changes: 19 additions & 0 deletions 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
41 changes: 41 additions & 0 deletions 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'))]"
}
}
}
32 changes: 32 additions & 0 deletions 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
}
}

0 comments on commit 469cce3

Please sign in to comment.