Your environment configuration challenges require systematic infrastructure-as-code practices and runtime validation.
Bicep Template Parameterization: Your current template doesn’t properly define deployment slots as separate resources. Expand your Bicep template to include explicit slot definitions:
resource appService 'Microsoft.Web/sites@2022-03-01' = {
name: appServiceName
properties: {
siteConfig: {
appSettings: baseAppSettings
}
}
}
resource stagingSlot 'Microsoft.Web/sites/slots@2022-03-01' = {
parent: appService
name: 'staging'
properties: {
siteConfig: {
appSettings: union(baseAppSettings, [
{ name: 'ENVIRONMENT', value: 'staging' }
{ name: 'SLOT_NAME', value: 'staging' }
])
}
}
}
Define slot-specific settings using parameter files for each environment. The union() function merges base settings with slot-specific overrides, ensuring consistent configuration structure across slots.
Environment Slot Configuration Management: Implement slot configuration as a two-phase deployment:
Phase 1 - Infrastructure deployment (Bicep template)
Phase 2 - Runtime configuration (Azure CLI)
az webapp config appsettings set \
--resource-group ${resourceGroup} \
--name ${appServiceName} \
--slot staging \
--settings ENVIRONMENT=staging \
--slot-settings ENVIRONMENT
The --slot-settings parameter marks settings as sticky, preventing them from swapping. Apply this configuration immediately after Bicep deployment completes but before any slot swap operations.
Configuration Drift Detection and Remediation: Implement a validation stage in your release pipeline that compares deployed configuration against source-controlled parameter files:
// Drift detection script (PowerShell)
$currentConfig = az webapp config appsettings list \
--name $appName --slot $slotName --output json | ConvertFrom-Json
$expectedConfig = Get-Content ./parameters/prod-config.json | ConvertFrom-Json
$drift = Compare-Object $currentConfig $expectedConfig -Property name,value
if ($drift) {
Write-Error "Configuration drift detected"
# Remediation: Reapply expected configuration
az webapp config appsettings set --settings @parameters/prod-config.json
}
Run this validation before and after slot swaps to ensure configuration integrity. Store drift detection results in pipeline artifacts for audit purposes.
Slot Swap Strategy: Your swap failures occur because slot-specific settings aren’t properly initialized in both slots. Before executing slot swaps, verify:
- All sticky settings exist in both source and target slots
- Non-sticky settings match expected post-swap state
- Application health checks pass in staging slot
- Configuration drift detection shows zero discrepancies
Implement a pre-swap validation task:
{
"task": "AzureCLI@2",
"inputs": {
"scriptType": "pscore",
"scriptLocation": "inlineScript",
"inlineScript": "az webapp deployment slot swap --slot staging --name $(appServiceName) --dry-run"
}
}
The --dry-run flag shows what configuration changes would occur without executing the swap, allowing validation before committing to the operation.
Multi-Release Coordination: For concurrent deployments, implement deployment locks using Azure Resource Manager locks or pipeline environment approvals. Configure exclusive lock mode on your production environment in Azure DevOps, ensuring only one release can deploy at a time. This prevents configuration race conditions when multiple releases target the same slots simultaneously.