How to Install Terraform on Windows 10/11 Using Winget

  • Thread Author
Deploying infrastructure efficiently has become the cornerstone of modern DevOps practices. If you're looking for a powerful tool to automate cloud provisioning and manage your infrastructure as code, Terraform is your go-to option. Developed by HashiCorp, this open-source tool allows users to define and provision infrastructure using a high-level configuration language — either HashiCorp Configuration Language (HCL) or JSON. Whether you're a systems administrator or a budding DevOps professional, mastering Terraform can significantly boost your productivity.
If you're using Windows 10 or 11, you're in luck! This guide will provide you with a step-by-step walkthrough on how to quickly install Terraform using Winget, Microsoft’s package manager that simplifies the installation process.

Why Use Winget?​

Winget (Windows Package Manager) is a command-line tool that helps you find, install, upgrade, and remove software packages. Its intuitive interface allows for rapid package management right from the command line. And for our Terraform installation, it's as easy as running a single command!

Step-by-Step Guide to Installing Terraform with Winget​

Step 1: Access the Command Prompt or PowerShell​

To begin, you’ll need administrative access to the command line. You can do this by right-clicking on the Start Menu and selecting Terminal (Admin) or Windows PowerShell (Admin).

Step 2: Verify Winget is Installed​

Winget is bundled with newer versions of Windows 10 (1809 and later) and Windows 11. To check if Winget is installed, execute the following command:
Bash:
 winget --version
If you see a version number, you’re good to go! If not, you can install it from the Microsoft Store or run this PowerShell command:
Bash:
 Add-AppxPackage -RegisterByFamilyName -MainPackage Microsoft.DesktopAppInstaller_8wekyb3d8bbwe

Step 3: Search for Terraform in Winget​

Before we dive into the installation, let’s confirm if Terraform is available via Winget. Run:
Bash:
 winget search terraform
This command will list any packages containing "Terraform" in their name.

Step 4: Install Terraform on Windows 10 or 11​

If Terraform is available, you can easily install it with:
Bash:
 winget install HashiCorp.Terraform
This command downloads and installs Terraform, configuring the system variables for immediate use.

Step 5: Verify the Terraform Installation​

Once the installation is complete, close your terminal and reopen it. This ensures the environment variable for Terraform is recognized by your command line shell. Now, check if Terraform is installed correctly:
Bash:
 terraform -v
If everything went smoothly, you should see the installed version of Terraform.

Step 6: Testing Terraform Installation​

To confirm that Terraform is functioning properly, let's run a quick test. Create a new directory for Terraform configuration:
Bash:
 mkdir terraform-test cd terraform-test
Next, create a simple Terraform configuration file main.tf using Notepad or any text editor:
Bash:
 notepad main.tf
Add the following content to main.tf:
Code:
 terraform { required_providers { local = { source = "hashicorp/local" version = "~> 2.0" } } } provider "local" {} resource "local_file" "example" { content = "Hello, Terraform!" filename = "${path.module}/hello.txt" }
After saving the changes, initialize the configuration:
Bash:
 terraform init
Apply the configuration to generate a file:
Bash:
 terraform apply
If everything went according to plan, Terraform will create a file named hello.txt in your project directory containing the message: "Hello, Terraform!". You can verify it with:
Bash:
 cat hello.txt

Updating or Uninstalling Terraform​

Should you need to upgrade to a newer version later, use:
Bash:
 winget upgrade HashiCorp.Terraform
And if you decide to uninstall Terraform, simply run:
Bash:
 winget uninstall HashiCorp.Terraform

Conclusion​

Installing Terraform on Windows 10 or 11 using Winget is a straightforward and efficient process. By leveraging this command-line tool, you can seamlessly manage your software installations, keeping your development environment up-to-date without the hassle of GUI interactions. Terraform's capabilities can greatly enhance your infrastructure management, making it a worthwhile addition to any developer or sysadmin's toolkit.
Now that you have learned how to install Terraform, are you ready to automate your infrastructure? If you have any questions or need further assistance, feel free to ask!
Source: How2shout How to install Terraform on Windows 11 or 10 using Winget