Skip to content

Commit bac8169

Browse files
Location specific resource creation (#82)
* Reset functionality of the Get-WinGetManifest (File) functionality Single Application Manifest(s) only. * Regions are adhered for for Azure object creation. Co-authored-by: jamespik <[email protected]>
1 parent 966028a commit bac8169

File tree

3 files changed

+270
-5
lines changed

3 files changed

+270
-5
lines changed
Lines changed: 261 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,261 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT License.
3+
4+
Function Get-PairedAzureRegion
5+
{
6+
PARAM(
7+
[Parameter(Position=0, Mandatory=$true)] [string]$Region
8+
)
9+
BEGIN
10+
{
11+
$LocationList = Get-AzLocation
12+
}
13+
PROCESS
14+
{
15+
if($Region -like "*us*" -and $Region -notlike "*australia*") {
16+
switch ($Region) {
17+
"eastus" {
18+
$Result = "westus"
19+
}
20+
"westus" {
21+
$Result = "eastus"
22+
}
23+
"eastus2" {
24+
$Result = "centralus"
25+
}
26+
"centralus" {
27+
$Result = "eastus2"
28+
}
29+
"northcentralus" {
30+
$Result = "southcentralus"
31+
}
32+
"southcentralus" {
33+
$Result = "northcentralus"
34+
}
35+
"westus2" {
36+
$Result = "westcentralus"
37+
}
38+
"westcentralus" {
39+
$Result = "westus2"
40+
}
41+
"westus3" {
42+
$Result = "westcentralus"
43+
}
44+
Default {
45+
$Result = "westus"
46+
}
47+
}
48+
}
49+
elseif($Region -like "*canada*") {
50+
switch ($Region) {
51+
"canadacentral" {
52+
$Result = "canadaeast"
53+
}
54+
"canadaeast" {
55+
$Result = "canadacentral"
56+
}
57+
Default {
58+
$Result = "canadacentral"
59+
}
60+
}
61+
}
62+
elseif($Region -like "*asia*") {
63+
switch ($Region) {
64+
"eastasia" {
65+
$Result = "southeastasia"
66+
}
67+
"southeastasia" {
68+
$Result = "eastasia"
69+
}
70+
Default {
71+
$Result = "eastasia"
72+
}
73+
}
74+
}
75+
elseif($Region -like "*japan*") {
76+
switch ($Region) {
77+
"japanwest" {
78+
$Result = "japaneast"
79+
}
80+
"japaneast" {
81+
$Result = "japanwest"
82+
}
83+
Default {
84+
$Result = "japanwest"
85+
}
86+
}
87+
}
88+
elseif($Region -like "*europe*") {
89+
switch ($Region) {
90+
"northeurope" {
91+
$Result = "westeurope"
92+
}
93+
"westeurope" {
94+
$Result = "northeurope"
95+
}
96+
Default {
97+
$Result = "westeurope"
98+
}
99+
}
100+
}
101+
elseif($Region -like "*brazil*") {
102+
switch ($Region) {
103+
"brazilsouth" {
104+
$Result = "brazilsoutheast"
105+
}
106+
"brazilsoutheast" {
107+
$Result = "brazilsouth"
108+
}
109+
Default {
110+
$Result = "brazilsoutheast"
111+
}
112+
}
113+
}
114+
elseif($Region -like "*australia*") {
115+
switch ($Region) {
116+
"australiaeast" {
117+
$Result = "australiasoutheast"
118+
}
119+
"australiasoutheast" {
120+
$Result = "australiaeast"
121+
}
122+
"australiacentral" {
123+
$Result = "australiacentral2"
124+
}
125+
"australiacentral2" {
126+
$Result = "australiacentral"
127+
}
128+
Default {
129+
$Result = "australiasoutheast"
130+
}
131+
}
132+
}
133+
elseif($Region -like "*india*") {
134+
switch ($Region) {
135+
"westindia" {
136+
$Result = "southindia"
137+
}
138+
"centralindia" {
139+
$Result = "southindia"
140+
}
141+
"southindia" {
142+
$Result = "centralindia"
143+
}
144+
Default {
145+
$Result = "southindia"
146+
}
147+
}
148+
}
149+
elseif($Region -like "*uk*") {
150+
switch ($Region) {
151+
"uksouth" {
152+
$Result = "ukwest"
153+
}
154+
"ukwest" {
155+
$Result = "uksouth"
156+
}
157+
Default {
158+
$Result = "uksouth"
159+
}
160+
}
161+
}
162+
elseif($Region -like "*korea*") {
163+
switch ($Region) {
164+
"koreacentral" {
165+
$Result = "koreasouth"
166+
}
167+
"koreasouth" {
168+
$Result = "koreacentral"
169+
}
170+
Default {
171+
$Result = "koreacentral"
172+
}
173+
}
174+
}
175+
elseif($Region -like "*france*") {
176+
switch ($Region) {
177+
"francecentral" {
178+
$Result = "francesouth"
179+
}
180+
"francesouth" {
181+
$Result = "francecentral"
182+
}
183+
Default {
184+
$Result = "francecentral"
185+
}
186+
}
187+
}
188+
elseif($Region -like "*africa*") {
189+
switch ($Region) {
190+
"southafricanorth" {
191+
$Result = "southafricawest"
192+
}
193+
"southafricawest" {
194+
$Result = "southafricanorth"
195+
}
196+
Default {
197+
$Result = "southafricanorth"
198+
}
199+
}
200+
}
201+
elseif($Region -like "*switzerland*") {
202+
switch ($Region) {
203+
"switzerlandnorth" {
204+
$Result = "switzerlandwest"
205+
}
206+
"switzerlandwest" {
207+
$Result = "switzerlandnorth"
208+
}
209+
Default {
210+
$Result = "switzerlandwest"
211+
}
212+
}
213+
}
214+
elseif($Region -like "*germany*") {
215+
switch ($Region) {
216+
"germanynorth" {
217+
$Result = "germanywestcentral"
218+
}
219+
"germanywestcentral" {
220+
$Result = "germanynorth"
221+
}
222+
Default {
223+
$Result = "germanywestcentral"
224+
}
225+
}
226+
}
227+
elseif($Region -like "*norway*") {
228+
switch ($Region) {
229+
"norwaywest" {
230+
$Result = "norwayeast"
231+
}
232+
"norwayeast" {
233+
$Result = "norwaywest"
234+
}
235+
Default {
236+
$Result = "norwaywest"
237+
}
238+
}
239+
}
240+
elseif($Region -like "*uae*") {
241+
switch ($Region) {
242+
"uaecentral" {
243+
$Result = "uaenorth"
244+
}
245+
"uaenorth" {
246+
$Result = "uaecentral"
247+
}
248+
Default {
249+
$Result = "uaecentral"
250+
}
251+
}
252+
}
253+
else {
254+
$Result = "westus"
255+
}
256+
}
257+
END
258+
{
259+
Return $Result
260+
}
261+
}

Tools/PowershellModule/src/Library/New-ARMParameterObject.ps1

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ Function New-ARMParameterObject
106106
$CosmosDBACapabilities = "[]"
107107
}
108108
}
109+
110+
$PrimaryRegionName = $(Get-AzLocation).Where({$_.Location -eq $Region}).DisplayName
111+
$SecondaryRegion = Get-PairedAzureRegion -Region $Region
112+
$SecondaryRegionName = $(Get-AzLocation).Where({$_.Location -eq $SecondaryRegion}).DisplayName
109113

