Some of Most Important Terraform Commands

Saurabh Dimri
3 min readNov 26, 2020

Terraform is an very powerful System tool developed by HashiCorp which is primarily used IaaC (Infrastructure as Code) or as an System Provisioning tool for managing Cloud platforms and its associated services. The services which terraform provides are easy to use and to create an Cloud based infrastructure on the go using basic commands and code. Since terraform is used mainly for cloud management here are 5 popular commands used for setting up and managing some services.

terraform init

It’s the first command you need to execute. This command performs several different initialization steps in order to prepare a working directory for use. This command is naturally very important as no commands pertaining to our cloud can be executed without initialization.

terraform init execution

terraform plan

It’s a command used prior to actually applying the configurations over the cloud. It’s an important feature of Terraform that allows a user to see which actions Terraform will perform prior to making any changes, increasing confidence that a change will have the desired effect once applied.

terraform plan executed

terraform apply

The bread and butter of terraform the actual command to execute the plan, setup your services and that’s it. By default, apply scans the current directory for the configuration and applies the changes appropriately. If no explicit plan file is given on the command line, terraform apply will create a new plan automatically and prompt for approval to apply it

terraform apply execution for the script

terraform destroy

Now we come to the antithesis of the apply command ; the terraform destroy. Our exit button, the shutdown button to applied plans. The terraform destroy command terminates resources defined in your Terraform configuration. This command is the reverse of terraform apply in that it terminates all the resources specified by the configuration. It does not destroy resources running elsewhere that are not described in the current configuration.

terraform destroy steps

terraform validate

Finally we come the terraform validate command. A very handy command for beginners it allows for syntax check of the Terraform files. A syntax check is done on all the Terraform files in the directory and will display an error if any of the files don’t validate. A thing to remember though the syntax check does not cover every syntax common issues.

terraform validate

As we can see all those terraform command require some scripts to work upon. Those scripts are precisely what known as terraform scripts or IaaC (Infrastructure as a Code)

For the sake of trying above commands here is a sample terraform script

terraform script example

This is all about how to begin using terraform for cloud infrastructure provisioning.

--

--

Saurabh Dimri

DevOps Enthusiast | Full Stack WebDeveloper | DevSecOps | Cloud Computing