From ab69b40429d7621e4e833699c0f0ef3bc4b0020e Mon Sep 17 00:00:00 2001 From: Jared Holgate Date: Mon, 2 Oct 2023 22:12:19 +0100 Subject: [PATCH 1/3] Resolve issues --- src/ALZ/Private/Get-HCLParserTool.ps1 | 37 +++++++++++++++++++++++++-- src/ALZ/Public/New-ALZEnvironment.ps1 | 29 ++++++++++----------- 2 files changed, 49 insertions(+), 17 deletions(-) diff --git a/src/ALZ/Private/Get-HCLParserTool.ps1 b/src/ALZ/Private/Get-HCLParserTool.ps1 index 8dcb45ea..f0cca400 100644 --- a/src/ALZ/Private/Get-HCLParserTool.ps1 +++ b/src/ALZ/Private/Get-HCLParserTool.ps1 @@ -12,6 +12,7 @@ function Get-HCLParserTool { $os = "" if ($IsWindows) { $os = "windows" + $architecture = $($env:PROCESSOR_ARCHITECTURE).ToLower() } if($IsLinux) { $os = "linux" @@ -20,8 +21,33 @@ function Get-HCLParserTool { $os = "darwin" } - $architecture = $($env:PROCESSOR_ARCHITECTURE).ToLower() - $toolFileName = "hcl2json_$($os)_$($architecture)" + $architecture = ([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture).ToString().ToLower() + + if($architecture -eq "x64") { + $architecture = "amd64" + } + if($architecture -eq "x86") { + $architecture = "386" + } + + $osAndArchitecture = "$($os)_$($architecture)" + + $supportedOsAndArchitectures = @( + "darwin_amd64", + "darwin_arm64", + "linux_386", + "linux_amd64", + "linux_arm64", + "windows_386", + "windows_amd64" + ) + + if($supportedOsAndArchitectures -notcontains $osAndArchitecture) { + Write-Error "Unsupported OS and architecture combination: $osAndArchitecture" + exit 1 + } + + $toolFileName = "hcl2json_$osAndArchitecture" if($os -eq "windows") { $toolFileName = "$($toolFileName).exe" @@ -32,6 +58,13 @@ function Get-HCLParserTool { if(!(Test-Path $toolFilePath)) { Invoke-WebRequest -Uri "https://github.com/tmccombs/hcl2json/releases/download/$($toolVersion)/$($toolFileName)" -OutFile "$toolFilePath" | Out-String | Write-Verbose } + + if($os -ne "windows") { + $isExecutable = $(test -x $toolFilePath; 0 -eq $LASTEXITCODE) + if(!($isExecutable)) { + chmod +x $toolFilePath + } + } } return $toolFilePath diff --git a/src/ALZ/Public/New-ALZEnvironment.ps1 b/src/ALZ/Public/New-ALZEnvironment.ps1 index 1b90b86a..fd4f7731 100644 --- a/src/ALZ/Public/New-ALZEnvironment.ps1 +++ b/src/ALZ/Public/New-ALZEnvironment.ps1 @@ -58,22 +58,21 @@ function New-ALZEnvironment { Write-InformationColored "Getting ready to create a new ALZ environment with you..." -ForegroundColor Green -InformationAction Continue if ($PSCmdlet.ShouldProcess("Accelerator setup", "modify")) { - switch($alzIacProvider) { - "bicep" { - if($alzVersion -eq "") { - $alzVersion = "v0.16.3" - } - New-ALZEnvironmentBicep -alzEnvironmentDestination $alzEnvironmentDestination -alzVersion $alzVersion -alzCicdPlatform $alzCicdPlatform + if($alzIacProvider -eq "bicep") { + if($alzVersion -eq "") { + $alzVersion = "v0.16.3" } - "terraform" { - if($alzVersion -eq "") { - $alzVersion = "latest" - } - if($autoApprove) { - New-ALZEnvironmentTerraform -alzEnvironmentDestination $alzEnvironmentDestination -alzVersion $alzVersion -alzCicdPlatform $alzCicdPlatform -userInputOverridePath $userInputOverridePath -autoApprove - } else { - New-ALZEnvironmentTerraform -alzEnvironmentDestination $alzEnvironmentDestination -alzVersion $alzVersion -alzCicdPlatform $alzCicdPlatform -userInputOverridePath $userInputOverridePath - } + New-ALZEnvironmentBicep -alzEnvironmentDestination $alzEnvironmentDestination -alzVersion $alzVersion -alzCicdPlatform $alzCicdPlatform + } + + if($alzIacProvider -eq "terraform") { + if($alzVersion -eq "") { + $alzVersion = "latest" + } + if($autoApprove) { + New-ALZEnvironmentTerraform -alzEnvironmentDestination $alzEnvironmentDestination -alzVersion $alzVersion -alzCicdPlatform $alzCicdPlatform -userInputOverridePath $userInputOverridePath -autoApprove + } else { + New-ALZEnvironmentTerraform -alzEnvironmentDestination $alzEnvironmentDestination -alzVersion $alzVersion -alzCicdPlatform $alzCicdPlatform -userInputOverridePath $userInputOverridePath } } } From 1ce8417b934b3ae0c1d8bb54f4db14d6be14a876 Mon Sep 17 00:00:00 2001 From: Jared Holgate Date: Mon, 2 Oct 2023 22:20:04 +0100 Subject: [PATCH 2/3] REmove redundant code --- src/ALZ/Private/Get-HCLParserTool.ps1 | 1 - 1 file changed, 1 deletion(-) diff --git a/src/ALZ/Private/Get-HCLParserTool.ps1 b/src/ALZ/Private/Get-HCLParserTool.ps1 index f0cca400..d644134d 100644 --- a/src/ALZ/Private/Get-HCLParserTool.ps1 +++ b/src/ALZ/Private/Get-HCLParserTool.ps1 @@ -12,7 +12,6 @@ function Get-HCLParserTool { $os = "" if ($IsWindows) { $os = "windows" - $architecture = $($env:PROCESSOR_ARCHITECTURE).ToLower() } if($IsLinux) { $os = "linux" From 74d813809b58f2f4a7cd3daa9308c8bdeb742653 Mon Sep 17 00:00:00 2001 From: Jared Holgate Date: Mon, 2 Oct 2023 22:21:31 +0100 Subject: [PATCH 3/3] Add comment --- src/ALZ/Private/Get-HCLParserTool.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ALZ/Private/Get-HCLParserTool.ps1 b/src/ALZ/Private/Get-HCLParserTool.ps1 index d644134d..1772c17f 100644 --- a/src/ALZ/Private/Get-HCLParserTool.ps1 +++ b/src/ALZ/Private/Get-HCLParserTool.ps1 @@ -20,6 +20,7 @@ function Get-HCLParserTool { $os = "darwin" } + # Enum values can be seen here: https://learn.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.architecture?view=net-7.0#fields $architecture = ([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture).ToString().ToLower() if($architecture -eq "x64") {