Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example of Condition deploy logging resource for Web App #1199

Merged
merged 7 commits into from Dec 21, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 48 additions & 0 deletions docs/examples/201/web-app-conditional-log/logging.bicep
@@ -0,0 +1,48 @@
param appName string
param location string = resourceGroup().location

var appInsightName = toLower('appi-${appName}')
var logAnalyticsName = toLower('la-${appName}')

resource appServiceAppSettings 'Microsoft.Web/sites/config@2020-06-01' = {
name: '${appName}/appsettings'
properties: {
APPINSIGHTS_INSTRUMENTATIONKEY: appInsights.properties.InstrumentationKey
}
dependsOn: [
appInsights
appServiceSiteExtension
]
}
resource appServiceSiteExtension 'Microsoft.Web/sites/siteextensions@2020-06-01' = {
name: '${appName}/Microsoft.ApplicationInsights.AzureWebsites'
dependsOn: [
appInsights
]
}
resource appInsights 'microsoft.insights/components@2020-02-02-preview' = {
name: appInsightName
location: location
kind: 'string'
tags: {
displayName: 'AppInsight'
}
properties: {
Application_Type: 'web'
WorkspaceResourceId: logAnalyticsWorkspace.id
}
}

resource logAnalyticsWorkspace 'Microsoft.OperationalInsights/workspaces@2020-03-01-preview' = {
name: logAnalyticsName
location: location
tags: {
displayName: 'Log Analytics'
}
properties: {
sku: {
name: 'PerGB2018'
}
retentionInDays: 120
}
}
72 changes: 72 additions & 0 deletions docs/examples/201/web-app-conditional-log/logging.json
@@ -0,0 +1,72 @@
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"appName": {
"type": "string"
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]"
}
},
"functions": [],
"variables": {
"appInsightName": "[toLower(format('appi-{0}', parameters('appName')))]",
"logAnalyticsName": "[toLower(format('la-{0}', parameters('appName')))]"
},
"resources": [
{
"type": "Microsoft.Web/sites/config",
"apiVersion": "2020-06-01",
"name": "[format('{0}/appsettings', parameters('appName'))]",
"properties": {
"APPINSIGHTS_INSTRUMENTATIONKEY": "[reference(resourceId('Microsoft.Insights/components', variables('appInsightName'))).InstrumentationKey]"
},
"dependsOn": [
"[resourceId('Microsoft.Insights/components', variables('appInsightName'))]",
"[resourceId('Microsoft.Web/sites/siteextensions', split(format('{0}/Microsoft.ApplicationInsights.AzureWebsites', parameters('appName')), '/')[0], split(format('{0}/Microsoft.ApplicationInsights.AzureWebsites', parameters('appName')), '/')[1])]"
]
},
{
"type": "Microsoft.Web/sites/siteextensions",
"apiVersion": "2020-06-01",
"name": "[format('{0}/Microsoft.ApplicationInsights.AzureWebsites', parameters('appName'))]",
"dependsOn": [
"[resourceId('Microsoft.Insights/components', variables('appInsightName'))]"
]
},
{
"type": "Microsoft.Insights/components",
"apiVersion": "2020-02-02-preview",
"name": "[variables('appInsightName')]",
"location": "[parameters('location')]",
"kind": "string",
"tags": {
"displayName": "AppInsight"
},
"properties": {
"Application_Type": "web",
"WorkspaceResourceId": "[resourceId('Microsoft.OperationalInsights/workspaces', variables('logAnalyticsName'))]"
},
"dependsOn": [
"[resourceId('Microsoft.OperationalInsights/workspaces', variables('logAnalyticsName'))]"
]
},
{
"type": "Microsoft.OperationalInsights/workspaces",
"apiVersion": "2020-03-01-preview",
"name": "[variables('logAnalyticsName')]",
"location": "[parameters('location')]",
"tags": {
"displayName": "Log Analytics"
},
"properties": {
"sku": {
"name": "PerGB2018"
},
"retentionInDays": 120
}
}
]
}
16 changes: 16 additions & 0 deletions docs/examples/201/web-app-conditional-log/main.bicep
@@ -0,0 +1,16 @@
param appName string = uniqueString(resourceGroup().id)
param logging bool = false

module webappModule './webapp.bicep' = {
name: 'webAppPlanDeploy'
params: {
appName: appName
}
}

module loggingModule './logging.bicep' = if (logging) {
name: 'loggingDeploy'
params: {
appName: webappModule.outputs.appServiceName
}
}
231 changes: 231 additions & 0 deletions docs/examples/201/web-app-conditional-log/main.json
@@ -0,0 +1,231 @@
{
"$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)]"
},
"logging": {
"type": "bool",
"defaultValue": false
}
},
"functions": [],
"resources": [
{
"type": "Microsoft.Resources/deployments",
"apiVersion": "2019-10-01",
"name": "webAppPlanDeploy",
"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')))]",
"webSiteName": "[toLower(format('wapp-{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')]"
}
},
{
"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": "[resourceId('Microsoft.Web/serverfarms', variables('appServicePlanName'))]",
"httpsOnly": true,
"siteConfig": {
"minTlsVersion": "1.2"
}
},
"dependsOn": [
"[resourceId('Microsoft.Web/serverfarms', variables('appServicePlanName'))]"
]
},
{
"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'))]"
]
}
],
"outputs": {
"appServiceName": {
"type": "string",
"value": "[variables('webSiteName')]"
}
}
}
}
},
{
"condition": "[parameters('logging')]",
"type": "Microsoft.Resources/deployments",
"apiVersion": "2019-10-01",
"name": "loggingDeploy",
"properties": {
"expressionEvaluationOptions": {
"scope": "inner"
},
"mode": "Incremental",
"parameters": {
"appName": {
"value": "[reference(extensionResourceId(resourceGroup().id, 'Microsoft.Resources/deployments', 'webAppPlanDeploy'), '2019-10-01').outputs.appServiceName.value]"
}
},
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"logging": {
"type": "bool",
"defaultValue": false
},
"appName": {
"type": "string"
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]"
}
},
"functions": [],
"variables": {
"appInsightName": "[toLower(format('appi-{0}', parameters('appName')))]",
"logAnalyticsName": "[toLower(format('la-{0}', parameters('appName')))]"
},
"resources": [
{
"condition": "[parameters('logging')]",
"type": "Microsoft.Web/sites/config",
"apiVersion": "2020-06-01",
"name": "[format('{0}/appsettings', parameters('appName'))]",
"properties": {
"APPINSIGHTS_INSTRUMENTATIONKEY": "[reference(resourceId('Microsoft.Insights/components', variables('appInsightName'))).InstrumentationKey]"
},
"dependsOn": [
"[resourceId('Microsoft.Insights/components', variables('appInsightName'))]",
"[resourceId('Microsoft.Web/sites/siteextensions', split(format('{0}/Microsoft.ApplicationInsights.AzureWebsites', parameters('appName')), '/')[0], split(format('{0}/Microsoft.ApplicationInsights.AzureWebsites', parameters('appName')), '/')[1])]"
]
},
{
"condition": "[parameters('logging')]",
"type": "Microsoft.Web/sites/siteextensions",
"apiVersion": "2020-06-01",
"name": "[format('{0}/Microsoft.ApplicationInsights.AzureWebsites', parameters('appName'))]",
"dependsOn": [
"[resourceId('Microsoft.Insights/components', variables('appInsightName'))]"
]
},
{
"condition": "[parameters('logging')]",
"type": "Microsoft.Insights/components",
"apiVersion": "2020-02-02-preview",
"name": "[variables('appInsightName')]",
"location": "[parameters('location')]",
"kind": "string",
"tags": {
"displayName": "AppInsight"
},
"properties": {
"Application_Type": "web",
"WorkspaceResourceId": "[resourceId('Microsoft.OperationalInsights/workspaces', variables('logAnalyticsName'))]"
},
"dependsOn": [
"[resourceId('Microsoft.OperationalInsights/workspaces', variables('logAnalyticsName'))]"
]
},
{
"condition": "[parameters('logging')]",
"type": "Microsoft.OperationalInsights/workspaces",
"apiVersion": "2020-03-01-preview",
"name": "[variables('logAnalyticsName')]",
"location": "[parameters('location')]",
"tags": {
"displayName": "Log Analytics"
},
"properties": {
"sku": {
"name": "PerGB2018"
},
"retentionInDays": 120
}
}
]
}
},
"dependsOn": [
"[extensionResourceId(resourceGroup().id, 'Microsoft.Resources/deployments', 'webAppPlanDeploy')]"
]
}
]
}