Skip to content

Commit aaa460c

Browse files
authored
Fix logic for Bicep legacy upgrades/creation and wiki (#133)
# Pull Request This pull request includes several updates to the documentation and PowerShell scripts to improve clarity and functionality. The most important changes are grouped into documentation updates and PowerShell script improvements. ### Documentation Updates: * Updated `New-Item` commands to specify `ItemType` for both files and directories in `docs/wiki/[User-Guide]-Quick-Start-Phase-2-Azure-DevOps.md` ([docs/wiki/[User-Guide]-Quick-Start-Phase-2-Azure-DevOps.mdL16-R23](diffhunk://#diff-5d0a7946d9bb62a79f8c8591729ef54a59f8a93aecb6c330d8d6c1d81c5ad906L16-R23), [docs/wiki/[User-Guide]-Quick-Start-Phase-2-Azure-DevOps.mdL92-R99](diffhunk://#diff-5d0a7946d9bb62a79f8c8591729ef54a59f8a93aecb6c330d8d6c1d81c5ad906L92-R99)). * Updated `New-Item` commands to specify `ItemType` for both files and directories in `docs/wiki/[User-Guide]-Quick-Start-Phase-2-GitHub.md` ([docs/wiki/[User-Guide]-Quick-Start-Phase-2-GitHub.mdL16-R21](diffhunk://#diff-e060bdd53a4020560742d085e24e0eecd91edd047d922f826b224a20df914e27L16-R21), [docs/wiki/[User-Guide]-Quick-Start-Phase-2-GitHub.mdL84-R89](diffhunk://#diff-e060bdd53a4020560742d085e24e0eecd91edd047d922f826b224a20df914e27L84-R89)). * Updated `New-Item` commands to specify `ItemType` for both files and directories in `docs/wiki/[User-Guide]-Quick-Start-Phase-2-Local.md` ([docs/wiki/[User-Guide]-Quick-Start-Phase-2-Local.mdL16-R21](diffhunk://#diff-f86bb4f6ce154adfd0bf07c039be16f163e0e081779c957de4826e664e2792d0L16-R21), [docs/wiki/[User-Guide]-Quick-Start-Phase-2-Local.mdL77-R84](diffhunk://#diff-f86bb4f6ce154adfd0bf07c039be16f163e0e081779c957de4826e664e2792d0L77-R84)). ### PowerShell Script Improvements: * Added a `replaceFiles` switch parameter to the `New-ALZEnvironmentBicep` function and included logic to conditionally overwrite the configuration directory based on this parameter in `src/ALZ/Private/Legacy-Bicep/New-ALZEnvironmentBicep.ps1` [[1]](diffhunk://#diff-8f6a995ce9e20e98ce73d801cac6f693c81cb6c1c7a8cff780657dca6168f2ffL24-R27) [[2]](diffhunk://#diff-8f6a995ce9e20e98ce73d801cac6f693c81cb6c1c7a8cff780657dca6168f2ffR39-R54). * Corrected a typo in the `Get-GithubRelease` function to change "over-writing" to "overwriting" in `src/ALZ/Private/Shared/Get-GithubRelease.ps1`. * Removed unnecessary whitespace and adjusted variable initialization in the `New-ALZEnvironment` function in `src/ALZ/Public/New-ALZEnvironment.ps1` [[1]](diffhunk://#diff-cdabc275fb414799b1878e803c6198c09565ef53d02c3f977b4a859605fde71dL60) [[2]](diffhunk://#diff-cdabc275fb414799b1878e803c6198c09565ef53d02c3f977b4a859605fde71dR191) [[3]](diffhunk://#diff-cdabc275fb414799b1878e803c6198c09565ef53d02c3f977b4a859605fde71dL231-R234). ## Issue Fixes #129 Fixes Azure/ALZ-Bicep#813 Fixes [AB](https://dev.azure.com/CSUSolEng/Azure%20Landing%20Zones/_sprints/backlog/Azure%20Landing%20Zones%20Bicep%20Team/Azure%20Landing%20Zones/Dilithium/202408?workitem=36409) Description of changes: ## License By submitting this pull request, I confirm that my contribution is made under the terms of the projects associated license.
1 parent 6c37952 commit aaa460c

File tree

7 files changed

+68
-61
lines changed

7 files changed

+68
-61
lines changed

docs/wiki/[User-Guide]-Quick-Start-Phase-2-Azure-DevOps.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ Although you can just run `Deploy-Accelerator` and fill out the prompted inputs,
1313

1414
```pwsh
1515
# Windows
16-
New-Item c:\accelerator\config\inputs.yaml -Force
17-
New-Item c:\accelerator\output
16+
New-Item -ItemType "file" c:\accelerator\config\inputs.yaml -Force
17+
New-Item -ItemType "directory" c:\accelerator\output
1818
```
1919
2020
```pwsh
2121
# Linux/Mac
22-
New-Item ~/accelerator/config/inputs.yaml -Force
23-
New-Item ~/accelerator/output
22+
New-Item -ItemType "file" ~/accelerator/config/inputs.yaml -Force
23+
New-Item -ItemType "directory" ~/accelerator/output
2424
```
2525
2626
```plaintext
@@ -89,14 +89,14 @@ Although you can just run `Deploy-Accelerator` and fill out the prompted inputs,
8989
9090
```pwsh
9191
# Windows
92-
New-Item c:\accelerator\config\inputs.yaml -Force
93-
New-Item c:\accelerator\output
92+
New-Item -ItemType "file" c:\accelerator\config\inputs.yaml -Force
93+
New-Item -ItemType "directory" c:\accelerator\output
9494
```
9595
9696
```pwsh
9797
# Linux/Mac
98-
New-Item ~/accelerator/config/inputs.yaml -Force
99-
New-Item ~/accelerator/output
98+
New-Item -ItemType "file" ~/accelerator/config/inputs.yaml -Force
99+
New-Item -ItemType "directory" ~/accelerator/output
100100
```
101101
102102
```plaintext

docs/wiki/[User-Guide]-Quick-Start-Phase-2-GitHub.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ Although you can just run `Deploy-Accelerator` and fill out the prompted inputs,
1313

1414
```pwsh
1515
# Windows
16-
New-Item c:\accelerator\config\inputs.yaml -Force
17-
New-Item c:\accelerator\output
16+
New-Item -ItemType "file" c:\accelerator\config\inputs.yaml -Force
17+
New-Item -ItemType "directory" c:\accelerator\output
1818
1919
# Linux/Mac
20-
New-Item ~/accelerator/config/inputs.yaml -Force
21-
New-Item ~/accelerator/output
20+
New-Item -ItemType "file" ~/accelerator/config/inputs.yaml -Force
21+
New-Item -ItemType "directory" ~/accelerator/output
2222
```
2323
2424
```plaintext
@@ -81,12 +81,12 @@ Although you can just run `Deploy-Accelerator` and fill out the prompted inputs,
8181
8282
```pwsh
8383
# Windows
84-
New-Item c:\accelerator\config\inputs.yaml -Force
85-
New-Item c:\accelerator\output
84+
New-Item -ItemType "file" c:\accelerator\config\inputs.yaml -Force
85+
New-Item -ItemType "directory" c:\accelerator\output
8686
8787
# Linux/Mac
88-
New-Item ~/accelerator/config/inputs.yaml -Force
89-
New-Item ~/accelerator/output
88+
New-Item -ItemType "file" ~/accelerator/config/inputs.yaml -Force
89+
New-Item -ItemType "directory" ~/accelerator/output
9090
```
9191
9292
```plaintext

docs/wiki/[User-Guide]-Quick-Start-Phase-2-Local.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ Although you can just run `Deploy-Accelerator` and fill out the prompted inputs,
1313

1414
```pwsh
1515
# Windows
16-
New-Item c:\accelerator\config\inputs.yaml -Force
17-
New-Item c:\accelerator\output
16+
New-Item -ItemType "file" c:\accelerator\config\inputs.yaml -Force
17+
New-Item -ItemType "directory" c:\accelerator\output
1818
1919
# Linux/Mac
20-
New-Item ~/accelerator/config/inputs.yaml -Force
21-
New-Item ~/accelerator/output
20+
New-Item -ItemType "file" ~/accelerator/config/inputs.yaml -Force
21+
New-Item -ItemType "directory" ~/accelerator/output
2222
```
2323
2424
```plaintext
@@ -74,14 +74,14 @@ Although you can just run `Deploy-Accelerator` and fill out the prompted inputs,
7474
7575
```pwsh
7676
# Windows
77-
New-Item c:\accelerator\config\inputs.yaml -Force
78-
New-Item c:\accelerator\output
77+
New-Item -ItemType "file" c:\accelerator\config\inputs.yaml -Force
78+
New-Item -ItemType "directory" c:\accelerator\output
7979
```
8080
8181
```pwsh
8282
# Linux/Mac
83-
New-Item ~/accelerator/config/inputs.yaml -Force
84-
New-Item ~/accelerator/output
83+
New-Item -ItemType "file" ~/accelerator/config/inputs.yaml -Force
84+
New-Item -ItemType "directory" ~/accelerator/output
8585
```
8686
8787
```plaintext

docs/wiki/examples/powershell-inputs/inputs-local-terraform.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# https://github.com/Azure/ALZ-PowerShell-Module/wiki/%5BUser-Guide%5D-Quick-Start-Phase-2-Azure-DevOps#2211-azure-devops-with-bicep
44

55
# Basic Inputs
6-
iac: "bicep"
6+
iac: "terraform"
77
bootstrap: "alz_local"
88
starter: "complete"
99

src/ALZ/Private/Legacy-Bicep/New-ALZEnvironmentBicep.ps1

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ function New-ALZEnvironmentBicep {
2121
[switch] $local,
2222

2323
[Parameter(Mandatory = $false)]
24-
[switch] $autoApprove
24+
[switch] $autoApprove,
25+
26+
[Parameter(Mandatory = $false)]
27+
[switch] $replaceFiles
2528
)
2629

2730
if ($PSCmdlet.ShouldProcess("ALZ-Bicep module configuration", "modify")) {
@@ -33,22 +36,27 @@ function New-ALZEnvironmentBicep {
3336
Write-Verbose "Config path: $configFilePath"
3437
$bicepConfig = Get-ALZConfig -configFilePath $configFilePath
3538

36-
Write-InformationColored "Copying ALZ-Bicep module to $targetDirectory" -ForegroundColor Green -InformationAction Continue
37-
Copy-ALZParametersFile -alzEnvironmentDestination $targetDirectory -upstreamReleaseDirectory $upstreamReleaseFolderPath -configFiles $bicepConfig.config_files | Out-String | Write-Verbose
38-
Copy-ALZParametersFile -alzEnvironmentDestination $targetDirectory -upstreamReleaseDirectory $upstreamReleaseFolderPath -configFiles $bicepConfig.cicd.$vcs | Out-String | Write-Verbose
39-
40-
$configuration = Request-ALZEnvironmentConfig -configurationParameters $bicepConfig.parameters -userInputOverrides $userInputOverrides -autoApprove:$autoApprove.IsPresent
41-
42-
Set-ComputedConfiguration -configuration $configuration | Out-String | Write-Verbose
43-
Edit-ALZConfigurationFilesInPlace -alzEnvironmentDestination $targetDirectory -configuration $configuration | Out-String | Write-Verbose
44-
Build-ALZDeploymentEnvFile -configuration $configuration -Destination $targetDirectory -version $upstreamReleaseVersion | Out-String | Write-Verbose
45-
Add-AvailabilityZonesBicepParameter -alzEnvironmentDestination $targetDirectory -zonesSupport $bicepConfig.zonesSupport | Out-String | Write-Verbose
46-
47-
if($local) {
39+
# Check if the configuration directory exists
40+
$configDirectory = Join-Path -Path $targetDirectory -ChildPath "config"
41+
if (-not (Test-Path -Path $configDirectory) -or $replaceFiles.IsPresent) {
42+
Write-InformationColored "Copying ALZ-Bicep module to $targetDirectory" -ForegroundColor Green -InformationAction Continue
43+
Copy-ALZParametersFile -alzEnvironmentDestination $targetDirectory -upstreamReleaseDirectory $upstreamReleaseFolderPath -configFiles $bicepConfig.config_files | Out-String | Write-Verbose
44+
Copy-ALZParametersFile -alzEnvironmentDestination $targetDirectory -upstreamReleaseDirectory $upstreamReleaseFolderPath -configFiles $bicepConfig.cicd.$vcs | Out-String | Write-Verbose
45+
$configuration = Request-ALZEnvironmentConfig -configurationParameters $bicepConfig.parameters -userInputOverrides $userInputOverrides -autoApprove:$autoApprove.IsPresent
46+
47+
Set-ComputedConfiguration -configuration $configuration | Out-String | Write-Verbose
48+
Edit-ALZConfigurationFilesInPlace -alzEnvironmentDestination $targetDirectory -configuration $configuration | Out-String | Write-Verbose
49+
Build-ALZDeploymentEnvFile -configuration $configuration -Destination $targetDirectory -version $upstreamReleaseVersion | Out-String | Write-Verbose
50+
Add-AvailabilityZonesBicepParameter -alzEnvironmentDestination $targetDirectory -zonesSupport $bicepConfig.zonesSupport | Out-String | Write-Verbose
51+
52+
} else {
53+
Write-InformationColored "Configuration directory $configDirectory already exists and the replacefiles parameter is set to $replaceFiles. Will skil overwriting the config directory." -ForegroundColor Yellow -InformationAction Continue
54+
}
55+
if ($local) {
4856
$isGitRepo = Test-ALZGitRepository -alzEnvironmentDestination $targetDirectory -autoApprove:$autoApprove.IsPresent
4957
if (-not $isGitRepo) {
50-
Write-InformationColored "The directory $targetDirectory is not a git repository. Please make sure it is a git repo after initialization." -ForegroundColor Red -InformationAction Continue
58+
Write-InformationColored "The directory $targetDirectory is not a git repository. Please make sure it is a git repo after initialization." -ForegroundColor Red -InformationAction Continue
5159
}
5260
}
5361
}
54-
}
62+
}

src/ALZ/Private/Shared/Get-GithubRelease.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,16 +146,16 @@ function Get-GithubRelease {
146146
Remove-Item -Path "$targetVersionPath/tmp" -Force -Recurse
147147
Write-InformationColored "The directory for $targetVersionPath has been created and populated." -ForegroundColor Green -InformationAction Continue
148148
} else {
149-
Write-InformationColored "The directory for $targetVersionPath already exists and has content in it, so we are not over-writing it." -ForegroundColor Green -InformationAction Continue
149+
Write-InformationColored "The directory for $targetVersionPath already exists and has content in it, so we are not overwriting it." -ForegroundColor Green -InformationAction Continue
150150
Write-Verbose "===> Content already exists in $releaseDirectory. Skipping"
151151
}
152152

153153
# Check and replace the .env file release version if it is Bicep
154154
$envFilePath = Join-Path -Path $parentDirectory -ChildPath ".env"
155-
if(Test-Path $envFilePath) {
155+
if (Test-Path $envFilePath) {
156156
Write-Verbose "===> Replacing the .env file release version with $releaseTag"
157157
(Get-Content $envFilePath) -replace "UPSTREAM_RELEASE_VERSION=.*", "UPSTREAM_RELEASE_VERSION=$releaseTag" | Set-Content $envFilePath
158158
}
159159

160160
return $releaseTag
161-
}
161+
}

src/ALZ/Public/New-ALZEnvironment.ps1

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ function New-ALZEnvironment {
5757
[Alias("b")]
5858
[string] $bootstrap = "",
5959

60-
6160
[Parameter(Mandatory = $false, HelpMessage = "The starter module to deploy. You will be prompted to enter this if not supplied.")]
6261
[string] $starter = "",
6362

@@ -123,36 +122,36 @@ function New-ALZEnvironment {
123122
if ($PSCmdlet.ShouldProcess("Accelerator setup", "modify")) {
124123
# Get User Inputs from the -inputs file
125124
$userInputOverrides = $null
126-
if($userInputOverridePath -ne "") {
125+
if ($userInputOverridePath -ne "") {
127126
$userInputOverrides = Get-ALZConfig -configFilePath $userInputOverridePath
128127
}
129128

130129
# Get the IAC type if not specified
131-
if($iac -eq "") {
130+
if ($iac -eq "") {
132131
$iac = Request-SpecialInput -type "iac" -userInputOverrides $userInputOverrides
133132
}
134133

135134
# Setup the Bicep flag
136135
$isLegacyBicep = $false
137-
if($iac -eq "bicep") {
136+
if ($iac -eq "bicep") {
138137
$isLegacyBicep = $bicepLegacyMode -eq $true
139138
}
140139

141-
if($isLegacyBicep) {
140+
if ($isLegacyBicep) {
142141
Write-Verbose "We are running in legacy Bicep mode"
143142
}
144143

145-
if(!$isLegacyBicep){
144+
if (!$isLegacyBicep) {
146145
Write-Verbose "We are running in modern mode"
147146
}
148147

149148
# Check and install Terraform CLI if needed
150-
if(!$isLegacyBicep) {
151-
if($skipInternetChecks) {
149+
if (!$isLegacyBicep) {
150+
if ($skipInternetChecks) {
152151
Write-InformationColored "Skipping Terraform tool check as you used the skipInternetCheck parameter. Please ensure you have the most recent version of Terraform installed" -ForegroundColor Yellow -InformationAction Continue
153152
} else {
154153
Write-InformationColored "Checking you have the latest version of Terraform installed..." -ForegroundColor Green -NewLineBefore -InformationAction Continue
155-
if($iac -eq "bicep") {
154+
if ($iac -eq "bicep") {
156155
Write-InformationColored "Although you have selected Bicep, the Accelerator leverages the Terraform tool to bootstrap your Version Control System and Azure. This is will not impact your choice of Bicep post this initial bootstrap. Please refer to our documentation for further details..." -ForegroundColor Yellow -InformationAction Continue
157156
}
158157
$toolsPath = Join-Path -Path $targetDirectory -ChildPath ".tools"
@@ -165,7 +164,7 @@ function New-ALZEnvironment {
165164
$bootstrapPath = ""
166165
$bootstrapTargetFolder = "bootstrap"
167166

168-
if(!$isLegacyBicep) {
167+
if (!$isLegacyBicep) {
169168
Write-InformationColored "Checking and Downloading the bootstrap module..." -ForegroundColor Green -NewLineBefore -InformationAction Continue
170169

171170
$versionAndPath = New-ModuleSetup `
@@ -187,8 +186,9 @@ function New-ALZEnvironment {
187186
$starterFolder = "starter"
188187

189188
$starterModuleTargetFolder = $starterFolder
190-
if($isLegacyBicep) {
189+
if ($isLegacyBicep) {
191190
$starterModuleTargetFolder = "./upstream-releases"
191+
$starterFolder = ""
192192
}
193193

194194
# Setup the variables for bootstrap and starter modules
@@ -203,7 +203,7 @@ function New-ALZEnvironment {
203203
$inputConfig = $null
204204
$zonesSupport = $null
205205

206-
if(!$isLegacyBicep) {
206+
if (!$isLegacyBicep) {
207207
$bootstrapAndStarterConfig = Get-BootstrapAndStarterConfig `
208208
-iac $iac `
209209
-bootstrap $bootstrap `
@@ -221,18 +221,17 @@ function New-ALZEnvironment {
221221
$inputConfig = $bootstrapAndStarterConfig.inputConfig
222222
$zonesSupport = $bootstrapAndStarterConfig.zonesSupport
223223
} else {
224-
if($bootstrap -eq "") {
224+
if ($bootstrap -eq "") {
225225
$bootstrap = Request-SpecialInput -type "bootstrap" -bootstrapModules $bootstrapModules -userInputOverrides $userInputOverrides
226226
}
227227
}
228228

229229
# Download the starter modules
230230
$starterReleaseTag = ""
231-
$starterPath = ""
232231
$starterConfig = $null
233232

234-
if(($hasStarterModule -or $isLegacyBicep)) {
235-
Write-InformationColored "Checking and Downloading the starter module..." -ForegroundColor Green -NewLineBefore -InformationAction Continue
233+
if (($hasStarterModule -or $isLegacyBicep)) {
234+
Write-InformationColored "Checking and downloading the starter module..." -ForegroundColor Green -NewLineBefore -InformationAction Continue
236235

237236
$versionAndPath = New-ModuleSetup `
238237
-targetDirectory $targetDirectory `
@@ -247,7 +246,7 @@ function New-ALZEnvironment {
247246

248247
$starterReleaseTag = $versionAndPath.releaseTag
249248
$starterPath = $versionAndPath.path
250-
if($starterConfigFilePath -ne "") {
249+
if ($starterConfigFilePath -ne "") {
251250
$starterConfig = Get-StarterConfig -starterPath $starterPath -starterConfigPath $starterConfigFilePath
252251
}
253252
}
@@ -273,7 +272,7 @@ function New-ALZEnvironment {
273272
}
274273

275274
# Run the bootstrap
276-
if(!$isLegacyBicep) {
275+
if (!$isLegacyBicep) {
277276

278277
# Set computed interface inputs
279278
$computedInputs = @{

0 commit comments

Comments
 (0)