How to Install Terraform on CentOS Stream 9 Server (Tutorial)

How to Install Terraform on CentOS Stream 9 Server. In this post we will introduce what Terraform is with the main terraform benefits and pros and next we will install Terraform on CentOS Stream 9 Server. Let’s start. 

What is Terraform

HashiCorp Terraform is an open source infrastructure as a code tool that enables you to define both clouds and on prem resources in independent configuration files. Such files can be versioned, reused and shared effortlessly.

It even allows you to utilize a continuous workflow to provision and manage all the infrastructure processes in its system. Therefore, with the help of Terraform, you can not only manage low level components like compute, storage and networking resources but also high level components such as DNS entries and SaaS features.

This is an infrastructure provisioning tool where you can store your cloud infrastructures setups in the form of codes. Its architecture is made up of two main components, namely Terraform Core and Providers.

Terraform core uses two significant inputs, such as Terraform Configuration that you can configure and state where all the updated data is kept. On the other hand, providers are cloud providers that offer you the potential to create infrastructure on different levels. Therefore, it is one of the most essential and useful tools one can use in their infrastructure.

Terraform Features

  • Immutable infrastructure.
  • Client only architecture. Terraform works on APIs and have a wide variety of options.
  • Consistent workflow.
  • Declarative, not procedural code.
  • A tool to manage virtual server life cycles (VMWare).
  • Tool that manages supporting services (DNS, Email).
  • Manages system services (MySQL, PostgreSQL).
  • VCS integration (Azure DevOps, Bitbucket, GitHub and GitLab).

Terraform Pros

Let’s learn even more of  Terraform benefits:

Enhance Deployment Of Multi Cloud Infrastructure

When Terraform is applied to multi channel infrastructure, similar infrastructure is also deployed on other cloud providers or local data centers. This way, developers can leverage the same tool and configuration files to manage the resources of different cloud providers simultaneously.

Minimizes Provision Time

Organizations that utilize the traditional click ops deployment method can face a lot of difficulties. Sharing files can take weeks or even months and is susceptible to errors. However, using Terraform, the deployment process is completed within minutes. It makes the deployment and migrations effortless and efficient.

Minimizes Cost Of Development

Terraform allows you to create on demand development and deployment environments that minimize the costs and even help in determining the environments before making any type of changes to the system.

Infrastructure As A Code

Terraform enables you to leverage code to manage and maintain the resources. With it, you can store the infrastructure status to trace the shifts in components of the system and even share these configurations with others.

Manages Automated Infrastructure

Terraform is capable of developing configuration file templates that define, provision, and configure ECS resources repeatedly and predictably. This way, the errors while deploying and managing from the intervention of humans significantly decrease. Moreover, it deploys the same template numerous times with the purpose of generating a similar development, test and production environment.

Prevents Configuration Drifts

Since Terraform is a provisioning software, it tends to make necessary changes in the infrastructure and then deploy new ones all over the server. This way, the server configuration process becomes independent, thereby providing similar examples across other infrastructures.

Doesn’t Require Any Separate Documentation

The code created for your infrastructure becomes the documentation. It is procedural natural and helps you to figure out the latest deployment and configuration.

Portability

With Terraform, you can utilize only one tool or language to describe the infrastructure for Google Cloud, AWS, Open Stack, and other clouds. It eliminates the problem of switching providers regularly.

Flexibility

Terraform is the best tool as it manages both IaaS and PaaS and helps you to store local variables, such as cloud tokens and passwords in encrypted form on the Terraform registry.

Next in this post, we will explain how to install Terraform on CentOS Stream 9 Server.

Install Terraform on CentOS Stream 9 Server

There are two methods you can install Terraform on CentOS Stream 9 Server.

  1. Install Terraform from the Terraform Repository.
  2. Install Terraform Manually.

Let’s explore each method to install Terraform.

Install Terraform from the Terraform Repository

By default, the Terraform package is not included in the CentOS 9 default repo. So you will need to add the Terraform official repo to your system.

You can add the Terraform repo using the following command:

				
					dnf install dnf-utils
yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
				
			

Once the Terraform repo is added, you can verify it using the following command:

				
					dnf repolist
				
			

You will get the following output:

				
					repo id repo name
appstream CentOS 9 - AppStream
baseos CentOS 9 - BaseOS
extras CentOS 9 - Extras
hashicorp Hashicorp Stable - x86_64

				
			

Next, install the Terraform package by running the following command:

				
					dnf install terraform -y
				
			

You can also list all available Terraform versions using the following command:

				
					dnf --showduplicate list terraform
				
			

You will get the following output:

				
					terraform.x86_64 1.0.8-1 hashicorp
terraform.x86_64 1.0.9-1 hashicorp
terraform.x86_64 1.0.10-1 hashicorp
terraform.x86_64 1.0.11-1 hashicorp
terraform.x86_64 1.1.0-1 hashicorp
terraform.x86_64 1.1.1-1 hashicorp
terraform.x86_64 1.1.2-1 hashicorp
terraform.x86_64 1.1.3-1 hashicorp
terraform.x86_64 1.1.4-1 hashicorp
terraform.x86_64 1.1.5-1 hashicorp
terraform.x86_64 1.1.6-1 hashicorp
terraform.x86_64 1.1.7-1 hashicorp

				
			

To check the Terraform version, run the following command:

				
					terraform version
				
			

You will get the Terraform version in the following output:

				
					Terraform v1.1.7
on linux_amd64
				
			

Install Terraform Manually

In this section of how to install Terraform on CentOS Stream 9 Server  is to install Terraform manually by downloading it from the source. This way you can download the specific or latest version of Terraform to your system. You will also get the flexibility to install more than one version of Terraform.

Firstly, is to go to the Terraform download page and choose the latest version of Terraform and run the following command to download it to your system:

				
					wget https://releases.hashicorp.com/terraform/1.1.7/terraform_1.1.7_linux_amd64.zip
				
			

Once the download is finished, unzip the downloaded file using the unzip command.

				
					unzip terraform_1.1.7_linux_amd64.zip
				
			

Next, copy the Terraform binary from the extracted file to the /usr/bin/ directory:

				
					cp terraform /usr/bin/
				
			

Then verify the Terraform version by running the following command:

				
					terraform -v
				
			

You will get the Terraform version in the following output:

				
					Terraform v1.1.7
on linux_amd64
				
			

How to Use Terraform

After installing Terraform, you will need to create a Terraform configuration file to connect any cloud providers. First, create a directory to store the Terraform configuration file:

				
					mkdir AWS
				
			

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

				
					cd AWS
nano config.tf
				
			

Add your AWS configuration in the following formates:

				
					provider "aws" {
region = "us-west-2"
access_key = "aws_access_key"
secret_key = "aws_secret_key"
}

resource "aws_instance" "example" {
ami = "ami-329455"
instance_type = "t2.micro"
}

				
			

Save and close the file when you are finished.

Next, initialize the Terraform to download AWS provider information to your system.

				
					terraform init
				
			

You will get the following output:

				
					Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.

				
			

Next, run the following command to test how Terraform works.

				
					terraform plan
				
			

Finally, run the following command to deploy the configuration on the AWS.

				
					terraform apply
				
			

Uninstall Terraform from CentOS 9

You can remove Terraform from your system easily by just running the following command:

				
					dnf remove terraform -y
				
			

You can also remove it manually by running the following command:

				
					rm -rf /usr/bin/terraform
				
			

How to Install Terraform on CentOS Stream 9 Server Conclusion

In this guide, you learned how to install Terraform using two methods on CentOS Stream 9 Server. You can now choose your preferred method to install Terraform on your server. 

 

Terraform has a simple syntax and can provision infrastructure across multiple cloud and on premises data centers. You also re provision infrastructure in case any configuration changes. Terraform is currently one of the most popular infrastructure automation tools available. If your organization considers deploying a hybrid cloud or multi cloud environment you are likely to consider Terraform.

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