Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 43 additions & 15 deletions src/ALZ/Private/Tools/Test-Tooling.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ function Test-Tooling {
[Parameter(Mandatory = $false)]
[switch]$skipAlzModuleVersionCheck,
[Parameter(Mandatory = $false)]
[switch]$checkYamlModule
[switch]$checkYamlModule,
[Parameter(Mandatory = $false)]
[switch]$skipYamlModuleInstall
)

$checkResults = @()
Expand Down Expand Up @@ -157,12 +159,22 @@ function Test-Tooling {
}
}

$currentScope = "CurrentUser"

if($skipAlzModuleVersionCheck.IsPresent) {
Write-Verbose "Skipping ALZ module version check"
} else {
# Check if latest ALZ module is installed
Write-Verbose "Checking ALZ module version"
$alzModuleCurrentVersion = Get-InstalledPSResource -Name ALZ | Select-Object -Property Name, Version | Sort-Object Version -Descending | Select-Object -First 1
$alzModuleCurrentVersion = Get-InstalledPSResource -Name ALZ 2>$null | Select-Object -Property Name, Version | Sort-Object Version -Descending | Select-Object -First 1
if($null -eq $alzModuleCurrentVersion) {
Write-Verbose "ALZ module not found in CurrentUser scope, checking AllUsers scope"
$alzModuleCurrentVersion = Get-InstalledPSResource -Name ALZ -Scope AllUsers 2>$null | Select-Object -Property Name, Version | Sort-Object Version -Descending | Select-Object -First 1
if($null -ne $alzModuleCurrentVersion) {
Write-Verbose "ALZ module found in AllUsers scope"
$currentScope = "AllUsers"
}
}

if($null -eq $alzModuleCurrentVersion) {
$checkResults += @{
Expand Down Expand Up @@ -191,31 +203,47 @@ function Test-Tooling {
# Check if powershell-yaml module is installed (only when YAML files are being used)
if ($checkYamlModule.IsPresent) {
Write-Verbose "Checking powershell-yaml module installation"
$yamlModule = Get-InstalledPSResource -Name powershell-yaml 2> $null
$yamlModule = Get-InstalledPSResource -Name powershell-yaml 2> $null | Select-Object -Property Name, Version | Sort-Object Version -Descending | Select-Object -First 1
if($null -eq $yamlModule) {
Write-Verbose "powershell-yaml module not found in CurrentUser scope, checking AllUsers scope"
$yamlModule = Get-InstalledPSResource -Name powershell-yaml -Scope AllUsers 2> $null | Select-Object -Property Name, Version | Sort-Object Version -Descending | Select-Object -First 1
}

if ($yamlModule) {
$checkResults += @{
message = "powershell-yaml module is installed (version $($yamlModule.Version))."
result = "Success"
}
} elseif ($skipYamlModuleInstall.IsPresent) {
Write-Verbose "powershell-yaml module is not installed, skipping installation attempt"
$checkResults += @{
message = "powershell-yaml module is not installed. Please install it using 'Install-PSResource powershell-yaml -Scope $currentScope'."
result = "Failure"
}
$hasFailure = $true
} else {
$installSuccessful = $false
try {
Install-PSResource powershell-yaml -TrustRepository
$installSuccessful = $true
} catch {
Write-Verbose "Failed to install powershell-yaml module"
}
if($installSuccessful) {
Write-Verbose "powershell-yaml module is not installed, attempting installation"
$installResult = Install-PSResource powershell-yaml -TrustRepository -Scope $currentScope 2>&1
if($installResult -like "*Access to the path*") {
Write-Verbose "Failed to install powershell-yaml module due to permission issues at $currentScope scope."
$checkResults += @{
message = "powershell-yaml module was not installed, but has been successfully installed (version $((Get-InstalledPSResource -Name powershell-yaml).Version))."
result = "Success"
message = "powershell-yaml module is not installed. Please install it using an admin terminal with 'Install-PSResource powershell-yaml -Scope $currentScope'. Could not install due to permission issues."
result = "Failure"
}
} else {
$hasFailure = $true
} elseif ($null -ne $installResult) {
Write-Verbose "Failed to install powershell-yaml module: $installResult"
$checkResults += @{
message = "powershell-yaml module is not installed. Please install it using 'Install-PSResource powershell-yaml'."
message = "powershell-yaml module is not installed. Please install it using 'Install-PSResource powershell-yaml -Scope $currentScope'. Attempted installation error: $installResult"
result = "Failure"
}
$hasFailure = $true
} else {
$installedVersion = (Get-InstalledPSResource -Name powershell-yaml -Scope $currentScope).Version
$checkResults += @{
message = "powershell-yaml module was not installed, but has been successfully installed (version $installedVersion)."
result = "Success"
}
}
}
}
Expand Down
9 changes: 8 additions & 1 deletion src/ALZ/Public/Deploy-Accelerator.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,13 @@ function Deploy-Accelerator {
[Alias("skipAlzModuleVersionRequirementsCheck")]
[switch] $skip_alz_module_version_requirements_check,

[Parameter(
Mandatory = $false,
HelpMessage = "[OPTIONAL] Determines whether to skip attempting to install the powershell-yaml module if it is not installed."
)]
[Alias("skipYamlModuleInstall")]
[switch] $skip_yaml_module_install,

[Parameter(
Mandatory = $false,
HelpMessage = "[OPTIONAL] Determines whether Clean the bootstrap folder of Terraform meta files. Only use for development purposes."
Expand Down Expand Up @@ -204,7 +211,7 @@ function Deploy-Accelerator {
Write-InformationColored "WARNING: Skipping the software requirements check..." -ForegroundColor Yellow -InformationAction Continue
} else {
Write-InformationColored "Checking the software requirements for the Accelerator..." -ForegroundColor Green -InformationAction Continue
Test-Tooling -skipAlzModuleVersionCheck:$skip_alz_module_version_requirements_check.IsPresent -checkYamlModule:$hasYamlFiles
Test-Tooling -skipAlzModuleVersionCheck:$skip_alz_module_version_requirements_check.IsPresent -checkYamlModule:$hasYamlFiles -skipYamlModuleInstall:$skip_yaml_module_install.IsPresent
}

Write-InformationColored "Getting ready to deploy the accelerator with you..." -ForegroundColor Green -NewLineBefore -InformationAction Continue
Expand Down
Loading