Last active
April 22, 2019 11:27
-
-
Save HammoTime/e403a114581daa42784683b01882cbcc to your computer and use it in GitHub Desktop.
Install Terraform on Windows
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$VersionInfo = ((Invoke-WebRequest https://api.github.com/repos/hashicorp/terraform/releases/latest).Content | ConvertFrom-Json).tag_name | |
$VersionInfo = $VersionInfo.Replace("v", "") | |
Write-Host "Installing Terraform $VersionInfo." | |
$Url = "https://releases.hashicorp.com/terraform/" + $VersionInfo + "/terraform_" + $VersionInfo + "_windows_amd64.zip" | |
$InstallDirectory = [Environment]::GetFolderPath([Environment+SpecialFolder]::ApplicationData) + "\Terraform" | |
if(Test-Path $InstallDirectory) { | |
Remove-Item $InstallDirectory -Recurse | |
} | |
Write-Host "Creating install directory." | |
New-Item -ItemType Directory -Path $InstallDirectory | Out-Null | |
$InstallFile = $InstallDirectory + "\terraform_" + $VersionInfo + "_windows_amd64.zip" | |
Write-Host "Downloading Terraform executable." | |
Invoke-WebRequest -Uri $Url -OutFile $InstallFile | |
Write-Host "Expanding archive." | |
Expand-Archive -Path $InstallFile -DestinationPath $InstallDirectory -Force | |
if($Env:Path -notlike "*" + $InstallDirectory + "*") { | |
Write-Host "Adding directory to path." | |
$Path = (Get-ItemProperty -Path 'Registry::HKEY_CURRENT_USER\Environment' -Name PATH).Path | |
$Path = $InstallDirectory + ";" + $Path | |
Set-ItemProperty -Path 'Registry::HKEY_CURRENT_USER\Environment' -Name PATH –Value $Path | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment