Skip to content
Merged
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
53 changes: 24 additions & 29 deletions src/ALZ/Private/Tools/Get-TerraformTool.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -39,52 +39,47 @@ function Get-TerraformTool {
}
}

$osArchitecture = Get-OSArchitecture
Write-Verbose "Detected OS: $($osArchitecture.os), Architecture: $($osArchitecture.architecture)"

$unzipdir = Join-Path -Path $toolsPath -ChildPath "terraform_$version"

if (Test-Path $unzipdir) {
Write-Verbose "Terraform $version already installed, adding to Path."
if($os -eq "windows") {
$env:PATH = "$($unzipdir);$env:PATH"
} else {
$env:PATH = "$($unzipdir):$env:PATH"
}
return
}

$osArchitecture = Get-OSArchitecture

$zipfilePath = "$unzipdir.zip"
} else {
$zipfilePath = "$unzipdir.zip"

$url = $release.builds | Where-Object { $_.arch -eq $osArchitecture.architecture -and $_.os -eq $osArchitecture.os } | Select-Object -First 1 -ExpandProperty url
$url = $release.builds | Where-Object { $_.arch -eq $osArchitecture.architecture -and $_.os -eq $osArchitecture.os } | Select-Object -First 1 -ExpandProperty url

if(!(Test-Path $toolsPath)) {
New-Item -ItemType Directory -Path $toolsPath| Out-String | Write-Verbose
}
if(!(Test-Path $toolsPath)) {
New-Item -ItemType Directory -Path $toolsPath| Out-String | Write-Verbose
}

Invoke-WebRequest -Uri $url -OutFile "$zipfilePath" | Out-String | Write-Verbose
Invoke-WebRequest -Uri $url -OutFile "$zipfilePath" | Out-String | Write-Verbose

Expand-Archive -Path $zipfilePath -DestinationPath $unzipdir
Expand-Archive -Path $zipfilePath -DestinationPath $unzipdir

$toolFileName = "terraform"
$toolFileName = "terraform"

if($osArchitecture.os -eq "windows") {
$toolFileName = "$($toolFileName).exe"
}
if($osArchitecture.os -eq "windows") {
$toolFileName = "$($toolFileName).exe"
}

$toolFilePath = Join-Path -Path $unzipdir -ChildPath $toolFileName
$toolFilePath = Join-Path -Path $unzipdir -ChildPath $toolFileName

if($osArchitecture.os -ne "windows") {
$isExecutable = $(test -x $toolFilePath; 0 -eq $LASTEXITCODE)
if(!($isExecutable)) {
chmod +x $toolFilePath
if($osArchitecture.os -ne "windows") {
$isExecutable = $(test -x $toolFilePath; 0 -eq $LASTEXITCODE)
if(!($isExecutable)) {
chmod +x $toolFilePath
}
}
Write-Verbose "Installed Terraform version $version"
Remove-Item $zipfilePath | Out-String | Write-Verbose
}

if($osArchitecture.os -eq "windows") {
$env:PATH = "$($unzipdir);$env:PATH"
} else {
$env:PATH = "$($unzipdir):$env:PATH"
}

Remove-Item $zipfilePath
Write-Verbose "Installed Terraform version $version"
}
Loading