Skip to main content
  1. Posts/

Deploy Azure Azure Web Apps Windows and Linux using Bicep!

·420 words·2 mins
Author
Gregor Suttie
Passionate about all things Azure. Microsoft Azure MVP, blogger, speaker and community enthusiast based in Scotland.

When setting up your infrastructure in Azure, using the Azure Verified Modules can streamline the creation of any Azure Resource such as Azure Web Apps for Windows and Linux with App Service Plans. This post guides you through the code for doing just that, I leave it to you to create the parameters and fill them in :)

//MARK: App Insights Instance @description(‘Create Application Insights Instance’) module createAppInsights ‘br/public:avm/res/insights/component:0.4.1’ = if (deployWebApps) { scope: resourceGroup(resourceGroupArray[2].name) name: ‘createAppInsights’ params: { name: appInsightsName workspaceResourceId: logAnalytics.outputs.resourceId diagnosticSettings: [ { workspaceResourceId: logAnalytics.outputs.resourceId } ] } dependsOn: [ logAnalytics ] }

//MARK: App Service Plan Windows //Deploy an azure web app with App service plan for Windows module appServicePlanWindows ‘br/public:avm/res/web/serverfarm:0.2.4’ = if (deployWebApps) { scope: resourceGroup(resourceGroupArray[2].name) name: ‘appServicePlanWindows’ params: { name: ‘aspwin-${customerName}-${environmentName}-${locationShortCode}’ location: location tags: tags skuName: skuNameAppServicePlanWindows kind: skuKindAppServicePlanWindows skuCapacity: skuCapacityAppServicePlanWindows diagnosticSettings: [ { workspaceResourceId: logAnalytics.outputs.resourceId } ] } dependsOn: [ logAnalytics ] }

//MARK: App Service Windows module appServiceWindows ‘br/public:avm/res/web/site:0.9.0’ = if (deployWebApps) { scope: resourceGroup(resourceGroupArray[2].name) name: ‘appService’ params: { name: ‘appwin-${customerName}-${environmentName}-${locationShortCode}’ kind: ‘app’ location: location tags: tags serverFarmResourceId: appServicePlanWindows.outputs.resourceId managedIdentities: { systemAssigned: false userAssignedResourceIds: [ managedIdentity.id ] } diagnosticSettings: [ { workspaceResourceId: logAnalytics.outputs.resourceId } ] siteConfig: { alwaysOn: true http20Enabled: false appSettings: [ { name: ‘APPINSIGHTS_INSTRUMENTATIONKEY’ value: createAppInsights.outputs.instrumentationKey } ] } appInsightResourceId: createAppInsights.outputs.resourceId } dependsOn: [ logAnalytics appServicePlanWindows createAppInsights ] }

//MARK: App Service Plan Linux //Deploy an azure web app with App service plan for Linux module appServicePlanLinux ‘br/public:avm/res/web/serverfarm:0.2.4’ = if (deployWebApps) { scope: resourceGroup(resourceGroupArray[2].name) name: ‘appServicePlanLinux’ params: { name: ‘asplinux-${customerName}-${environmentName}-${locationShortCode}’ location: location tags: tags skuName: ‘P1v3’ kind: skuKindAppServicePlanLinux zoneRedundant: false diagnosticSettings: [ { workspaceResourceId: logAnalytics.outputs.resourceId } ] } dependsOn: [ logAnalytics ] }

//MARK: App Service Linux module appServiceLinux ‘br/public:avm/res/web/site:0.9.0’ = if (deployWebApps) { scope: resourceGroup(workloadsResourceGroupArray[2].name) name: ‘appServiceLinux’ params: { name: ‘applin-${customerName}-${environmentName}-${locationShortCode}’ kind: ‘app’ location: location tags: tags serverFarmResourceId: appServicePlanLinux.outputs.resourceId managedIdentities: { systemAssigned: false userAssignedResourceIds: [ managedIdentity.id ] } diagnosticSettings: [ { workspaceResourceId: logAnalytics.outputs.resourceId } ] siteConfig: { alwaysOn: true http20Enabled: false appSettings: [ { name: ‘APPINSIGHTS_INSTRUMENTATIONKEY’ value: createAppInsights.outputs.instrumentationKey } ] } appInsightResourceId: createAppInsights.outputs.resourceId } dependsOn: [ logAnalytics appServicePlanLinux createAppInsights ] }

This code will now create an a Windows App Service Plan with a Web App, a Linux App Service Plan with a Web App and also an Application Insights instance and hook up both web apps to the same App Insights instance for monitoring. Yes this code could be tidied up even further but the purpose it so show you how easy it can be to deploy resources using Bicep along with the Azure Verified Modules github repository.

Share this:

Related