Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
August 17, 2022 12:51 pm GMT

Let's start Terraform !

The article discusses the purpose, usage, and basics of Terraform. We will be walking through the concept of Infrastructure as Code, and mainly learn to get started with Terraform.

Introduction

This is the definition of Terraform as per their website:

"It is an infrastructure as code tool that lets you define both cloud and on-prem resources in human-readable configuration files that you can version, reuse, and share. You can then use a consistent workflow to provision and manage all of your infrastructure throughout its life cycle."

Terraform is a tool that is used in many forms in the industry. Most of them use it to develop their Infrastructure as Code, while its uses don't only limit to this!

Infrastructure as Code (IaC)

It is the managing and provisioning of infrastructure through code instead of all the hectic manual processes. In any company, or even personal project hosting your product/project on the internet is necessary. Cloud providers in today's world give easy access to deploy your code on the internet and make your work available to the public. But:

  • What if your VM's instance fails, or the Database is deleted?
  • What if you want to migrate to another cloud provider?

For any failure or migration, you will have to recreate the resource manually each time. IaC is a real-life saver in such scenarios. One file that helps you recreate all of your Infrastructure anytime.

Why Terraform?

Terraform not only saves the Infrastructure as code. The tool saves the infrastructure and manages the resources as declared. It orchestrates the changes and detects any drift in configuration. Also ensures the resources with the required specifications are not only up but also connected as declared.
Steps it follows in the process:

Write:

Mention the configuration of your architecture in .tf files

Plan:

It will create a plan to create the changes you have mentioned. You can make changes in the plan and apply as wanted.

Apply :

It applies the changes you asked for and moving forward from this point maintains this state perpetually until advised else wise.

Official Video on Why Terraform: Here

Image description

Terraform's History

As per Mitchell Hashimoto, the co-creator of HashiCorp Terraform. Terraform was built once AWS came up with the Cloudformation.
He saw a need of an open source, cloud-agnostic solution; a tool that could provide the same workflows, no matter what cloud you were using. Here

Using Terraform

Before I start with the basics, it's my responsibility as a developer to inform you about better sources. Hashicorp maintains amazing resources and tutorials to get anyone started: Here

Now, I see there are three most basic things to learn about Terraform:

  • Terraform CommandsYou can see all the Terraform CLI commands over HereWe will discuss the basic commands:

terraform init : It is used to initialize a working directory containing Terraform configuration files. Not exactly but it's like git init command (just a metaphor)

terraform plan: This step will actually create a plan to orchestrate and spin up resources as described in the scripts

terraform apply: It is used to apply the changes. It will continue to keep the system in the same state until said to do so.

  • Terraform Scripts
    Yes, these are not very different from scripts in any other language. Like Python or any other programming language, we import packages called as Terraform Providers. These scripts use HCL(Hashicorp Configuration Language) Language. We can have variables and modules that are begin imported from other
    files as well.

  • Terraform Providers
    These are like npm or python libraries that are saved on Terraform Registry, there are several providers available as per the requirements. Some are Official while others are community-built. It basically handles all the parameters passed to it in the terraform scripts. It will build the plan to apply the requested changes.

This is a basic overview of Terraform:

Terraform Working

The Terraform Provider has further four most basic functions of Create, Read, Update and Delete Resources. We will probably talk more about Terraform providers and my failed attempt at it in another article.

Conclusion:

Terraform is one of the tools in the DevOps domain.
Is it the best tool or the only tool one needs to learn?
Absolutely not!
As Developers, it's our work to learn and utilise several tools, but it's also our responsibility to not evangelise a technology as magic.

Terraform is a very good alternative when a smaller company wants to have a setup to automatically manage resources on the cloud. Since this is an automated way, even bigger company can have their smaller products and projects based on Terraform.
There is always an argument on Terraform being used for critical systems. According to me, it is always better to have custom in-house projects on a large scale.

Thanks for reading my article :)

P.S.: All these great images are built using DALL-E


Original Link: https://dev.to/kitarp29/lets-start-terraform--10h3

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To