Terraform, the open-source infrastructure-as-code (IaC) tool developed by HashiCorp, has gained significant traction among developers for its ability to automate cloud provisioning and manage infrastructure efficiently. This guide outlines the steps to install Terraform on Windows 10 or 11 using a single command via Winget, the Windows Package Manager.
Step-by-Step Guide to Installing Terraform with Winget
Step 1: Access the Command Prompt or PowerShell
To begin, you will need to access the command line interface. Right-click the Start menu button on your Windows 10 or 11 system and select either the Terminal (Admin) or Windows PowerShell (Admin) option to open it with administrative rights.
Step 2: Verify Winget is Installed
Winget is included as a pre-installed application in Windows 10 version 1809 and later, including Windows 11. To verify its presence, execute the following command:
winget --version
Note: If the command does not return a version number, you may need to install it from the Microsoft Store or use this PowerShell command:
Add-AppxPackage -RegisterByFamilyName -MainPackage Microsoft.DesktopAppInstaller_8wekyb3d8bbwe
Step 3: Search for Terraform in Winget
To confirm that Terraform is available for installation, search for it in the Winget repository with the following command:
winget search terraform
Step 4: Install Terraform on Windows 11 or 10
Once you have verified that Terraform is available, proceed with the installation by executing this command:
winget install HashiCorp.Terraform
This command will automatically download and install Terraform, configuring the necessary environment variables for system-wide accessibility.
Step 5: Verify the Terraform Installation
After installation, close your command terminal and reopen it to ensure the new environment variable is recognized. Then, check the installed version of Terraform with:
terraform -v
This will confirm the successful installation of Terraform.
Step 6: Testing Terraform Installation
To validate that Terraform is functioning correctly, create a simple test configuration:
mkdir terraform-test
cd terraform-test
Next, create a configuration file named main.tf:
notepad test.tf
Add the following content to the test.tf file and save it:
terraform {
required_providers {
local = {
source = "hashicorp/local"
version = "~> 2.0"
}
}
}
provider "local" {}
resource "local_file" "example" {
content = "Hello, Terraform!"
filename = "${path.module}/hello.txt"
}
Initialize the configuration by running:
terraform init
If successful, Terraform will create a hello.txt file in your directory. You can verify the content of the file by running:
Add-AppxPackage -RegisterByFamilyName -MainPackage Microsoft.DesktopAppInstaller_8wekyb3d8bbwe
0
Update and Uninstallation
To update Terraform to the latest version, use the following command:
Add-AppxPackage -RegisterByFamilyName -MainPackage Microsoft.DesktopAppInstaller_8wekyb3d8bbwe
1
To uninstall Terraform completely, run:
Add-AppxPackage -RegisterByFamilyName -MainPackage Microsoft.DesktopAppInstaller_8wekyb3d8bbwe
2