Terraform is one of the most widely used applications to use the Infrastructure as Code. It is available for almost all the cloud service providers out there & also can be used for in-house solutions.

Terraform can be used to create a single instance or a complete data center. Not only instances, but we can also perform networking, DNS, or firewall management using the terraform scripts.  In this tutorial, we will discuss some of the important Terraform commands that we should know. 

Note:- If you need to learn about how to install Terraform, read the article HERE.

Recommended Read:  How to install Google Cloud SDK in Linux

Also Read: Reference guide for Docker Commands – NEW v/s OLD

Now let’s start with the cheatsheet for important Terraform Commands.


Terraform Command Cheatsheet

 

1- Terraform Init

Like in git, this is the first command that we will run when using terraform. This command will initialize the current working directory that holds the terraform configuration files.

$ terraform init


2- Terraform Validate

This command will check all the configuration files in the current directory for errors & will let us know of any errors in the file.

$ terraform validate

We can actually skip this command & it is not a mandatory step for creating resources using the terraform script.


3- Terraform plan

So this is the 2nd command that we need to run when provisioning resources using terraform. This command will create an action plan for the resources that are to be created using the terraform script. 

$ terraform plan

This is actually a kind of dry run, review screen, where you can check what changes will take place once we apply the scripts.


4- Terraform Apply

This is 3rd step & final step to apply the changes. provision the resources that we have mentioned in the terraform script.

$ terraform apply


5- Terraform Output

This command is used to extract the values for a variable from the configuration file, state file or from a terraform module. So from example, we provision a PUBLIC IP for our resource & we would need that provisioned IP as output, we can use this to fetch that information.


6 - Terraform Destroy

Now this command as the name suggests will destroy all the resources that we have provisioned using the terraform script.

$ terraform destroy

This command will scan the current directory for the configuration file & will then destroy/delete/terminate the resources provisioned using the file. So please use this with caution.

Now there are a number of options that we can use with Terraform command, we hardly use all of them. We can get the complete list of options that we can use by running the following command,

$ terraform

This completes our tutorial on important Terraform commands that you should, consider this post as a sort of Terraform commands cheatsheet. For any queries, feel free to connect to us using the comment box below.

We are giving you exclusive deals to try Linux Servers for free with 100$ credit, check these links to claim your 100$,

DigitalOcean - 100$ free credit & Linode - 100$ free credit

Check some Exclusive Deals, HERE.

Also, check out DevOps Book You should read section.