Skip to content

Commit c10483a

Browse files
committed
various fixes and improvements
1 parent 125a64c commit c10483a

4 files changed

Lines changed: 189 additions & 23 deletions

File tree

src/ALZ/ALZ.psd1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Included Cmdlets:
4040
- Deploy-Accelerator: Deploys the Azure Landing Zone accelerator to your Azure subscription.
4141
- Grant-SubscriptionCreatorRole: Grants the Subscription Creator role to a specified user or service principal.
4242
- Remove-PlatformLandingZone: Removes the deployed Azure Landing Zone from your Azure subscription
43+
- New-AcceleratorFolderStructure: Creates a new folder structure for the Azure Landing Zone accelerator with necessary configuration files.
4344
'@
4445

4546
CompatiblePSEditions = 'Core'
@@ -85,7 +86,8 @@ Included Cmdlets:
8586
'Test-AcceleratorRequirement',
8687
'Deploy-Accelerator',
8788
'Grant-SubscriptionCreatorRole',
88-
'Remove-PlatformLandingZone'
89+
'Remove-PlatformLandingZone',
90+
'New-AcceleratorFolderStructure'
8991
)
9092

9193
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.

src/ALZ/Private/Deploy-Accelerator-Helpers/New-Bootstrap.ps1

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ function New-Bootstrap {
3434
[Parameter(Mandatory = $false)]
3535
[switch] $destroy,
3636

37-
[Parameter(Mandatory = $false)]
38-
[PSCustomObject] $zonesSupport = $null,
39-
4037
[Parameter(Mandatory = $false, HelpMessage = "An extra level of logging that is turned off by default for easier debugging.")]
4138
[switch]
4239
$writeVerboseLogs,
@@ -172,22 +169,14 @@ function New-Bootstrap {
172169
Source = "calculated"
173170
Sensitive = $false
174171
}
175-
$inputConfig | Add-Member -NotePropertyName "availability_zones_bootstrap" -NotePropertyValue @{
176-
Value = @(Get-AvailabilityZonesSupport -region $inputConfig.bootstrap_location.Value -zonesSupport $zonesSupport)
177-
Source = "calculated"
178-
Sensitive = $false
179-
}
180172

181-
if ($inputConfig.PSObject.Properties.Name -contains "starter_location" -and $inputConfig.PSObject.Properties.Name -notcontains "starter_locations") {
182-
Write-Verbose "Converting starter_location $($inputConfig.starter_location.Value) to starter_locations..."
183-
$inputConfig | Add-Member -NotePropertyName "starter_locations" -NotePropertyValue @{
184-
Value = @($inputConfig.starter_location.Value)
185-
Source = "calculated"
186-
Sensitive = $false
187-
}
188-
}
173+
if ($iac -eq "bicep-classic" -and $inputConfig.PSObject.Properties.Name -contains "starter_locations") {
174+
# Get the supported regions and availability zones
175+
Write-Verbose "Getting Supported Regions and Availability Zones with Terraform"
176+
$regionsAndZones = Get-AzureRegionData -toolsPath $toolsPath
177+
Write-Verbose "Supported Regions: $($regionsAndZones.supportedRegions)"
178+
$zonesSupport = $regionsAndZones.zonesSupport
189179

190-
if ($inputConfig.PSObject.Properties.Name -contains "starter_locations") {
191180
$availabilityZonesStarter = @()
192181
foreach ($region in $inputConfig.starter_locations.Value) {
193182
$availabilityZonesStarter += , @(Get-AvailabilityZonesSupport -region $region -zonesSupport $zonesSupport)

src/ALZ/Public/Deploy-Accelerator.ps1

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,12 @@ function Deploy-Accelerator {
211211

212212
if ($PSCmdlet.ShouldProcess("Accelerator setup", "modify")) {
213213

214+
# Normalize output folder path
215+
if($output_folder_path.StartsWith("~/" )) {
216+
$output_folder_path = Join-Path $HOME $output_folder_path.Replace("~/", "")
217+
}
218+
$output_folder_path = (Resolve-Path -Path $output_folder_path).Path
219+
214220
# Check and install tools needed
215221
$toolsPath = Join-Path -Path $output_folder_path -ChildPath ".tools"
216222
if ($skipInternetChecks) {
@@ -235,6 +241,11 @@ function Deploy-Accelerator {
235241

236242
# Get the input config from yaml and json files
237243
foreach ($inputConfigFilePath in $inputConfigFilePaths) {
244+
if($inputConfigFilePath.StartsWith("~/" )) {
245+
$inputConfigFilePath = Join-Path $HOME $inputConfigFilePath.Replace("~/", "")
246+
}
247+
$inputConfigFilePath = (Resolve-Path -Path $inputConfigFilePath).Path
248+
Write-Verbose "Loading input config from file: $inputConfigFilePath"
238249
$inputConfig = Get-ALZConfig -configFilePath $inputConfigFilePath -inputConfig $inputConfig -hclParserToolPath $hclParserToolPath
239250
}
240251

@@ -259,6 +270,8 @@ function Deploy-Accelerator {
259270
}
260271
$inputConfig = Convert-ParametersToInputConfig -inputConfig $inputConfig -parameters $parametersWithValues
261272

273+
Write-Verbose "Initial Input config: $(ConvertTo-Json $inputConfig -Depth 100)"
274+
262275
# Throw if IAC type is not specified
263276
if (!$inputConfig.iac_type.Value) {
264277
Write-InformationColored "No Infrastructure as Code type has been specified. Please supply the IAC type you wish to deploy..." -ForegroundColor Red -InformationAction Continue
@@ -269,15 +282,17 @@ function Deploy-Accelerator {
269282
Write-InformationColored "Although you have selected Bicep, the Accelerator leverages the Terraform tool to bootstrap your Version Control System and Azure. This will not impact your choice of Bicep post this initial bootstrap. Please refer to our documentation for further details..." -ForegroundColor Yellow -InformationAction Continue
270283
}
271284

272-
Write-Verbose "Initial Input config: $(ConvertTo-Json $inputConfig -Depth 100)"
273-
274285
# Download the bootstrap modules
275286
$bootstrapReleaseTag = ""
276287
$bootstrapPath = ""
277288
$bootstrapTargetFolder = "bootstrap"
278289

279290
Write-InformationColored "Checking and Downloading the bootstrap module..." -ForegroundColor Green -NewLineBefore -InformationAction Continue
280291

292+
if($inputConfig.bootstrap_module_override_folder_path.Value.StartsWith("~/" )) {
293+
$inputConfig.bootstrap_module_override_folder_path.Value = Join-Path $HOME $inputConfig.bootstrap_module_override_folder_path.Value.Replace("~/", "")
294+
}
295+
281296
$versionAndPath = New-ModuleSetup `
282297
-targetDirectory $inputConfig.output_folder_path.Value `
283298
-targetFolder $bootstrapTargetFolder `
@@ -304,7 +319,6 @@ function Deploy-Accelerator {
304319
$starterConfigFilePath = ""
305320

306321
$bootstrapDetails = $null
307-
$zonesSupport = $null
308322

309323
# Request the bootstrap type if not already specified
310324
if(!$inputConfig.bootstrap_module_name.Value) {
@@ -327,7 +341,6 @@ function Deploy-Accelerator {
327341
$starterModuleSourceFolder = $bootstrapAndStarterConfig.starterModuleSourceFolder
328342
$starterReleaseArtifactName = $bootstrapAndStarterConfig.starterReleaseArtifactName
329343
$starterConfigFilePath = $bootstrapAndStarterConfig.starterConfigFilePath
330-
$zonesSupport = $bootstrapAndStarterConfig.zonesSupport
331344

332345
# Download the starter modules
333346
$starterReleaseTag = ""
@@ -336,6 +349,10 @@ function Deploy-Accelerator {
336349
if ($hasStarterModule) {
337350
Write-InformationColored "Checking and downloading the starter module..." -ForegroundColor Green -NewLineBefore -InformationAction Continue
338351

352+
if($inputConfig.starter_module_override_folder_path.Value.StartsWith("~/" )) {
353+
$inputConfig.starter_module_override_folder_path.Value = Join-Path $HOME $inputConfig.starter_module_override_folder_path.Value.Replace("~/", "")
354+
}
355+
339356
$versionAndPath = New-ModuleSetup `
340357
-targetDirectory $inputConfig.output_folder_path.Value `
341358
-targetFolder $starterModuleTargetFolder `
@@ -383,6 +400,17 @@ function Deploy-Accelerator {
383400
$bootstrapTargetPath = Join-Path $inputConfig.output_folder_path.Value $bootstrapTargetFolder
384401
$starterTargetPath = Join-Path $inputConfig.output_folder_path.Value $starterFolder
385402

403+
# Normalize starter additional files input
404+
$starterAdditionalFiles = @()
405+
foreach ($additionalFile in $inputConfig.starter_additional_files.Value) {
406+
if($additionalFile.StartsWith("~/" )) {
407+
$additionalFile = Join-Path $HOME $additionalFile.Replace("~/", "")
408+
}
409+
$additionalFile = (Resolve-Path -Path $additionalFile).Path
410+
$starterAdditionalFiles += $additionalFile
411+
}
412+
$inputConfig.starter_additional_files.Value = $starterAdditionalFiles
413+
386414
New-Bootstrap `
387415
-iac $inputConfig.iac_type.Value `
388416
-bootstrapDetails $bootstrapDetails `
@@ -395,7 +423,6 @@ function Deploy-Accelerator {
395423
-starterConfig $starterConfig `
396424
-autoApprove:$inputConfig.auto_approve.Value `
397425
-destroy:$inputConfig.destroy.Value `
398-
-zonesSupport $zonesSupport `
399426
-writeVerboseLogs:$inputConfig.write_verbose_logs.Value `
400427
-hclParserToolPath $hclParserToolPath `
401428
-convertTfvarsToJson:$inputConfig.convert_tfvars_to_json.Value `
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
function New-AcceleratorFolderStructure {
2+
[CmdletBinding(SupportsShouldProcess = $true)]
3+
param (
4+
[Parameter(
5+
Mandatory = $false,
6+
HelpMessage = "[REQUIRED] The infrastructure as code type for the accelerator. Options are 'terraform', 'bicep' or 'bicep-classic'"
7+
)]
8+
[string] $iacType = "terraform",
9+
[Parameter(
10+
Mandatory = $false,
11+
HelpMessage = "[REQUIRED] The version of the accelerator to use for the bootstrap and starter configuration files"
12+
)]
13+
[string] $versionControl = "github",
14+
[Parameter(
15+
Mandatory = $false,
16+
HelpMessage = "[OPTIONAL] The scenario number to use for the starter configuration files"
17+
)]
18+
[int] $scenarioNumber = 1,
19+
[Parameter(
20+
Mandatory = $false,
21+
HelpMessage = "[REQUIRED] The target folder to create the accelerator bootstrap and platform landing zone configuration files in"
22+
)]
23+
[string] $targetFolderPath = "~/accelerator",
24+
[Parameter(
25+
Mandatory = $false,
26+
HelpMessage = "[OPTIONAL] Forece recreate of the target folder if it already exists"
27+
)]
28+
[switch] $force
29+
)
30+
31+
if ($PSCmdlet.ShouldProcess("Accelerator folder create", "modify")) {
32+
33+
$currentPath = Get-Location
34+
35+
# Normalize target folder path
36+
if($targetFolderPath.StartsWith("~/" )) {
37+
$targetFolderPath = Join-Path $HOME $targetFolderPath.Replace("~/", "")
38+
}
39+
if(Test-Path -Path $targetFolderPath) {
40+
if($force.IsPresent) {
41+
Write-Host "Force flag is set, removing existing target folder at $targetFolderPath"
42+
Remove-Item -Recurse -Force -Path $targetFolderPath | Write-Verbose | Out-Null
43+
} else {
44+
throw "Target folder $targetFolderPath already exists. Please specify a different folder path or remove the existing folder."
45+
}
46+
}
47+
Write-Host "Creating target folder at $targetFolderPath"
48+
New-Item -ItemType "directory" -Path $targetFolderPath -Force | Write-Verbose | Out-Null
49+
$targetFolderPath = (Resolve-Path -Path $targetFolderPath).Path
50+
51+
# Create target folder structure
52+
$outputFolder = Join-Path $targetFolderPath "output"
53+
Write-Host "Creating output folder at $outputFolder"
54+
New-Item -ItemType "directory" $outputFolder -Force | Write-Verbose | Out-Null
55+
56+
# Create temp folder
57+
$tempFolderPath = Join-Path $targetFolderPath "temp"
58+
Write-Host "Creating temp folder at $tempFolderPath"
59+
New-Item -ItemType "directory" $tempFolderPath -Force | Write-Verbose | Out-Null
60+
61+
# Map the repo
62+
$repos = @{
63+
"terraform" = @{
64+
repoName = "alz-terraform-accelerator"
65+
folderToClone = "templates/platform_landing_zone"
66+
libraryFolderPath = "lib"
67+
exampleFolderPath = "examples"
68+
bootstrapExampleFolderPath = "bootstrap"
69+
hasScenarios = $true
70+
hasLibrary = $true
71+
}
72+
73+
"bicep" = @{
74+
repoName = "alz-bicep-accelerator"
75+
folderToClone = ""
76+
libraryFolderPath = ""
77+
exampleFolderPath = "examples"
78+
bootstrapExampleFolderPath = "bootstrap"
79+
hasScenarios = $false
80+
hasLibrary = $false
81+
platformLandingZoneFilePath = "platform-landing-zone.yaml"
82+
}
83+
84+
"bicep-classic" = @{
85+
repoName = "alz-bicep"
86+
folderToClone = "accelerator"
87+
libraryFolderPath = ""
88+
exampleFolderPath = "examples"
89+
bootstrapExampleFolderPath = "bootstrap"
90+
hasScenarios = $false
91+
hasLibrary = $false
92+
platformLandingZoneFilePath = ""
93+
}
94+
}
95+
96+
# Clone the repo and copy the bootstrap and starter configuration files
97+
$repo = $repos[$iacType]
98+
Write-Host "Cloning repo $($repo.repoName)"
99+
git clone -n --depth=1 --filter=tree:0 "https://github.com/Azure/$($repo.repoName)" "$tempFolderPath" | Write-Verbose | Out-Null
100+
Set-Location $tempFolderPath
101+
102+
Write-Host "Checking out folder $($repo.folderToClone)"
103+
git sparse-checkout set --no-cone $repo.folderToClone | Write-Verbose | Out-Null
104+
git checkout | Write-Verbose | Out-Null
105+
106+
Set-Location $currentPath
107+
$exampleFolderPath = "$($repo.folderToClone)/$($repo.exampleFolderPath)"
108+
$bootstrapExampleFolderPath = "$exampleFolderPath/$($repo.bootstrapExampleFolderPath)"
109+
110+
$configFolderPath = Join-Path $targetFolderPath "config"
111+
Write-Host "Creating config folder at $configFolderPath"
112+
New-Item -ItemType "directory" $configFolderPath -Force | Write-Verbose | Out-Null
113+
114+
# Copy the bootstrap configuration file
115+
Write-Host "Copying bootstrap configuration file to $($targetFolderPath)/config/inputs.yaml"
116+
Copy-Item -Path "$tempFolderPath/$bootstrapExampleFolderPath/inputs-$versionControl.yaml" -Destination "$targetFolderPath/config/inputs.yaml" -Force | Write-Verbose | Out-Null
117+
118+
if ($repo.hasLibrary) {
119+
$libFolderPath = "$($repo.folderToClone)/$($repo.libraryFolderPath)"
120+
Write-Host "Copying library files to $($targetFolderPath)/config"
121+
Copy-Item -Path "$tempFolderPath/$libFolderPath" -Destination "$targetFolderPath/config" -Recurse -Force | Write-Verbose | Out-Null
122+
}
123+
124+
# Copy the platform landing zone configuration files based on scenario number or specific file path
125+
if ($repo.hasScenarios) {
126+
$scenarios = @{
127+
1 = "full-multi-region/hub-and-spoke-vnet"
128+
2 = "full-multi-region/virtual-wan"
129+
3 = "full-multi-region-nva/hub-and-spoke-vnet"
130+
4 = "full-multi-region-nva/virtual-wan"
131+
5 = "management-only/management"
132+
6 = "full-single-region/hub-and-spoke-vnet"
133+
7 = "full-single-region/virtual-wan"
134+
8 = "full-single-region-nva/hub-and-spoke-vnet"
135+
9 = "full-single-region-nva/virtual-wan"
136+
}
137+
138+
Write-Host "Copying platform landing zone configuration file for scenario $scenarioNumber to $($targetFolderPath)/config/platform-landing-zone.tfvars"
139+
Copy-Item -Path "$tempFolderPath/templates/platform_landing_zone/examples/$($scenarios[$scenarioNumber]).tfvars" -Destination "$targetFolderPath/config/platform-landing-zone.tfvars" -Force | Write-Verbose | Out-Null
140+
141+
} elseif ($repo.platformLandingZoneFilePath -ne "") {
142+
Write-Host "Copying platform landing zone configuration file to $($targetFolderPath)/config/platform-landing-zone.yaml"
143+
Copy-Item -Path "$tempFolderPath/$($repo.platformLandingZoneFilePath)" -Destination "$targetFolderPath/config/platform-landing-zone.yaml" -Force | Write-Verbose | Out-Null
144+
}
145+
146+
Remove-Item -Path $tempFolderPath -Recurse -Force | Write-Verbose | Out-Null
147+
}
148+
}

0 commit comments

Comments
 (0)