DEV Community

Cover image for Get up and running with Terraform (IaC) Tool
Jordan Tingling
Jordan Tingling

Posted on

Get up and running with Terraform (IaC) Tool

What exactly is this amazing tool?

Infrastructure as code (IaC) tools allow you to manage infrastructure with configuration files rather than through a graphical user interface. IaC allows you to build, change, and manage your infrastructure in a safe, consistent, and repeatable way by defining resource configurations that you can version, reuse, and share.

Terraform is HashiCorp's infrastructure as code tool. It lets you define resources and infrastructure in human-readable, declarative configuration files, and manages your infrastructure's lifecycle. Using Terraform has several advantages over manually managing your infrastructure:

  • Terraform can manage infrastructure on multiple cloud platforms.

  • The human-readable configuration language helps you write infrastructure code quickly.

  • Terraform's state allows you to track resource changes throughout your deployments.

  • You can commit your configuration to version control to safely collaborate on infrastructure.

How exactly do I manage my Infrastructure?

Terraform plugins called providers let Terraform interact with cloud platforms and other services via their application programming interfaces (APIs). HashiCorp and the Terraform community have written over 1,000 providers to manage resources on Amazon Web Services (AWS), Azure, Google Cloud Platform (GCP), Kubernetes, Helm, GitHub, Splunk, and DataDog, just to name a few.

How do I deploy my Infrastructure?

Image description

Terraform's configuration language is declarative, meaning that it describes the desired end-state for your infrastructure, in contrast to procedural programming languages that require step-by-step instructions to perform tasks. Terraform providers automatically calculate dependencies between resources to create or destroy them in the correct order.

In order to deploy infrastructure with Terraform, you need to understand a few basic concepts:

  • Scope - Identify the infrastructure for your project.

  • Author - Write the configuration for your infrastructure.

  • Initialize - Install the plugins Terraform needs to manage the infrastructure.

  • Plan - Preview the changes Terraform needs to manage the infrastructure.

  • Apply - Make the planned changes.

Image description

Conclusion

Terraform also keeps track of your real infrastructure in a state file, which acts as a source of truth for your environment. Terraform uses the state file to determine the changes to make to your infrastructure so that it will match your configuration.

Terraform even has it's own cloud!

Terraform allows you to collaborate on your infrastructure with its remote state backends. When you use Terraform Cloud (free for up to five users), you can securely share your state with your teammates, provide a stable environment for Terraform to run in, and prevent race conditions when multiple people make configuration changes at once.

Keep learning Terraform and other Infrastructure as Code (IaC) tools!

To learn more about Infrastructure as Code, check out this blog post: What is Infrastructure as Code?

Additional Information:

Hashicorp Learn is a great place to learn Terraform for beginners - intermediate level. They also teach how to use Terraform with cloud providers (AWS / Azure / GCP) & tools like kubernetes, Docker, etc.

Hashicorp Learn

FreeCodeCamp also have a quick crash course on Terraform but more specifically, "Automate your AWS cloud infrastructure" using Terraform.

FreeCodeCamp - Terraform Course - Automate your AWS cloud infrastructure

Top comments (0)