110114
## The name of the Secret that will be created in the Azure Keyvault - Do not change
111115
$AzKVStorageSecretName = "AzStorageAccountKey"
@@ -223,12 +227,12 @@ Function New-ARMParameterObject
223227
locations = @{
224228
value = @(
225229
@{
226-
locationName = "West US"
230+
locationName = $PrimaryRegionName
227231
failoverPriority = 0
228232
isZoneRedundant = $false
229233
}
230234
@{
231-
locationName = "East US"
235+
locationName = $SecondaryRegionName
232236
failoverPriority = 1
233237
isZoneRedundant = $false
234238
}

Tools/PowershellModule/src/Library/Test-ARMTemplate.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,17 @@ Function Test-ARMTemplate
5353

5454
if($AzResourceResult -ne "") {
5555
if($AzNameResult) {
56-
$ErrorMessage = "$($Object.ObjectType) Name is already in use, or there is an error with the Parameter file"
56+
$ErrorMessage = "$($Object.ObjectType) name is already in use, or there is an error with the Parameter file"
5757
Write-Verbose "Name is already in use."
5858
Write-Error -Message $ErrorMessage -TargetObject $ErrReturnObject
5959
}
6060
else {
61-
Write-Error -Message "$($Object.ObjectType) Name does not meet the requirements" -TargetObject $ErrReturnObject
61+
Write-Error -Message "$($Object.ObjectType) name does not meet the requirements" -TargetObject $ErrReturnObject
6262
}
6363
}
6464
ElseIF(!$AzNameResult)
6565
{
66-
Write-Error "$($Object.ObjectType) Name does not meet the requirements." -TargetObject $ErrReturnObject
66+
Write-Error "$($Object.ObjectType) name does not meet the requirements." -TargetObject $ErrReturnObject
6767
}
6868

6969
$TestResult = @{

0 commit comments

Comments
 (0)