Terraform is a free open-source tool that is an Infrastructure as a code (IaC) software. It allows us to automate and manage infrastructure and services running on that infrastructure. It uses declarative language which is used to declare what we want to achieve. It is one of the best tools out there for Infrastructure provisioning.
In the scenario where one has to create infrastructures, and later on make some changes or delete some infrastructure, terraform is the tool you require. It makes all these processes pretty easy because of the reusable code of Terraform and tfstate file.
A tfstate file is created when we run terraform plan command. This file is basically stating the state or status of the resource at that exact time. It lets you track the changes from creating to destroying. So that when we plan next time, it will read the state file and know what is the state in the real world and try to match with that.
Destroy (terraform destroy): Destroy means delete the resources.
Setup terraform on ubuntu
Step1. Add Terraform key.
$ curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add –
Step2. Add repository
$ sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
Step3. Install Terraform
$ sudo apt-get update && sudo apt-get install terraform
Step3. Verify the installation by running the command:
$ terraform -help