DEV Community

kycodee
kycodee

Posted on • Updated on

Terraform and Infrastructure

What is Terraform?

Terraform is an open-source infrastructure-as-code software. It was initially released in July of 2014 by HashiCorp. Infrastructure-as-code, or IaC, is the provisioning of infrastructure by using code instead of manual processes.
Over the past decade, Terraform has been one of the leading infrastructure-as-code softwares in the DevOps industry. It has become so popular since it is a declarative process, meaning a user can give instructions on what they wanted coded, without giving step-by-step instructions on how to code it. Two of the key features of Terraform are it's ability to change the infrastructure of a project and automate those changes. Both of these features will be discussed in detail as you read through this article.

Changing and Automating Infrastructure

As many of us already know, Terraform can used for creating an infrastructure, but it also can be used for managing an established one as well. For instance, if after creating an infrastructure and deploying it, you want to add more servers to your infrastructure in order to deploy more microservices. Terraform makes this easy by allowing you to go back into the code to update the environment exactly how you need it to be.
Many times you will need a separate infrastructure environment from development to production. Terraform also allows us to replicate an infrastructure without affecting the original one. After learning your way around Terraform, you can also automate this process of replicating the code.

Basic Commands

Now it's time to discuss some of the basic commands that are commonly used in Terraform. The first one we'll go over is Refresh. Refresh queries the infrastructure provider to get the up to date state. This means that the refresh command can be used to grab the current data of the infrastructure at the time of the command. Plan is another command commonly used in Terraform. It creates an execution plan and determines what actions are needed to achieve the desired state. This command means exactly what it is called, to plan and map things out without making any actual changes. The next command commonly used directly after the Plan command is one called Apply. Apply executes all of the changes that were made in the PLAN phase. The Destroy command is the last one of this whole cycle. Destroy destroys the whole set-up and removes the elements one-by-one in the right order. This means that destroy can easily destroy everything we've built up from the previous stages.

Terraform vs. Ansible

Terraform and Ansible are both infrastructure as a code tools. They are both used to automate, provision, configure, and manage infrastructure. Terraform is mainly an infra-provisioning tool, but also has the ability to deploy applications in other tools on that infrastructure. Ansible, on the other hand is mainly a configuration tool. It is mostly used after the infrastructure has already been created, Ansible is usually used to deploy apps or install and update software on that infra's setup. To wrap your head around the main difference between Terraform and Ansible, I would say that terraform is better for provisioning or creating infrastructure and Ansible is better for configuring or updating the already-made infrastructure.

Conclusion

To conclude things, I’d like to advise anyone looking into DevOps or just wanting to learn about infrastructure to look into Terraform since it is a leader in the industry.

Top comments (0)