Created
July 21, 2020 15:20
-
-
Save SQLDBAWithABeard/885dcb92385774a2ca3f60bdeb05448c to your computer and use it in GitHub Desktop.
Updating terraform version
This file contains hidden or 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
# based on https://github.com/guillermo-musumeci/terraform-update-version/blob/master/update-terraform.ps1 | |
# Adding version so we dont get a beta version! | |
# download the page of Terraform releases | |
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 | |
$WebResponse = Invoke-WebRequest "https://releases.hashicorp.com/terraform" | |
# Version = | |
$Version = '0.12.28' | |
$versionLink = $WebResponse.Links | Where OuterText -eq "terraform_$version" | |
# describe the file to download, for the 32-bits, use “ _windows_386.zip” instead | |
$tfFile = $versionLink.outerText + "_windows_amd64.zip" | |
# define the full URL of the file to download from the Terraform web site | |
$tfURL = "https://releases.hashicorp.com" + $versionLink.href + $tfFile | |
# search for Terraform in Path environment variable | |
$tfPath = $env:Path -split ';' | Where-Object {$_ -Match "Terraform"} | |
if(-not $tfPath){ | |
$tfPath = Read-Host "Please specify path to Terraform.exe" | |
} | |
# define the output file where we will download the .zip file of Terraform | |
$tfOutFile = "c:\temp\$tffile" | |
# download the .zip file from the Terraform web site | |
Invoke-WebRequest -Uri $tfURL -OutFile $tfOutFile | |
# extract the content of the .zip file to the Terraform folder | |
Expand-Archive -LiteralPath $tfOutFile -DestinationPath $tfPath -Force | |
# check version of Terraform installed | |
terraform -v |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment