diff --git a/src/ALZ/Private/Tools/Get-TerraformTool.ps1 b/src/ALZ/Private/Tools/Get-TerraformTool.ps1 index 52584f0..5cc8a12 100644 --- a/src/ALZ/Private/Tools/Get-TerraformTool.ps1 +++ b/src/ALZ/Private/Tools/Get-TerraformTool.ps1 @@ -39,44 +39,42 @@ 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") { @@ -84,7 +82,4 @@ function Get-TerraformTool { } else { $env:PATH = "$($unzipdir):$env:PATH" } - - Remove-Item $zipfilePath - Write-Verbose "Installed Terraform version $version" }