Skip to content

Commit 8ed310d

Browse files
bug: fix switch and os selector (#75)
1 parent 6c6953c commit 8ed310d

File tree

2 files changed

+49
-17
lines changed

2 files changed

+49
-17
lines changed

src/ALZ/Private/Get-HCLParserTool.ps1

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,34 @@ function Get-HCLParserTool {
2020
$os = "darwin"
2121
}
2222

23-
$architecture = $($env:PROCESSOR_ARCHITECTURE).ToLower()
24-
$toolFileName = "hcl2json_$($os)_$($architecture)"
23+
# Enum values can be seen here: https://learn.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.architecture?view=net-7.0#fields
24+
$architecture = ([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture).ToString().ToLower()
25+
26+
if($architecture -eq "x64") {
27+
$architecture = "amd64"
28+
}
29+
if($architecture -eq "x86") {
30+
$architecture = "386"
31+
}
32+
33+
$osAndArchitecture = "$($os)_$($architecture)"
34+
35+
$supportedOsAndArchitectures = @(
36+
"darwin_amd64",
37+
"darwin_arm64",
38+
"linux_386",
39+
"linux_amd64",
40+
"linux_arm64",
41+
"windows_386",
42+
"windows_amd64"
43+
)
44+
45+
if($supportedOsAndArchitectures -notcontains $osAndArchitecture) {
46+
Write-Error "Unsupported OS and architecture combination: $osAndArchitecture"
47+
exit 1
48+
}
49+
50+
$toolFileName = "hcl2json_$osAndArchitecture"
2551

2652
if($os -eq "windows") {
2753
$toolFileName = "$($toolFileName).exe"
@@ -32,6 +58,13 @@ function Get-HCLParserTool {
3258
if(!(Test-Path $toolFilePath)) {
3359
Invoke-WebRequest -Uri "https://github.com/tmccombs/hcl2json/releases/download/$($toolVersion)/$($toolFileName)" -OutFile "$toolFilePath" | Out-String | Write-Verbose
3460
}
61+
62+
if($os -ne "windows") {
63+
$isExecutable = $(test -x $toolFilePath; 0 -eq $LASTEXITCODE)
64+
if(!($isExecutable)) {
65+
chmod +x $toolFilePath
66+
}
67+
}
3568
}
3669

3770
return $toolFilePath

src/ALZ/Public/New-ALZEnvironment.ps1

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,22 +58,21 @@ function New-ALZEnvironment {
5858
Write-InformationColored "Getting ready to create a new ALZ environment with you..." -ForegroundColor Green -InformationAction Continue
5959

6060
if ($PSCmdlet.ShouldProcess("Accelerator setup", "modify")) {
61-
switch($alzIacProvider) {
62-
"bicep" {
63-
if($alzVersion -eq "") {
64-
$alzVersion = "v0.16.3"
65-
}
66-
New-ALZEnvironmentBicep -alzEnvironmentDestination $alzEnvironmentDestination -alzVersion $alzVersion -alzCicdPlatform $alzCicdPlatform
61+
if($alzIacProvider -eq "bicep") {
62+
if($alzVersion -eq "") {
63+
$alzVersion = "v0.16.3"
6764
}
68-
"terraform" {
69-
if($alzVersion -eq "") {
70-
$alzVersion = "latest"
71-
}
72-
if($autoApprove) {
73-
New-ALZEnvironmentTerraform -alzEnvironmentDestination $alzEnvironmentDestination -alzVersion $alzVersion -alzCicdPlatform $alzCicdPlatform -userInputOverridePath $userInputOverridePath -autoApprove
74-
} else {
75-
New-ALZEnvironmentTerraform -alzEnvironmentDestination $alzEnvironmentDestination -alzVersion $alzVersion -alzCicdPlatform $alzCicdPlatform -userInputOverridePath $userInputOverridePath
76-
}
65+
New-ALZEnvironmentBicep -alzEnvironmentDestination $alzEnvironmentDestination -alzVersion $alzVersion -alzCicdPlatform $alzCicdPlatform
66+
}
67+
68+
if($alzIacProvider -eq "terraform") {
69+
if($alzVersion -eq "") {
70+
$alzVersion = "latest"
71+
}
72+
if($autoApprove) {
73+
New-ALZEnvironmentTerraform -alzEnvironmentDestination $alzEnvironmentDestination -alzVersion $alzVersion -alzCicdPlatform $alzCicdPlatform -userInputOverridePath $userInputOverridePath -autoApprove
74+
} else {
75+
New-ALZEnvironmentTerraform -alzEnvironmentDestination $alzEnvironmentDestination -alzVersion $alzVersion -alzCicdPlatform $alzCicdPlatform -userInputOverridePath $userInputOverridePath
7776
}
7877
}
7978
}

0 commit comments

Comments
 (0)