Skip to content

Commit 23af6b6

Browse files
fix: trim space and remove redundant variables (#491)
# Pull Request ## Issue Issue #, if available: ## Description 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 f6c8601 commit 23af6b6

3 files changed

Lines changed: 32 additions & 34 deletions

File tree

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,21 @@ function New-Bootstrap {
9393
$starterFoldersToRetain = @()
9494

9595
if ($hasStarter) {
96-
if ($inputConfig.starter_module_name.Value -eq "") {
96+
if (!$inputConfig.starter_module_name.Value) {
9797
Write-InformationColored "No starter module has been specified. Please supply the starter module you wish to deploy..." -ForegroundColor Red -InformationAction Continue
9898
throw "No starter module has been specified. Please supply the starter module you wish to deploy..."
9999
}
100100

101-
$chosenStarterConfig = $starterConfig.starter_modules.Value.$($inputConfig.starter_module_name.Value)
101+
$starter_module_name = $inputConfig.starter_module_name.Value.Trim()
102102

103-
Write-Verbose "Selected Starter: $($inputConfig.starter_module_name.Value))"
103+
$chosenStarterConfig = $starterConfig.starter_modules.Value.$($starter_module_name)
104+
105+
if($null -eq $chosenStarterConfig ) {
106+
Write-InformationColored "The starter module name '$($starter_module_name)' does not exist in the starter configuration. Please check your input and try again." -ForegroundColor Red -InformationAction Continue
107+
throw "The starter module name '$($starter_module_name)' does not exist in the starter configuration. Please check your input and try again."
108+
}
109+
110+
Write-Verbose "Selected Starter: $starter_module_name"
104111
$starterModulePath = (Resolve-Path (Join-Path -Path $starterPath -ChildPath $chosenStarterConfig.location)).Path
105112
$starterRootModuleFolderPath = $starterModulePath
106113
Write-Verbose "Starter Module Path: $starterModulePath"

src/ALZ/Public/Deploy-Accelerator.ps1

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,6 @@ function Deploy-Accelerator {
2020
[Alias("inputConfigFilePath")]
2121
[string[]] $inputConfigFilePaths = @(),
2222

23-
[Parameter(
24-
Mandatory = $false,
25-
HelpMessage = "[REQUIRED] The infrastructure as code type to target. Supported options are 'bicep', 'bicep-classic', 'terraform' or 'local'. Environment variable: ALZ_iac_type. Config file input: iac_type.")]
26-
[Alias("i")]
27-
[Alias("iac")]
28-
[string] $iac_type = "",
29-
30-
[Parameter(
31-
Mandatory = $false,
32-
HelpMessage = "[REQUIRED] The bootstrap module to deploy. Environment variable: ALZ_bootstrap_module_name. Config file input: bootstrap_module_name."
33-
)]
34-
[Alias("b")]
35-
[Alias("bootstrap")]
36-
[string] $bootstrap_module_name = "",
37-
38-
[Parameter(
39-
Mandatory = $false,
40-
HelpMessage = "[REQUIRED] The starter module to deploy. Environment variable: ALZ_starter_module_name. Config file input: starter_module_name."
41-
)]
42-
[Alias("s")]
43-
[Alias("starter")]
44-
[string] $starter_module_name = "",
45-
4623
[Parameter(
4724
Mandatory = $false,
4825
HelpMessage = "[OPTIONAL] The additional files or folders to be copied directly to the starter module root folder. Environment variable: ALZ_starter_additional_files. Config file input: starter_additional_files."
@@ -254,12 +231,12 @@ function Deploy-Accelerator {
254231
$inputConfig = Convert-ParametersToInputConfig -inputConfig $inputConfig -parameters $parametersWithValues
255232

256233
# Throw if IAC type is not specified
257-
if ($inputConfig.iac_type.Value -eq "") {
234+
if (!$inputConfig.iac_type.Value) {
258235
Write-InformationColored "No Infrastructure as Code type has been specified. Please supply the IAC type you wish to deploy..." -ForegroundColor Red -InformationAction Continue
259-
throw"No Infrastructure as Code type has been specified. Please supply the IAC type you wish to deploy..."
236+
throw "No Infrastructure as Code type has been specified. Please supply the IAC type you wish to deploy..."
260237
}
261238

262-
if ($inputConfig.iac_type.Value -like "bicep*") {
239+
if ($inputConfig.iac_type.Value.ToString() -like "bicep*") {
263240
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
264241
}
265242

@@ -301,14 +278,16 @@ function Deploy-Accelerator {
301278
$zonesSupport = $null
302279

303280
# Request the bootstrap type if not already specified
304-
if($inputConfig.bootstrap_module_name.Value -eq "") {
281+
if(!$inputConfig.bootstrap_module_name.Value) {
305282
Write-InformationColored "No bootstrap module has been specified. Please supply the bootstrap module you wish to deploy..." -ForegroundColor Red -InformationAction Continue
306283
throw "No bootstrap module has been specified. Please supply the bootstrap module you wish to deploy..."
307284
}
308285

286+
$bootstrap_module_name = $inputConfig.bootstrap_module_name.Value.Trim()
287+
309288
$bootstrapAndStarterConfig = Get-BootstrapAndStarterConfig `
310289
-iac $inputConfig.iac_type.Value `
311-
-bootstrap $inputConfig.bootstrap_module_name.Value `
290+
-bootstrap $bootstrap_module_name `
312291
-bootstrapPath $bootstrapPath `
313292
-bootstrapConfigPath $inputConfig.bootstrap_config_path.Value `
314293
-toolsPath $toolsPath

src/Tests/Unit/Public/Deploy-Accelerator.Tests.ps1

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,19 @@ InModuleScope 'ALZ' {
4545
Mock -CommandName Copy-Item -MockWith { }
4646

4747
Mock -CommandName Get-ALZConfig -MockWith {
48-
@{
48+
[PSCustomObject]@{
49+
"iac_type" = @{
50+
Value = "bicep"
51+
Source = "yaml"
52+
}
53+
"bootstrap_module_name" = @{
54+
Value = "platform_landing_zone"
55+
Source = "yaml"
56+
}
57+
"starter_module_name" = @{
58+
Value = "alz_github"
59+
Source = "yaml"
60+
}
4961
"module_url" = "test"
5062
"version" = "v1.0.0"
5163
"deployment_files" = @(
@@ -146,13 +158,13 @@ InModuleScope 'ALZ' {
146158
}
147159

148160
It 'should call the correct functions for bicep module configuration' {
149-
Deploy-Accelerator -i "bicep" -b "github" -inputs "example.yml"
161+
Deploy-Accelerator -inputs "example.yml"
150162
Assert-MockCalled -CommandName Get-BootstrapAndStarterConfig -Exactly 1
151163
Assert-MockCalled -CommandName New-ModuleSetup -Exactly 2
152164
}
153165

154166
It 'should call the correct functions for terraform module configuration' {
155-
Deploy-Accelerator -i "terraform" -b "github" -inputs "example.yml"
167+
Deploy-Accelerator -inputs "example.yml"
156168
Assert-MockCalled -CommandName Get-BootstrapAndStarterConfig -Exactly 1
157169
Assert-MockCalled -CommandName New-Bootstrap -Exactly 1
158170
Assert-MockCalled -CommandName New-ModuleSetup -Exactly 2

0 commit comments

Comments
 (0)