Skip to content

Commit

Permalink
bug: fix switch and os selector (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredfholgate authored Oct 3, 2023
1 parent 6c6953c commit 8ed310d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 17 deletions.
37 changes: 35 additions & 2 deletions src/ALZ/Private/Get-HCLParserTool.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,34 @@ function Get-HCLParserTool {
$os = "darwin"
}

$architecture = $($env:PROCESSOR_ARCHITECTURE).ToLower()
$toolFileName = "hcl2json_$($os)_$($architecture)"
# 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") {
$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"
Expand All @@ -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
Expand Down
29 changes: 14 additions & 15 deletions src/ALZ/Public/New-ALZEnvironment.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down

0 comments on commit 8ed310d

Please sign in to comment.