How to install Terraform on Windows using Chocolatey

Terraform is a tool for creating and changing infrastructure quickly and efficiently. Terraform can manage existing and popular service providers as well as custom in-house solutions.

Official website : https://www.terraform.io/

Chocolatey is a package manager for Windows that aims to automate the entire software lifecycle from install through upgrade and removal on Windows operating systems.

Official website: https://chocolatey.org/

Chocolatey installation

Know the Requirements:

  • Windows 7+ / Windows Server 2003+
  • PowerShell v2+ (minimum is v3 for install from this website due to TLS 1.2 requirement)
  • .NET Framework 4+ (the installation will attempt to install .NET 4.0 if you do not have it installed)(minimum is 4.5 for install from this website due to TLS 1.2 requirement)

Steps:

  • Open PowerShell cmd as Administrator
  • Type the following command and press Enter:
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
  • Wait for command to complete
  • Check that chocolatey is installed:
C:\WINDOWS\system32>choco version
Chocolatey v0.10.15

DEPRECATION NOTICE - choco version command is deprecated and will be
 removed in version 1.0.0. Please use `choco upgrade pkgname --noop`
 instead.
_ Chocolatey:ChocolateyVersionCommand - Noop Mode _
chocolatey v0.10.15 is the latest version available based on your source(s).

Chocolatey can upgrade 0/1 packages.
 See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).

Terraform installation

  • Open cmd as Administrator
  • Run the following command and press Enter
choco install -y terraform
  • Wait for command to finish
  • Check that terraform is installed :
C:\WINDOWS\system32>terraform
Usage: terraform [-version] [-help] <command> [args]

The available commands for execution are listed below.
The most common, useful commands are shown first, followed by
less common or more advanced commands. If you're just getting
started with Terraform, stick with the common commands. For the
other commands, please read the help and docs before usage.

Common commands:
    apply              Builds or changes infrastructure
    console            Interactive console for Terraform interpolations
    destroy            Destroy Terraform-managed infrastructure
    env                Workspace management
    fmt                Rewrites config files to canonical format
    get                Download and install modules for the configuration
    graph              Create a visual graph of Terraform resources
    import             Import existing infrastructure into Terraform
    init               Initialize a Terraform working directory
    login              Obtain and save credentials for a remote host
    logout             Remove locally-stored credentials for a remote host
    output             Read an output from a state file
    plan               Generate and show an execution plan
    providers          Prints a tree of the providers used in the configuration
    refresh            Update local state file against real resources
    show               Inspect Terraform state or plan
    taint              Manually mark a resource for recreation
    untaint            Manually unmark a resource as tainted
    validate           Validates the Terraform files
    version            Prints the Terraform version
    workspace          Workspace management

All other commands:
    0.12upgrade        Rewrites pre-0.12 module source code for v0.12
    debug              Debug output management (experimental)
    force-unlock       Manually unlock the terraform state
    push               Obsolete command for Terraform Enterprise legacy (v1)
    state              Advanced state management

Now, terraform is installed and you can start to manage your infrastructure. Check the official website for documentation.

Have fun.