Skip to content

Commit c7c9165

Browse files
committed
fix: linux second run terraform path
1 parent faa3d39 commit c7c9165

File tree

1 file changed

+24
-29
lines changed

1 file changed

+24
-29
lines changed

src/ALZ/Private/Tools/Get-TerraformTool.ps1

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -39,52 +39,47 @@ function Get-TerraformTool {
3939
}
4040
}
4141

42+
$osArchitecture = Get-OSArchitecture
43+
Write-Verbose "Detected OS: $($osArchitecture.os), Architecture: $($osArchitecture.architecture)"
44+
4245
$unzipdir = Join-Path -Path $toolsPath -ChildPath "terraform_$version"
46+
4347
if (Test-Path $unzipdir) {
4448
Write-Verbose "Terraform $version already installed, adding to Path."
45-
if($os -eq "windows") {
46-
$env:PATH = "$($unzipdir);$env:PATH"
47-
} else {
48-
$env:PATH = "$($unzipdir):$env:PATH"
49-
}
50-
return
51-
}
52-
53-
$osArchitecture = Get-OSArchitecture
54-
55-
$zipfilePath = "$unzipdir.zip"
49+
} else {
50+
$zipfilePath = "$unzipdir.zip"
5651

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

59-
if(!(Test-Path $toolsPath)) {
60-
New-Item -ItemType Directory -Path $toolsPath| Out-String | Write-Verbose
61-
}
54+
if(!(Test-Path $toolsPath)) {
55+
New-Item -ItemType Directory -Path $toolsPath| Out-String | Write-Verbose
56+
}
6257

63-
Invoke-WebRequest -Uri $url -OutFile "$zipfilePath" | Out-String | Write-Verbose
58+
Invoke-WebRequest -Uri $url -OutFile "$zipfilePath" | Out-String | Write-Verbose
6459

65-
Expand-Archive -Path $zipfilePath -DestinationPath $unzipdir
60+
Expand-Archive -Path $zipfilePath -DestinationPath $unzipdir
6661

67-
$toolFileName = "terraform"
62+
$toolFileName = "terraform"
6863

69-
if($osArchitecture.os -eq "windows") {
70-
$toolFileName = "$($toolFileName).exe"
71-
}
64+
if($osArchitecture.os -eq "windows") {
65+
$toolFileName = "$($toolFileName).exe"
66+
}
7267

73-
$toolFilePath = Join-Path -Path $unzipdir -ChildPath $toolFileName
68+
$toolFilePath = Join-Path -Path $unzipdir -ChildPath $toolFileName
7469

75-
if($osArchitecture.os -ne "windows") {
76-
$isExecutable = $(test -x $toolFilePath; 0 -eq $LASTEXITCODE)
77-
if(!($isExecutable)) {
78-
chmod +x $toolFilePath
70+
if($osArchitecture.os -ne "windows") {
71+
$isExecutable = $(test -x $toolFilePath; 0 -eq $LASTEXITCODE)
72+
if(!($isExecutable)) {
73+
chmod +x $toolFilePath
74+
}
7975
}
76+
Write-Verbose "Installed Terraform version $version"
77+
Remove-Item $zipfilePath | Out-String | Write-Verbose
8078
}
8179

8280
if($osArchitecture.os -eq "windows") {
8381
$env:PATH = "$($unzipdir);$env:PATH"
8482
} else {
8583
$env:PATH = "$($unzipdir):$env:PATH"
8684
}
87-
88-
Remove-Item $zipfilePath
89-
Write-Verbose "Installed Terraform version $version"
9085
}

0 commit comments

Comments
 (0)