Contents

Terraform Introduction

What is Terraform

Website Visitors:

Terraform is an open source tool used to manage cloud infrastructure resources. It allows you to create, change, and destroy resources on cloud infrastructure like AWS, GCP, Azure, and DigitalOcean. It is often used by developers who need to work on multiple projects simultaneously. Read more about the basics, along with examples of real-world applications.

Terraform Introduction

Terraform is an open-source infrastructure as code (IaC) software tool created by HashiCorp. It allows users to define and provision data center infrastructure using a declarative configuration language. With Terraform, you can describe the desired state of your infrastructure in code, specifying the resources and their configurations.

Terraform then takes these descriptions and translates them into API calls to various infrastructure providers, such as Amazon Web Services (AWS), Microsoft Azure, Google Cloud Platform (GCP), and many others. This enables users to manage and provision infrastructure across different cloud providers and on-premises environments in a consistent and automated manner.

Let’s get started

Basic terraform workflow is shown below.

write
init
plan
apply
tfstate
destroy

Let’s decode what this means.

  • Initially you will write  a script to create changes to your infrastructure. This could be creating a VPC or subnet etc…

  • Next, you have to initialize your code using init command. This is where terraform looks at your code and downloads the required files. For example, if you are deploying AWS infrastructure, terraform will download required AWS files.

  • In the next step, you need to run the plan command. This will create a plan of the changes that will be implemented from your terraform script. Running plan command will not deploy the infrastructure. It will only list what changes will be made when you run the terraform script. You can save the plan result to a file if needed. This is like running -whatif parameter in PowerShell language.

  • Next in the list is apply. After you verify the plan output and you’re ready to apply the changes to your infrastructure, you have to run apply command so that the changes you have in terraform script are implemented.

  • After apply command is executed, terraform will create a terraform.tfstate (aka state) file with the actual names of the infrastructure components deployed. For example, name of the VPC, subnet id, instance details etc… If you deploy infrastructure again, terraform will create backup of existing tfstate as terraform.tfstate.backup and create new terraform.tfstate file.

  • Optionally, you can destroy all the changes that you made earlier using the destroy command.

Suggested Article

Now that you know what is Terraform, continue reading Terraform Definitions here. All other DevOps categories are listed here: DevOps Tools. Have a look at the posts as per your topic of interest.

Conclusion

In this tutorial, we’ve explained what is Terraform and its basic usage. We’ve also demonstrated examples for all the topics that are discussed. We hope you have learned something new in this article.

Please feel free to share your thoughts about this article in the comments section below.

Your inbox needs more DevOps articles.

Subscribe to get our latest content by email.