Skip to content

Commit 80ac1f2

Browse files
feat: added feature to use azure_location environment variable for deployment with fallback to resource group location
feat: added feature to use azure_location environment variable for deployment with fallback to resource group location
2 parents f28f718 + 9f120ee commit 80ac1f2

7 files changed

Lines changed: 93 additions & 25 deletions

infra/deploy_app_service.bicep

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ targetScope = 'resourceGroup'
44
@description('Solution Name')
55
param solutionName string
66

7+
@description('Solution Location')
8+
param solutionLocation string
9+
710
@secure()
811
param appSettings object = {}
912
param appServicePlanId string
@@ -12,7 +15,7 @@ param userassignedIdentityId string = ''
1215

1316
resource appService 'Microsoft.Web/sites@2020-06-01' = {
1417
name: solutionName
15-
location: resourceGroup().location
18+
location: solutionLocation
1619
identity: userassignedIdentityId == '' ? {
1720
type: 'SystemAssigned'
1821
} : {

infra/deploy_app_service_plan.bicep

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
metadata description = 'Creates an Azure App Service plan.'
22
param solutionName string
33

4+
@description('Solution Location')
5+
param solutionLocation string
6+
47
@description('Name of App Service plan')
58
param HostingPlanName string = '${ solutionName }-app-service-plan'
69

@@ -12,7 +15,7 @@ param HostingPlanSku string = 'B2'
1215

1316
resource HostingPlan 'Microsoft.Web/serverfarms@2020-06-01' = {
1417
name: HostingPlanName
15-
location: resourceGroup().location
18+
location: solutionLocation
1619
sku: {
1720
name: HostingPlanSku
1821
}

infra/deploy_backend_docker.bicep

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
param imageTag string
22
param applicationInsightsId string
33
param solutionName string
4+
5+
@description('Solution Location')
6+
param solutionLocation string
7+
48
@secure()
59
param appSettings object = {}
610
param appServicePlanId string
@@ -84,6 +88,7 @@ module appService 'deploy_app_service.bicep' = {
8488
name: '${name}-app-module'
8589
params: {
8690
solutionName: name
91+
solutionLocation:solutionLocation
8792
appServicePlanId: appServicePlanId
8893
appImageName: imageName
8994
userassignedIdentityId:userassignedIdentityId

infra/deploy_frontend_docker.bicep

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
param imageTag string
22
param applicationInsightsId string
33
param solutionName string
4+
5+
@description('Solution Location')
6+
param solutionLocation string
7+
48
@secure()
59
param appSettings object = {}
610
param appServicePlanId string
@@ -11,6 +15,7 @@ var name = '${solutionName}-app'
1115
module appService 'deploy_app_service.bicep' = {
1216
name: '${name}-app-module'
1317
params: {
18+
solutionLocation:solutionLocation
1419
solutionName: name
1520
appServicePlanId: appServicePlanId
1621
appImageName: imageName

infra/main.bicep

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ param embeddingDeploymentCapacity int = 80
6565

6666
param imageTag string = 'latest_migrated'
6767

68-
var uniqueId = toLower(uniqueString(subscription().id, environmentName, resourceGroup().location))
68+
param AZURE_LOCATION string=''
69+
var solutionLocation = empty(AZURE_LOCATION) ? resourceGroup().location : AZURE_LOCATION
70+
71+
var uniqueId = toLower(uniqueString(subscription().id, environmentName, solutionLocation))
6972
var solutionPrefix = 'km${padLeft(take(uniqueId, 12), 12, '0')}'
70-
var resourceGroupLocation = resourceGroup().location
7173
// var resourceGroupName = resourceGroup().name
7274

73-
var solutionLocation = resourceGroupLocation
74-
7575
// ========== Managed Identity ========== //
7676
module managedIdentityModule 'deploy_managed_identity.bicep' = {
7777
name: 'deploy_managed_identity'
@@ -87,7 +87,7 @@ module kvault 'deploy_keyvault.bicep' = {
8787
name: 'deploy_keyvault'
8888
params: {
8989
solutionName: solutionPrefix
90-
solutionLocation: resourceGroupLocation
90+
solutionLocation: solutionLocation
9191
managedIdentityObjectId:managedIdentityModule.outputs.managedIdentityOutput.objectId
9292
}
9393
scope: resourceGroup(resourceGroup().name)
@@ -98,7 +98,7 @@ module aifoundry 'deploy_ai_foundry.bicep' = {
9898
name: 'deploy_ai_foundry'
9999
params: {
100100
solutionName: solutionPrefix
101-
solutionLocation: resourceGroupLocation
101+
solutionLocation: solutionLocation
102102
keyVaultName: kvault.outputs.keyvaultName
103103
cuLocation: contentUnderstandingLocation
104104
deploymentType: deploymentType
@@ -188,12 +188,14 @@ module hostingplan 'deploy_app_service_plan.bicep' = {
188188
name: 'deploy_app_service_plan'
189189
params: {
190190
solutionName: solutionPrefix
191+
solutionLocation: solutionLocation
191192
}
192193
}
193194

194195
module backend_docker 'deploy_backend_docker.bicep'= {
195196
name: 'deploy_backend_docker'
196197
params: {
198+
solutionLocation: solutionLocation
197199
imageTag: imageTag
198200
appServicePlanId: hostingplan.outputs.name
199201
applicationInsightsId: aifoundry.outputs.applicationInsightsId
@@ -231,6 +233,7 @@ module backend_docker 'deploy_backend_docker.bicep'= {
231233
module frontend_docker 'deploy_frontend_docker.bicep'= {
232234
name: 'deploy_frontend_docker'
233235
params: {
236+
solutionLocation:solutionLocation
234237
imageTag: imageTag
235238
appServicePlanId: hostingplan.outputs.name
236239
applicationInsightsId: aifoundry.outputs.applicationInsightsId
@@ -244,7 +247,7 @@ module frontend_docker 'deploy_frontend_docker.bicep'= {
244247

245248
output SOLUTION_NAME string = solutionPrefix
246249
output RESOURCE_GROUP_NAME string = resourceGroup().name
247-
output RESOURCE_GROUP_LOCATION string = resourceGroupLocation
250+
output RESOURCE_GROUP_LOCATION string = solutionLocation
248251
output ENVIRONMENT_NAME string = environmentName
249252
output AZURE_CONTENT_UNDERSTANDING_LOCATION string = contentUnderstandingLocation
250253
output AZURE_SECONDARY_LOCATION string = secondaryLocation

infra/main.bicepparam

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using './main.bicep'
22

3+
param AZURE_LOCATION = readEnvironmentVariable('AZURE_LOCATION', '')
34
param environmentName = readEnvironmentVariable('AZURE_ENV_NAME', 'env_name')
45
param contentUnderstandingLocation = readEnvironmentVariable('AZURE_CONTENT_UNDERSTANDING_LOCATION', 'swedencentral')
56
param secondaryLocation = readEnvironmentVariable('AZURE_SECONDARY_LOCATION', 'eastus2')

infra/main.json

Lines changed: 64 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"_generator": {
66
"name": "bicep",
77
"version": "0.34.44.8038",
8-
"templateHash": "16954169516642030194"
8+
"templateHash": "6194079026370260064"
99
}
1010
},
1111
"parameters": {
@@ -93,14 +93,17 @@
9393
"imageTag": {
9494
"type": "string",
9595
"defaultValue": "latest_migrated"
96+
},
97+
"AZURE_LOCATION": {
98+
"type": "string",
99+
"defaultValue": ""
96100
}
97101
},
98102
"variables": {
99103
"azureOpenAIApiVersion": "2024-02-15-preview",
100-
"uniqueId": "[toLower(uniqueString(subscription().id, parameters('environmentName'), resourceGroup().location))]",
101-
"solutionPrefix": "[format('km{0}', padLeft(take(variables('uniqueId'), 12), 12, '0'))]",
102-
"resourceGroupLocation": "[resourceGroup().location]",
103-
"solutionLocation": "[variables('resourceGroupLocation')]"
104+
"solutionLocation": "[if(empty(parameters('AZURE_LOCATION')), resourceGroup().location, parameters('AZURE_LOCATION'))]",
105+
"uniqueId": "[toLower(uniqueString(subscription().id, parameters('environmentName'), variables('solutionLocation')))]",
106+
"solutionPrefix": "[format('km{0}', padLeft(take(variables('uniqueId'), 12), 12, '0'))]"
104107
},
105108
"resources": [
106109
{
@@ -227,7 +230,7 @@
227230
"value": "[variables('solutionPrefix')]"
228231
},
229232
"solutionLocation": {
230-
"value": "[variables('resourceGroupLocation')]"
233+
"value": "[variables('solutionLocation')]"
231234
},
232235
"managedIdentityObjectId": {
233236
"value": "[reference(extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, resourceGroup().name), 'Microsoft.Resources/deployments', 'deploy_managed_identity'), '2022-09-01').outputs.managedIdentityOutput.value.objectId]"
@@ -349,7 +352,7 @@
349352
"value": "[variables('solutionPrefix')]"
350353
},
351354
"solutionLocation": {
352-
"value": "[variables('resourceGroupLocation')]"
355+
"value": "[variables('solutionLocation')]"
353356
},
354357
"keyVaultName": {
355358
"value": "[reference(extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, resourceGroup().name), 'Microsoft.Resources/deployments', 'deploy_keyvault'), '2022-09-01').outputs.keyvaultName.value]"
@@ -1595,6 +1598,9 @@
15951598
"parameters": {
15961599
"solutionName": {
15971600
"value": "[variables('solutionPrefix')]"
1601+
},
1602+
"solutionLocation": {
1603+
"value": "[variables('solutionLocation')]"
15981604
}
15991605
},
16001606
"template": {
@@ -1604,14 +1610,20 @@
16041610
"_generator": {
16051611
"name": "bicep",
16061612
"version": "0.34.44.8038",
1607-
"templateHash": "5000589525239764864"
1613+
"templateHash": "9333076050504873128"
16081614
},
16091615
"description": "Creates an Azure App Service plan."
16101616
},
16111617
"parameters": {
16121618
"solutionName": {
16131619
"type": "string"
16141620
},
1621+
"solutionLocation": {
1622+
"type": "string",
1623+
"metadata": {
1624+
"description": "Solution Location"
1625+
}
1626+
},
16151627
"HostingPlanName": {
16161628
"type": "string",
16171629
"defaultValue": "[format('{0}-app-service-plan', parameters('solutionName'))]",
@@ -1647,7 +1659,7 @@
16471659
"type": "Microsoft.Web/serverfarms",
16481660
"apiVersion": "2020-06-01",
16491661
"name": "[parameters('HostingPlanName')]",
1650-
"location": "[resourceGroup().location]",
1662+
"location": "[parameters('solutionLocation')]",
16511663
"sku": {
16521664
"name": "[parameters('HostingPlanSku')]"
16531665
},
@@ -1681,6 +1693,9 @@
16811693
},
16821694
"mode": "Incremental",
16831695
"parameters": {
1696+
"solutionLocation": {
1697+
"value": "[variables('solutionLocation')]"
1698+
},
16841699
"imageTag": {
16851700
"value": "[parameters('imageTag')]"
16861701
},
@@ -1753,7 +1768,7 @@
17531768
"_generator": {
17541769
"name": "bicep",
17551770
"version": "0.34.44.8038",
1756-
"templateHash": "14001159014642291962"
1771+
"templateHash": "14415535620383822032"
17571772
}
17581773
},
17591774
"parameters": {
@@ -1766,6 +1781,12 @@
17661781
"solutionName": {
17671782
"type": "string"
17681783
},
1784+
"solutionLocation": {
1785+
"type": "string",
1786+
"metadata": {
1787+
"description": "Solution Location"
1788+
}
1789+
},
17691790
"appSettings": {
17701791
"type": "secureObject",
17711792
"defaultValue": {}
@@ -1834,6 +1855,9 @@
18341855
"solutionName": {
18351856
"value": "[variables('name')]"
18361857
},
1858+
"solutionLocation": {
1859+
"value": "[parameters('solutionLocation')]"
1860+
},
18371861
"appServicePlanId": {
18381862
"value": "[parameters('appServicePlanId')]"
18391863
},
@@ -1854,7 +1878,7 @@
18541878
"_generator": {
18551879
"name": "bicep",
18561880
"version": "0.34.44.8038",
1857-
"templateHash": "356166454386735487"
1881+
"templateHash": "13414794767040680839"
18581882
}
18591883
},
18601884
"parameters": {
@@ -1864,6 +1888,12 @@
18641888
"description": "Solution Name"
18651889
}
18661890
},
1891+
"solutionLocation": {
1892+
"type": "string",
1893+
"metadata": {
1894+
"description": "Solution Location"
1895+
}
1896+
},
18671897
"appSettings": {
18681898
"type": "secureObject",
18691899
"defaultValue": {}
@@ -1906,7 +1936,7 @@
19061936
"type": "Microsoft.Web/sites",
19071937
"apiVersion": "2020-06-01",
19081938
"name": "[parameters('solutionName')]",
1909-
"location": "[resourceGroup().location]",
1939+
"location": "[parameters('solutionLocation')]",
19101940
"identity": "[if(equals(parameters('userassignedIdentityId'), ''), createObject('type', 'SystemAssigned'), createObject('type', 'SystemAssigned, UserAssigned', 'userAssignedIdentities', createObject(format('{0}', parameters('userassignedIdentityId')), createObject())))]",
19111941
"properties": {
19121942
"serverFarmId": "[parameters('appServicePlanId')]",
@@ -2044,6 +2074,9 @@
20442074
},
20452075
"mode": "Incremental",
20462076
"parameters": {
2077+
"solutionLocation": {
2078+
"value": "[variables('solutionLocation')]"
2079+
},
20472080
"imageTag": {
20482081
"value": "[parameters('imageTag')]"
20492082
},
@@ -2069,7 +2102,7 @@
20692102
"_generator": {
20702103
"name": "bicep",
20712104
"version": "0.34.44.8038",
2072-
"templateHash": "13062487122244574247"
2105+
"templateHash": "5253697335871068015"
20732106
}
20742107
},
20752108
"parameters": {
@@ -2082,6 +2115,12 @@
20822115
"solutionName": {
20832116
"type": "string"
20842117
},
2118+
"solutionLocation": {
2119+
"type": "string",
2120+
"metadata": {
2121+
"description": "Solution Location"
2122+
}
2123+
},
20852124
"appSettings": {
20862125
"type": "secureObject",
20872126
"defaultValue": {}
@@ -2105,6 +2144,9 @@
21052144
},
21062145
"mode": "Incremental",
21072146
"parameters": {
2147+
"solutionLocation": {
2148+
"value": "[parameters('solutionLocation')]"
2149+
},
21082150
"solutionName": {
21092151
"value": "[variables('name')]"
21102152
},
@@ -2125,7 +2167,7 @@
21252167
"_generator": {
21262168
"name": "bicep",
21272169
"version": "0.34.44.8038",
2128-
"templateHash": "356166454386735487"
2170+
"templateHash": "13414794767040680839"
21292171
}
21302172
},
21312173
"parameters": {
@@ -2135,6 +2177,12 @@
21352177
"description": "Solution Name"
21362178
}
21372179
},
2180+
"solutionLocation": {
2181+
"type": "string",
2182+
"metadata": {
2183+
"description": "Solution Location"
2184+
}
2185+
},
21382186
"appSettings": {
21392187
"type": "secureObject",
21402188
"defaultValue": {}
@@ -2177,7 +2225,7 @@
21772225
"type": "Microsoft.Web/sites",
21782226
"apiVersion": "2020-06-01",
21792227
"name": "[parameters('solutionName')]",
2180-
"location": "[resourceGroup().location]",
2228+
"location": "[parameters('solutionLocation')]",
21812229
"identity": "[if(equals(parameters('userassignedIdentityId'), ''), createObject('type', 'SystemAssigned'), createObject('type', 'SystemAssigned, UserAssigned', 'userAssignedIdentities', createObject(format('{0}', parameters('userassignedIdentityId')), createObject())))]",
21822230
"properties": {
21832231
"serverFarmId": "[parameters('appServicePlanId')]",
@@ -2314,7 +2362,7 @@
23142362
},
23152363
"RESOURCE_GROUP_LOCATION": {
23162364
"type": "string",
2317-
"value": "[variables('resourceGroupLocation')]"
2365+
"value": "[variables('solutionLocation')]"
23182366
},
23192367
"ENVIRONMENT_NAME": {
23202368
"type": "string",

0 commit comments

Comments
 (0)