Created
November 12, 2023 22:35
-
-
Save SvenAelterman/2a06dfedcd3a5939981fc84b33a76ab3 to your computer and use it in GitHub Desktop.
DeploymentSlotVNetIntegration
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
[CmdletBinding()] | |
param ( | |
[Parameter(Mandatory)] | |
[string]$TargetSubscriptionId, | |
[Parameter(Mandatory)] | |
[string]$TargetResourceGroup, | |
[Parameter(Mandatory)] | |
[string]$DeploymentLocation | |
) | |
Select-AzSubscription $TargetSubscriptionId | |
$DeploymentResults = New-AzResourceGroupDeployment -ResourceGroupName $TargetResourceGroup -Name "SlotVNetIntegration-$(Get-Date -Format 'yyyyMMddThhmmssZ' -AsUTC)" ` | |
-Location $DeploymentLocation ` | |
-TemplateFile .\main.bicep | |
if ($DeploymentResults.ProvisioningState -eq "Succeeded") { | |
Write-Host "🔥 Deployment successful" | |
} | |
else { | |
$DeploymentResults | |
} |
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
param appSvcName string | |
param location string = resourceGroup().location | |
resource vnet 'Microsoft.Network/virtualNetworks@2022-05-01' = { | |
name: '${appSvcName}-vnet' | |
location: location | |
properties: { | |
addressSpace: { | |
addressPrefixes: [ | |
'10.0.0.0/16' | |
] | |
} | |
subnets: [ | |
{ | |
name: 'AppSvcSubnet' | |
properties: { | |
addressPrefix: '10.0.0.0/24' | |
delegations: [ | |
{ | |
name: 'delegation' | |
properties: { | |
serviceName: 'Microsoft.Web/serverfarms' | |
} | |
} | |
] | |
} | |
}] | |
} | |
} | |
resource appServicePlan 'Microsoft.Web/serverfarms@2022-09-01' = { | |
name: '${appSvcName}-plan' | |
location: location | |
sku: { | |
name: 'S1' | |
tier: 'Standard' | |
size: 'S1' | |
family: 'S' | |
capacity: 1 | |
} | |
kind: 'app' | |
} | |
var appServiceAndSlotCommonProperties = { | |
httpsOnly: true | |
vnetRouteAllEnabled: true | |
siteConfig: { | |
http20Enabled: true | |
alwaysOn: true | |
ftpsState: 'FtpsOnly' | |
use32BitWorkerProcess: false | |
netFrameworkVersion: 'v4.0' | |
logsDirectorySizeLimit: 35 | |
httpLoggingEnabled: true | |
} | |
} | |
// Define the resource properties that are specific to App Service (and don't apply to deployment slots) | |
var appServiceProperties = { | |
enabled: true | |
serverFarmId: appServicePlan.id | |
// IF MOVING THIS PROPERTY TO appServiceAndSlotCommonProperties, deployment fails initially | |
virtualNetworkSubnetId: vnet.properties.subnets[0].id // App Service and its slots need to be integrated | |
} | |
// There are no deployment slot-specific properties to deploy at this time | |
var deploymentSlotProperties = {} | |
resource appService 'Microsoft.Web/sites@2022-09-01' = { | |
location: location | |
name: appSvcName | |
// Merge the properties that are common between the App Service and its slots and the App Service-only properties | |
properties: union(appServiceAndSlotCommonProperties, appServiceProperties) | |
} | |
// Create as many deployment slots as specified in the first level of the deploymentSlotApplicationSettings object tree | |
resource deploymentSlots 'Microsoft.Web/sites/slots@2022-09-01' = { | |
name: 'stage' | |
parent: appService | |
location: location | |
properties: union(appServiceAndSlotCommonProperties, deploymentSlotProperties) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment