Get Started-Install Terraform

We are going to work with the Terraform command-line tool in this post. 

The first step is installing the Terraform on your system (This system has no specific recommendation, if you can watch a video on your laptop, then you can install Terraform on it too.)

HashiCorp officially maintains and signs packages for the following Linux distributions:

  • Ubuntu/Debian
  • CentOS/RHEL
  • Fedora
  • Amazon Linux

We will work with Ubuntu in this document to ensure that your system is up to date, and you have the gnupg, software-properties-common, and curl packages installed. You will use these packages to verify HashiCorp’s GPG signature and install HashiCorp’s Debian package repository.

sudo apt-get update && sudo apt-get install -y gnupg software-properties-common curl

Now add the HashiCorp GPG Key.

curl -fsSL | sudo apt-key add -

Add the official HashiCorp Linux repository.

sudo apt-add-repository "deb [arch=amd64] $(lsb_release -cs) main"

Update to add the repository, and install the Terraform CLI.

sudo apt-get update && sudo apt-get install terraform

If you want to be sure that terraform has been installed correctly or not type the terraform -help command in the CLI you should see as below:

Actually, you can add any subcommand after this command to get more information about the specific common. For example, this command shows more info about terraform plan command :

terraform -help plan

Now you are able to work with Terraform. But At first, it is important to know what is the flow of Terraform and you should be familiar with basic commands.

As we say in the previous post there are 5 main steps in Terraform workflow:

  • ScopeAuthorInitializePlanApply 

Scop and Author are some concepts for planning the job. After writing a terraform file (  we need to work on three main commands in order as below:

terraform init 

This command is used to initialize a working directory containing Terraform configuration files. This is the first command that should be run after writing a new Terraform configuration or cloning an existing one from version control. It is safe to run this command multiple times.

terraform plan

This command creates an execution plan, which lets you preview the changes that Terraform plans to make to your infrastructure.

terraform apply

This command executes the actions proposed in a Terraform plan.

After creating an infrastructure maybe you want to destroy all the configuration that is set on the infrastructure. Therefore, you can use destroy command as below: 

terraform destroy

This command is a convenient way to destroy all remote objects managed by a particular Terraform configuration.

Now you are familiar with the main command of Terraform, it is time to run the first project with Terraform. Follow the next post to run the first Terraform project. 

Leave a Reply

Your email address will not be published.