How to Install Terraform on Windows 10 / Windows Server 2019

How to Install Terraform on Windows 10 / Windows Server 2019. In this article we will introduce what Terraform is with it’s features and pros and we will move onto the installation part with Scoop installer. Let’s get started. 

What is Terraform?

Terraform is a free, open source infrastructure as a code (IaC) tool that helps manage various cloud services.  Terraform is a cloud agnostic Infrastructure automation tool to manage cloud and on-prem resources in code.Terraform helps Networking, DNS and Database resources.

The powerful tool uses HashiCorp Configuration Language (a JSON like configuration language) to build, change and version infrastructure safely. DevOps Teams can apply the language syntax for provision and re provision infrastructure across multitier applications, on premises and in multiple clouds. You need CLI on your local system to get started. 

Terraform plugin based architecture can easily help to extend and connect with various providers (AWS, Google Cloud, etc.). One can also connect the open source tools with various infrastructure hosts for obtaining complex management scenarios.

If your organization is looking to deploy a hybrid cloud or multi cloud environment then it is a good choice to switch to using Terraform.

 

  • It is one of the most popular infrastructure automation tools available in the market.
  • DevOps engineers use Infrastructure as a code practice and programming to manage, monitor and provision resources.
  • This IT practice supports various external resource management, multi cloud deployments and multitier applications.
  • You can reduce human error by adapting infrastructure as a code software tool to manage infrastructure across clouds.
  • Terraform allows making incremental changes to resources and supports multiple cloud platforms.
  • You can also translate HCL code into JSON using Terraform.

How Does Terraform Work

Next part of our article how to Install Terraform on Windows 10 / Windows Server 2019 let’s find out how does Tearraform work? Terraform uses configuration files and version control to define and track the infrastructure. As a user gives the command to run or deploy a server or database, terraform pases the code by writing new plugins and translates them into API calls. 

There are two essential components, Terraform Core and Terraform Plugins that play a vital role in the smooth functioning of Terraform.

The role of Terraform Core is to oversee the interpolation of resource graphs, plans to add or remove infrastructure components, manage configuration files and management features. It also handles the requirement of provisioning or decommissioning of resources. This section comprises binaries that work as a command line interface (CLI). These binaries written in the Go programming language use remote procedure calls (RPC) to communicate with the plugins.

Terraform Plugins act as a specific service or a provisioner responsible for connecting Terraform Core with the infrastructure host or SaaS providers. They authenticate infrastructure providers and initialize API calls.

Transform your infrastructure resources as a code. Now, the Terraform will review and decide a plan to either add or remove resources. Once done, accept the planned changes. This is how Transform workflow works.

Features of Terraform

Write Declarative configuration files : Configuration files use Terraform language to declare resources. These files in terraform help update on which plugins require installation, what new resources to create, how to manage existing ones, what information to fetch and what you need to destroy. These also help in creating multiple similar resources.

Installable modules: Each Terraform configuration includes a minimum of one module. A module comprises multiple resources that help create lightweight abstractions for describing infrastructure. These are easy to write and share. Also, one can automatically download if included in configuration and install modules from the Terraform registry.

Plan and predict changes: DevOps engineers or operators have complete access to create an execution plan for infrastructure. Use the terraform plan command to check the proposed changes match your prediction or not.

Dependency graphing: The tool supports a dependency graph. These graphs are built from Terraform configurations that can be further used to generate plans and more. These graphs involve only three types of nodes, Resource Node, Provider Configuration Node, and Resource Meta Node.

State management: State management in Terraform is essential as it helps map real world resources to your configuration. This feature also helps keep track of metadata. By default, the state is in a local file which is used to improve performance for large infrastructures.

Provision infrastructure in familiar languages: Terraform supports HashiCorp Configuration Language (HCL). This language makes it easier for people to read and write configurations in Terraform. The tool also allows operators to practice familiar programming languages like TypeScript, Python, Java, C#, and Go to define infrastructure code. Terraform configuration can select the programming language of their choice, 1000+ existing Terraform providers, and HCL Terraform modules.

Supports 1000+ providers: Discover Terraform providers and choose one for your cloud platforms and services. Add the Terraform providers to your configuration and use resources for provisioning or reprovisioning infrastructure.

Follow the next steps for steps how to install Terraform on Windows 10 and Windows Server 2019.

Install Scoop Installer

Scoop is an open source and command line package manager for Windows that allows you to install open source packages on Windows systems. It provides an easier way to install and use a wide variety of Windows software, as well as favourites from the Linux world.

To install Scoop, login as an Administrator user and launch PowerShell. Then, run the following command to install the Scoop installer:

				
					Set-ExecutionPolicy RemoteSigned -scope CurrentUser 
				
			

You will be asked to change the execution policy as shown below:

				
					Execution Policy Change
The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose
you to the security risks described in the about_Execution_Policies help topic at
https:/go.microsoft.com/fwlink/?LinkID=135170. Do you want to change the execution policy?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): A

				
			

Type A and press the Enter key to install Scoop. You will get the following output:

				
					iex (new-object net.webclient).downloadstring('https://get.scoop.sh')
Initializing...
Downloading scoop...
Extracting...
Creating shim...
Downloading main bucket...
Extracting...
Adding ~\scoop\shims to your path.
'lastupdate' has been set to '2022-01-05T14:33:07.5798460+00:00'
Scoop was installed successfully!
Type 'scoop help' for instructions.

				
			

After the installation, run the following command to list all options available with Scoop:

				
					scoop help
				
			

You should see all available options in the following screen:

Install Terraform on Windows 10 / Windows Server 2019

At this point, the Scoop installer has been installed. Now, open the PowerShell window and run the following command to install Terraform with other useful utilities like nano and which:

				
					scoop install terraform nano which
				
			

You should see the following screen:

After the successful installation, verify the Terraform version using the command given below:

				
					terraform.exe -v
				
			

You will get the following output:

				
					Terraform v1.1.2
on windows_amd64
				
			

You can also find the location of the Terraform binary using the following command:

				
					which terraform
				
			

You will get the following output:

				
					C:\Users\Administrator\scoop\shims\terraform.EXE
				
			

How to Use Terraform

In order to use Terraform, you will need to create a Terraform main configuration file with .tf extension. In this file, you can define the cloud provider that you want to configure. Terraform supports many cloud providers including, AWS, GCP, Azure and more. In this section, we will use AWS cloud providers.

First, create a directory for your project:

				
					mkdir terraform
				
			

Next, navigate to the project directory and create a Terraform main configuration file:

				
					cd terraform
nano main.tf
				
			

Add the following lines:

				
					# Provider
 provider "aws" {
   access_key = ""
   secret_key = ""
   region = "us-west-1"
 }

				
			

Save and close the file when you are done.

Note: You can provide your AWS access key and secret key inside the access_key and secret_key section.

Now, initialize the Terraform with the following command:

				
					terraform init
				
			

This will automatically download the provider to the .terraform directory:

You can list all created files and directories using the following command:

				
					ls
				
			

You will get the following output:

				
					Directory: C:\Users\Administrator\terraform


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----         1/5/2022   2:37 PM                .terraform
-a----         1/5/2022   2:37 PM           1077 .terraform.lock.hcl
-a----         1/5/2022   2:37 PM             95 main.tf

				
			

Uninstall Terraform

You can use the Scoop command to easily remove the Terraform from your system. First, list all installed packages using the following command:

				
					scoop list
				
			

You will get a list of all installed packages in the following output:

				
					Installed apps:

  7zip 21.07 [main]
  nano 5.9-10 [main]
  terraform 1.1.2 [main]
  which 2.20 [main]
				
			

Now, remove Terraform by running the following command:

				
					scoop uninstall terraform
				
			

You will get the following output:

				
					Uninstalling 'terraform' (1.1.2).
Removing shim 'terraform.exe'.
Removing shim 'terraform.shim'.
Unlinking ~\scoop\apps\terraform\current
'terraform' was uninstalled.
				
			

How to Install Terraform on Windows 10 / Windows Server 2019 Conclusion

In this post, we explained how to install Terraform on Windows server 2019 and Windows 10. I hope this will help you to install Terraform in your Windows system.

Terraform is easy to learn and can simplify complex manual tasks.

Avatar for Hitesh Jethva
Hitesh Jethva

I am a fan of open source technology and have more than 10 years of experience working with Linux and Open Source technologies. I am one of the Linux technical writers for Cloud Infrastructure Services.

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x