-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deploy App Service Plan - MLZ Example (#526)
- Loading branch information
1 parent
6b6e740
commit cdd9c3f
Showing
9 changed files
with
629 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# App Service Plan Example | ||
|
||
This example deploys an App Service Plan (AKA: Web Server Cluster) to support simple web accessible linux docker containers. It also optionally supports the use of dynamic (up and down) scale settings based on CPU percentage up to a max of 10 compute instances. | ||
|
||
Read on to understand what this example does, and when you're ready, collect all of the pre-requisites, then deploy the example. | ||
|
||
## What this example does | ||
|
||
### Deploys an Azure App Service Plan | ||
|
||
The docs on Azure App Service Plans: <https://docs.microsoft.com/en-us/azure/app-service/overview-hosting-plans>. This sample shows how to deploy using Bicep and utilizes the shared file variable pattern to support the deployment. By default, this template will deploy resources into standard default MLZ subscriptions and resource groups. | ||
|
||
The subscription and resource group can be changed by providing the resource group name (Param: targetResourceGroup) and ensuring that the Azure context is set the proper subscription. | ||
|
||
## Pre-requisites | ||
|
||
1. A Mission LZ deployment (a deployment of mlz.bicep) | ||
2. The outputs from a deployment of mlz.bicep (./src/bicep/examples/deploymentVariables.json). | ||
|
||
See below for information on how to create the appropriate deployment variables file for use with this template. | ||
|
||
### Template Parameters | ||
|
||
Template Parameters Name | Description | ||
-----------------------| ----------- | ||
appServicePlanName | The name of the App Service Plan. If not specified, the name will default to the MLZ default naming pattern. | ||
targetResourceGroup | The name of the resource group where the App Service Plan will be deployed. If not specified, the resource group name will default to the shared services MLZ resource group name and subscription. | ||
enableAutoScale | A true/false value that determines if dynamic auto scale is enabled. If set to "true", dynamic auto scale is enabled up to a maximum of 10 compute instances based on CPU percentage exceeding 70% for 10 minutes. Will also scale down if CPU percentage is below 30% for 10 minutes. If set to "false", the App Service Plan will statically maintain two compute instances indefinitely. | ||
|
||
### Generate MLZ Variable File (deploymentVariables.json) | ||
|
||
For instructions on generating 'deploymentVariables.json' using both Azure PowerShell and Azure CLI, please see the [README at the root of the examples folder](..\README.md). | ||
|
||
Place the resulting 'deploymentVariables.json' file within the ./src/bicep/examples folder. | ||
|
||
### Deploying App Service Plan | ||
|
||
Connect to the appropriate Azure Environment and set appropriate context, see getting started with Azure PowerShell for help if needed. The commands below assume you are deploying in Azure Commercial and show the entire process from deploying MLZ and then adding an Azure App Service Plan post-deployment. | ||
|
||
```PowerShell | ||
cd .\src\bicep | ||
Connect-AzAccount | ||
New-AzSubscriptionDeployment -Name contoso -TemplateFile .\mlz.bicep -resourcePrefix 'contoso' -Location 'eastus' | ||
cd .\examples | ||
(Get-AzSubscriptionDeployment -Name contoso).outputs | ConvertTo-Json | Out-File -FilePath .\deploymentVariables.json | ||
cd .\AppServicePlan | ||
New-AzSubscriptionDeployment -DeploymentName deployAppServicePlan -TemplateFile .\appService.bicep -Location 'eastus' | ||
``` | ||
|
||
```Azure CLI | ||
az login | ||
cd src/bicep | ||
az deployment sub create -n contoso -f mlz.bicep -l eastus --parameters resourcePrefix=contoso | ||
cd examples | ||
az deployment sub show -n contoso --query properties.outputs > ./deploymentVariables.json | ||
cd appServicePlan | ||
az deployment sub create -n deployAppServicePlan -f appService.bicep -l eastus | ||
``` | ||
|
||
### References | ||
|
||
* <https://docs.microsoft.com/en-us/azure/app-service/overview-hosting-plans> | ||
* <https://docs.microsoft.com/en-us/azure/azure-resource-manager/bicep/patterns-shared-variable-file> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
Deployes a web server farm(aka: App Service Plan) to support web container deployments for Linux. | ||
Optionally enable dynamic auto scaling based on CPU Percentages using 'enableAutoScale' true/false | ||
*/ | ||
targetScope = 'subscription' | ||
|
||
param mlzDeploymentVariables object = json(loadTextContent('../deploymentVariables.json')) | ||
|
||
@description('The name of the web server farm which will be created. If unchanged or not specified, the MLZ resource prefix + "--ASP" will be utilized.') | ||
param appServicePlanName string = '${mlzDeploymentVariables.mlzResourcePrefix.Value}-asp' | ||
|
||
@description('The name of the resource group in which the app service plan will be deployed. If unchanged or not specified, the MLZ shared services resource group is used.') | ||
param targetResourceGroup string = '${mlzDeploymentVariables.spokes.Value[2].resourceGroupName}' | ||
|
||
@description('If true, enables dynamic scale-in & scale-out based on CPU percentages. If false, then compute instances remain static with 2 instances supporting all traffic') | ||
param enableAutoScale bool = true | ||
|
||
@description('Defines the performance tier of your web farm. By default the performance scale will be premium 2nd generation version 2 "p2v2". Another value would be standard generation 2 "s2".') | ||
param appServiceSkuName string = 'p2v2' | ||
|
||
var targetSubscriptionId_Var = targetResourceGroup == '${mlzDeploymentVariables.spokes.Value[2].resourceGroupName}' ? '${mlzDeploymentVariables.spokes.Value[2].subscriptionId}' : subscription().subscriptionId | ||
var location = deployment().location | ||
var kind = 'linux' | ||
var capacity = 2 | ||
|
||
resource targetASPResourceGroup 'Microsoft.Resources/resourceGroups@2020-10-01' = { | ||
name: targetResourceGroup | ||
location: location | ||
} | ||
|
||
module appServicePlan 'modules/appServicePlan.bicep' = { | ||
name: appServicePlanName | ||
scope: resourceGroup(targetSubscriptionId_Var, targetASPResourceGroup.name) | ||
params: { | ||
location: location | ||
svcPlanName: appServicePlanName | ||
sku: appServiceSkuName | ||
capacity: capacity | ||
kind: kind | ||
} | ||
} | ||
module appServicePlanSettings 'modules/appServiceSettings.bicep' = if (enableAutoScale) { | ||
name: 'appServicePlanSettingsName' | ||
scope: resourceGroup(targetSubscriptionId_Var, targetASPResourceGroup.name) | ||
params: { | ||
location: location | ||
svcPlanName: appServicePlan.outputs.svcPlanName | ||
svcPlanNameID: appServicePlan.outputs.svcPlanID | ||
} | ||
} | ||
output appServicePlanName string = appServicePlanName | ||
output resourceGroupName string = targetResourceGroup |
Oops, something went wrong.