Skip to content

Instantly share code, notes, and snippets.

@HammoTime
Last active April 22, 2019 11:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HammoTime/e403a114581daa42784683b01882cbcc to your computer and use it in GitHub Desktop.
Save HammoTime/e403a114581daa42784683b01882cbcc to your computer and use it in GitHub Desktop.
Install Terraform on Windows
$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