How to Install Terraform on Windows

Terraform, a widely embraced tool in the Linux community, has seamlessly extended its reach to Windows. To ensure a smooth installation process, make sure you have PowerShell version 4 or later installed. While it’s explicitly recommended for Windows 10/11 Desktop, Windows Server 2012, and Windows Server 2016, it may also be compatible with other Windows versions, though untested.

The Easy Way To Install Terraform on Windows

The easiest way to install Terraform on Windows is to use the Chocolatey package manager.

Step 1 – Enable Chocolatey on your Windows Desktop

To use Chocolatey, you need to have it installed on your desktop

First Check if you already have it installed. Open PowerShell and type:

PowerShell
choco 

You should see output like this:

PowerShell
PS C:\Windows\system32> choco
Chocolatey v2.2.2
Please run 'choco -?' or 'choco <command> -?' for help menu.

If you get no response, or an error, you need to install chocolatey

PowerShell
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))

If Chocolatey is already installed, you will get this message:

PowerShell
WARNING: 'choco' was found at 'C:\ProgramData\chocolatey\bin\choco.exe'.
WARNING: An existing Chocolatey installation was detected. Installation will not continue. This script will not
overwrite existing installations.
If there is no Chocolatey installation at 'C:\ProgramData\chocolatey', delete the folder and attempt the installation
again.

Please use choco upgrade chocolatey to handle upgrades of Chocolatey itself.
If the existing installation is not functional or a prior installation did not complete, follow these steps:
 - Backup the files at the path listed above so you can restore your previous installation if needed.
 - Remove the existing installation manually.
 - Rerun this installation script.
 - Reinstall any packages previously installed, if needed (refer to the lib folder in the backup).

Once installation is completed, the backup folder is no longer needed and can be deleted.

Step 2 – Install Terraform Via Chocolatey

PowerShell
choco install terraform

When Prompted – type A for ALL

Upon completion, you should see the following output:

PowerShell
PS C:\Windows\system32> choco install terraform
Chocolatey v2.2.2
Installing the following packages:
terraform
By installing, you accept licenses for the packages.
Progress: Downloading terraform 1.7.0... 100%

terraform v1.7.0 [Approved]
terraform package files install completed. Performing other installation steps.
The package terraform wants to run 'chocolateyInstall.ps1'.
Note: If you don't run this script, the installation will fail.
Note: To confirm automatically next time, use '-y' or consider:
choco feature enable -n allowGlobalConfirmation
Do you want to run the script?([Y]es/[A]ll - yes to all/[N]o/[P]rint): a

Removing old terraform plugins
Downloading terraform 64 bit
  from 'https://releases.hashicorp.com/terraform/1.7.0/terraform_1.7.0_windows_amd64.zip'
Progress: 100% - Completed download of C:\Users\richi\AppData\Local\Temp\chocolatey\terraform\1.7.0\terraform_1.7.0_windows_amd64.zip (25.05 MB).
Download of terraform_1.7.0_windows_amd64.zip (25.05 MB) completed.
Hashes match.
Extracting C:\Users\richi\AppData\Local\Temp\chocolatey\terraform\1.7.0\terraform_1.7.0_windows_amd64.zip to C:\ProgramData\chocolatey\lib\terraform\tools...
C:\ProgramData\chocolatey\lib\terraform\tools
 ShimGen has successfully created a shim for terraform.exe
 The install of terraform was successful.
  Software installed to 'C:\ProgramData\chocolatey\lib\terraform\tools'

Chocolatey installed 1/1 packages.
 See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
PS C:\Windows\system32>

Step 3 – Run Terraform on Windows

Now simply type Terraform in your PowerShell window, and it should all be good to go.

PowerShell
PS C:\Windows\system32> terraform
Usage: terraform [global options] <subcommand> [args]

The available commands for execution are listed below.
The primary workflow commands are given first, followed by
less common or more advanced commands.

Main commands:
  init          Prepare your working directory for other commands
  validate      Check whether the configuration is valid
  plan          Show changes required by the current configuration
  apply         Create or update infrastructure
  destroy       Destroy previously-created infrastructure

All other commands:
  console       Try Terraform expressions at an interactive command prompt
  fmt           Reformat your configuration in the standard style
  force-unlock  Release a stuck lock on the current workspace
  get           Install or upgrade remote Terraform modules
  graph         Generate a Graphviz graph of the steps in an operation
  import        Associate existing infrastructure with a Terraform resource
  login         Obtain and save credentials for a remote host
  logout        Remove locally-stored credentials for a remote host
  metadata      Metadata related commands
  output        Show output values from your root module
  providers     Show the providers required for this configuration
  refresh       Update the state to match remote systems
  show          Show the current state or a saved plan
  state         Advanced state management
  taint         Mark a resource instance as not fully functional
  test          Execute integration tests for Terraform modules
  untaint       Remove the 'tainted' state from a resource instance
  version       Show the current Terraform version
  workspace     Workspace management

Global options (use these before the subcommand, if any):
  -chdir=DIR    Switch to a different working directory before executing the
                given subcommand.
  -help         Show this help output, or the help for a specified subcommand.
  -version      An alias for the "version" subcommand.
PS C:\Windows\system32>
Elsewhere On TurboGeek:  Upgrade Domain Controller from Windows Server 2003 to 2016

You may also like...

2 Responses

  1. 19/10/2022

    […] How to Install Terraform on Windows […]

  2. 02/11/2022

    […] Learn how to install Terraform on Windows here. […]

Leave a Reply

Your email address will not be published. Required fields are marked *

Translate ยป