Skip to content

Commit c19e427

Browse files
committed
Initial changes to support bicep-avm
1 parent c1a71b8 commit c19e427

File tree

4 files changed

+65
-40
lines changed

4 files changed

+65
-40
lines changed

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,17 @@
1010

1111
## Introduction
1212

13-
This repository contains the PowerShell module and documentation for the Azure landing zones Accelerators for Bicep and Terraform. The accelerators are an opinionated implementation of the Azure Landing Zones Terraform modules, with Azure DevOps or GitHub bootstrapping.
13+
This repository contains the PowerShell module and documentation for the Azure landing zones Accelerators for Bicep and Terraform. The accelerators are an opinionated implementation of the Azure Landing Zones modules, with Azure DevOps or GitHub bootstrapping.
1414

15-
It is designed to be used as a template to enable you to get started quickly deploying ALZ with Bicep or Terraform.
15+
## Supported Infrastructure as Code (IaC) Types
16+
17+
The accelerators support multiple Infrastructure as Code approaches:
18+
19+
- **terraform**: Terraform-based Azure Landing Zones
20+
- **bicep**: Bicep-based Azure Landing Zones using the traditional [ALZ-Bicep](https://github.com/Azure/ALZ-Bicep) framework
21+
- **bicep-avm**: Bicep-based Azure Landing Zones using the new [alz-bicep-accelerator](https://github.com/Azure/alz-bicep-accelerator) framework built on Azure Verified Modules
22+
23+
It is designed to be used as a template to enable you to get started quickly deploying ALZ with any of these approaches.
1624

1725
Please refer to our [Docs](https://aka.ms/alz/acc) for detailed features and usage instructions.
1826

src/ALZ/Private/Config-Helpers/Request-SpecialInput.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ function Request-SpecialInput {
1919
$typeDescription = ""
2020

2121
if($type -eq "iac") {
22-
$options += @{ key = "bicep"; name = "Bicep"; description = "Bicep" }
22+
$options += @{ key = "bicep-avm"; name = "Bicep AVM"; description = "Bicep (New Framework)" }
23+
$options += @{ key = "bicep"; name = "Bicep Classic"; description = "Bicep (Classic Framework)" }
2324
$options += @{ key = "terraform"; name = "Terraform"; description = "Terraform" }
2425
$typeDescription = "Infrastructure as Code (IaC) language"
2526
}

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

Lines changed: 45 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ function New-Bootstrap {
8282
$starterRootModuleFolderPath = ""
8383
$starterFoldersToRetain = @()
8484

85-
if($hasStarter) {
86-
if($inputConfig.starter_module_name.Value -eq "") {
85+
if ($hasStarter) {
86+
if ($inputConfig.starter_module_name.Value -eq "") {
8787
$inputConfig.starter_module_name = @{
8888
Value = Request-SpecialInput -type "starter" -starterConfig $starterConfig
8989
Source = "user"
@@ -97,12 +97,12 @@ function New-Bootstrap {
9797
$starterRootModuleFolderPath = $starterModulePath
9898
Write-Verbose "Starter Module Path: $starterModulePath"
9999

100-
if($chosenStarterConfig.PSObject.Properties.Name -contains "additional_retained_folders") {
100+
if ($chosenStarterConfig.PSObject.Properties.Name -contains "additional_retained_folders") {
101101
$starterFoldersToRetain = $chosenStarterConfig.additional_retained_folders
102102
Write-Verbose "Starter Additional folders to retain: $($starterFoldersToRetain -join ",")"
103103
}
104104

105-
if($chosenStarterConfig.PSObject.Properties.Name -contains "root_module_folder") {
105+
if ($chosenStarterConfig.PSObject.Properties.Name -contains "root_module_folder") {
106106
$starterRootModuleFolder = $chosenStarterConfig.root_module_folder
107107

108108
# Retain the root module folder
@@ -127,23 +127,23 @@ function New-Bootstrap {
127127

128128
Write-Verbose "Getting the bootstrap configuration..."
129129
$terraformFiles = Get-ChildItem -Path $bootstrapModulePath -Filter "*.tf" -File
130-
foreach($terraformFile in $terraformFiles) {
130+
foreach ($terraformFile in $terraformFiles) {
131131
$bootstrapParameters = Convert-HCLVariablesToInputConfig -targetVariableFile $terraformFile.FullName -hclParserToolPath $hclParserToolPath -validators $validationConfig -appendToObject $bootstrapParameters
132132
}
133133

134134
# Getting the configuration for the starter module user input
135-
$starterParameters = [PSCustomObject]@{}
135+
$starterParameters = [PSCustomObject]@{}
136136

137-
if($hasStarter) {
137+
if ($hasStarter) {
138138
Write-Verbose "Getting the starter configuration..."
139-
if($iac -eq "terraform") {
139+
if ($iac -eq "terraform") {
140140
$terraformFiles = Get-ChildItem -Path $starterRootModuleFolderPath -Filter "*.tf" -File
141-
foreach($terraformFile in $terraformFiles) {
141+
foreach ($terraformFile in $terraformFiles) {
142142
$starterParameters = Convert-HCLVariablesToInputConfig -targetVariableFile $terraformFile.FullName -hclParserToolPath $hclParserToolPath -validators $validationConfig -appendToObject $starterParameters
143143
}
144144
}
145145

146-
if($iac -eq "bicep") {
146+
if ($iac -in @("bicep", "bicep-avm")) {
147147
$starterParameters = Convert-BicepConfigToInputConfig -bicepConfig $starterConfig.starter_modules.Value.$($inputConfig.starter_module_name.Value) -validators $validationConfig
148148
}
149149
}
@@ -158,17 +158,17 @@ function New-Bootstrap {
158158
Source = "calculated"
159159
}
160160

161-
if($inputConfig.PSObject.Properties.Name -contains "starter_location" -and $inputConfig.PSObject.Properties.Name -notcontains "starter_locations") {
161+
if ($inputConfig.PSObject.Properties.Name -contains "starter_location" -and $inputConfig.PSObject.Properties.Name -notcontains "starter_locations") {
162162
Write-Verbose "Converting starter_location $($inputConfig.starter_location.Value) to starter_locations..."
163163
$inputConfig | Add-Member -NotePropertyName "starter_locations" -NotePropertyValue @{
164164
Value = @($inputConfig.starter_location.Value)
165165
Source = "calculated"
166166
}
167167
}
168168

169-
if($inputConfig.PSObject.Properties.Name -contains "starter_locations") {
169+
if ($inputConfig.PSObject.Properties.Name -contains "starter_locations") {
170170
$availabilityZonesStarter = @()
171-
foreach($region in $inputConfig.starter_locations.Value) {
171+
foreach ($region in $inputConfig.starter_locations.Value) {
172172
$availabilityZonesStarter += , @(Get-AvailabilityZonesSupport -region $region -zonesSupport $zonesSupport)
173173
}
174174
$inputConfig | Add-Member -NotePropertyName "availability_zones_starter" -NotePropertyValue @{
@@ -203,12 +203,12 @@ function New-Bootstrap {
203203
# Write the tfvars file for the bootstrap and starter module
204204
Write-TfvarsJsonFile -tfvarsFilePath $bootstrapTfvarsPath -configuration $bootstrapConfiguration
205205

206-
if($iac -eq "terraform") {
207-
if($starterFoldersToRetain.Length -gt 0) {
206+
if ($iac -eq "terraform") {
207+
if ($starterFoldersToRetain.Length -gt 0) {
208208
Write-Verbose "Removing unwanted folders from the starter module..."
209209
$folders = Get-ChildItem -Path $starterModulePath -Directory
210-
foreach($folder in $folders) {
211-
if($starterFoldersToRetain -notcontains $folder.Name) {
210+
foreach ($folder in $folders) {
211+
if ($starterFoldersToRetain -notcontains $folder.Name) {
212212
Write-Verbose "Removing folder: $($folder.FullName)"
213213
Remove-Item -Path $folder.FullName -Recurse -Force
214214
} else {
@@ -218,12 +218,12 @@ function New-Bootstrap {
218218
}
219219
}
220220
Remove-TerraformMetaFileSet -path $starterModulePath -writeVerboseLogs:$writeVerboseLogs.IsPresent
221-
if($convertTfvarsToJson) {
221+
if ($convertTfvarsToJson) {
222222
Write-TfvarsJsonFile -tfvarsFilePath $starterTfvarsPath -configuration $starterConfiguration
223223
} else {
224224
$inputsFromTfvars = $inputConfig.PSObject.Properties | Where-Object { $_.Value.Source -eq ".tfvars" } | Select-Object -ExpandProperty Name
225225
Write-TfvarsJsonFile -tfvarsFilePath $starterTfvarsPath -configuration $starterConfiguration -skipItems $inputsFromTfvars
226-
foreach($inputConfigFilePath in $inputConfigFilePaths | Where-Object { $_ -like "*.tfvars" }) {
226+
foreach ($inputConfigFilePath in $inputConfigFilePaths | Where-Object { $_ -like "*.tfvars" }) {
227227
$fileName = [System.IO.Path]::GetFileName($inputConfigFilePath)
228228
$fileName = $fileName.Replace(".tfvars", ".auto.tfvars")
229229
$destination = Join-Path -Path $starterRootModuleFolderPath -ChildPath $fileName
@@ -233,8 +233,8 @@ function New-Bootstrap {
233233
}
234234

235235
# Copy additional files
236-
foreach($additionalFile in $starterAdditionalFiles) {
237-
if(Test-Path $additionalFile -PathType Container) {
236+
foreach ($additionalFile in $starterAdditionalFiles) {
237+
if (Test-Path $additionalFile -PathType Container) {
238238
$folderName = ([System.IO.DirectoryInfo]::new($additionalFile)).Name
239239
$destination = Join-Path -Path $starterRootModuleFolderPath -ChildPath $folderName
240240
Write-Verbose "Copying folder $additionalFile to $destination"
@@ -248,31 +248,47 @@ function New-Bootstrap {
248248
}
249249
}
250250

251-
if($iac -eq "bicep") {
252-
Copy-ParametersFileCollection -starterPath $starterModulePath -configFiles $starterConfig.starter_modules.Value.$($inputConfig.starter_module_name.Value).deployment_files
251+
if ($iac -in @("bicep", "bicep-avm")) {
252+
$starterModuleDefinition = $starterConfig.starter_modules.Value.$($inputConfig.starter_module_name.Value)
253+
Copy-ParametersFileCollection -starterPath $starterModulePath -configFiles $starterModuleDefinition.deployment_files
253254
Set-ComputedConfiguration -configuration $starterConfiguration
254255
Edit-ALZConfigurationFilesInPlace -alzEnvironmentDestination $starterModulePath -configuration $starterConfiguration
255-
Write-JsonFile -jsonFilePath $starterBicepVarsPath -configuration $starterConfiguration
256+
if ($iac -eq "bicep-avm") {
257+
$bicepAvmEnvConfiguration = Get-BicepAvmEnvironmentConfiguration -inputConfig $inputConfig
258+
$combinedConfiguration = [PSCustomObject]@{}
259+
260+
foreach ($property in $starterConfiguration.PSObject.Properties) {
261+
$combinedConfiguration | Add-Member -NotePropertyName $property.Name -NotePropertyValue $property.Value
262+
}
263+
264+
foreach ($property in $bicepAvmEnvConfiguration.PSObject.Properties) {
265+
$combinedConfiguration | Add-Member -NotePropertyName $property.Name -NotePropertyValue $property.Value -Force
266+
}
267+
268+
Write-JsonFile -jsonFilePath $starterBicepVarsPath -configuration $combinedConfiguration
269+
} else {
270+
Write-JsonFile -jsonFilePath $starterBicepVarsPath -configuration $starterConfiguration
271+
}
256272

257273
# Remove unrequired files
258-
$foldersOrFilesToRetain = $starterConfig.starter_modules.Value.$($inputConfig.starter_module_name.Value).folders_or_files_to_retain
274+
$foldersOrFilesToRetain = $starterModuleDefinition.folders_or_files_to_retain
259275
$foldersOrFilesToRetain += "parameters.json"
260276
$foldersOrFilesToRetain += "config"
261277
$foldersOrFilesToRetain += "starter-cache.json"
262278

263-
foreach($deployment_file in $starterConfig.starter_modules.Value.$($inputConfig.starter_module_name.Value).deployment_files) {
279+
foreach ($deployment_file in $starterModuleDefinition.deployment_files) {
264280
$foldersOrFilesToRetain += $deployment_file.templateParametersSourceFilePath
265281
}
266282

267-
$subFoldersOrFilesToRemove = $starterConfig.starter_modules.Value.$($inputConfig.starter_module_name.Value).subfolders_or_files_to_remove
283+
$subFoldersOrFilesToRemove = $starterModuleDefinition.subfolders_or_files_to_remove
268284

269285
Remove-UnrequiredFileSet -path $starterModulePath -foldersOrFilesToRetain $foldersOrFilesToRetain -subFoldersOrFilesToRemove $subFoldersOrFilesToRemove -writeVerboseLogs:$writeVerboseLogs.IsPresent
270286
}
271287

272288
# Running terraform init and apply
273289
Write-InformationColored "Thank you for providing those inputs, we are now initializing and applying Terraform to bootstrap your environment..." -ForegroundColor Green -NewLineBefore -InformationAction Continue
274290

275-
if($autoApprove) {
291+
if ($autoApprove) {
276292
Invoke-Terraform -moduleFolderPath $bootstrapModulePath -autoApprove -destroy:$destroy.IsPresent
277293
} else {
278294
Write-InformationColored "Once the plan is complete you will be prompted to confirm the apply." -ForegroundColor Green -NewLineBefore -InformationAction Continue
@@ -281,4 +297,4 @@ function New-Bootstrap {
281297

282298
Write-InformationColored "Bootstrap has completed successfully! Thanks for using our tool. Head over to Phase 3 in the documentation to continue..." -ForegroundColor Green -NewLineBefore -InformationAction Continue
283299
}
284-
}
300+
}

src/ALZ/Public/Deploy-Accelerator.ps1

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function Deploy-Accelerator {
2222

2323
[Parameter(
2424
Mandatory = $false,
25-
HelpMessage = "[REQUIRED] The infrastructure as code type to target. Supported options are 'bicep', 'terrform' or 'local'. Environment variable: ALZ_iac_type. Config file input: iac_type.")]
25+
HelpMessage = "[REQUIRED] The infrastructure as code type to target. Supported options are 'bicep', 'bicep-avm', 'terraform' or 'local'. Environment variable: ALZ_iac_type. Config file input: iac_type.")]
2626
[Alias("i")]
2727
[Alias("iac")]
2828
[string] $iac_type = "",
@@ -188,7 +188,7 @@ function Deploy-Accelerator {
188188

189189
$ProgressPreference = "SilentlyContinue"
190190

191-
if($skip_requirements_check.IsPresent) {
191+
if ($skip_requirements_check.IsPresent) {
192192
Write-InformationColored "WARNING: Skipping the software requirements check..." -ForegroundColor Yellow -InformationAction Continue
193193
} else {
194194
Write-InformationColored "Checking the software requirements for the Accelerator..." -ForegroundColor Green -InformationAction Continue
@@ -201,7 +201,7 @@ function Deploy-Accelerator {
201201

202202
# Check and install tools needed
203203
$toolsPath = Join-Path -Path $output_folder_path -ChildPath ".tools"
204-
if($skipInternetChecks) {
204+
if ($skipInternetChecks) {
205205
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
206206
} else {
207207
Write-InformationColored "Checking you have the latest version of Terraform installed..." -ForegroundColor Green -NewLineBefore -InformationAction Continue
@@ -213,7 +213,7 @@ function Deploy-Accelerator {
213213
$inputConfig = $null
214214
if ($inputConfigFilePaths.Length -eq 0) {
215215
$envInputConfigPaths = $env:ALZ_input_config_path
216-
if($null -ne $envInputConfigPaths -and $envInputConfigPaths -ne "") {
216+
if ($null -ne $envInputConfigPaths -and $envInputConfigPaths -ne "") {
217217
$inputConfigFilePaths = $envInputConfigPaths -split ","
218218
} else {
219219
Write-InformationColored "No input configuration file path has been provided. Please provide the path(s) to your configuration file(s)..." -ForegroundColor Yellow -InformationAction Continue
@@ -222,7 +222,7 @@ function Deploy-Accelerator {
222222
}
223223

224224
# Get the input config from yaml and json files
225-
foreach($inputConfigFilePath in $inputConfigFilePaths) {
225+
foreach ($inputConfigFilePath in $inputConfigFilePaths) {
226226
$inputConfig = Get-ALZConfig -configFilePath $inputConfigFilePath -inputConfig $inputConfig -hclParserToolPath $hclParserToolPath
227227
}
228228

@@ -231,13 +231,13 @@ function Deploy-Accelerator {
231231
$parametersWithValues = @{}
232232
foreach ($parameterKey in $parameters.Keys) {
233233
$parameter = $parameters[$parameterKey]
234-
if($parameter.IsDynamic) {
234+
if ($parameter.IsDynamic) {
235235
continue
236236
}
237237

238238
$parameterValue = Get-Variable -Name $parameterKey -ValueOnly -ErrorAction SilentlyContinue
239239

240-
if($null -ne $parameterValue) {
240+
if ($null -ne $parameterValue) {
241241
$parametersWithValues[$parameterKey] = @{
242242
type = $parameters[$parameterKey].ParameterType.Name
243243
value = $parameterValue
@@ -255,7 +255,7 @@ function Deploy-Accelerator {
255255
}
256256
}
257257

258-
if ($inputConfig.iac_type.Value -eq "bicep") {
258+
if ($inputConfig.iac_type.Value -eq "bicep" -or $inputConfig.iac_type.Value -eq "bicep-classic") {
259259
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
260260
}
261261

0 commit comments

Comments
 (0)