What Is Terraform?
Terraform is an open source infrastructure as code tool. HashiCarp has developed it.
Terraform is used by almost all experts/engineers to create any cloud infrastructure. Terraform is go to tool for all the Cloud Engineers.
Below are the key benefits of terraform
- We can codify our application infrastructure
- An infrastructure that can be easily reproduced using terraform.
- We can version control infrastructure, it can be kept securely and safely.
Why Terraform is so Popular?
Currently terraform is go to tool for any infrastructure provisioning tasks.
Below are the main reasons
- Free to use.
- Terraform is declarative language.
- Learning curve is very short.
- Once you learn terraform, it is easy to provision infrastructure in other cloud providers with minimal effort.
- Syntax is same for other providers.
- We can create Immutable infrastructure.
- Once you don’t need infrastructure, we can destroy infrastructure. Which will save the cost for IT resources.
- Terraform is master and agent less compared to other tools. Which saves costs.
How to install Terraform on laptop?
In order to install terraform please download appropriate package for your system as zip.
Steps to install on Mac/Linux
- Unzip terraform
- In order to move the terraform binary use command “mv terraform /usr/local/bin/”
- In order to verify installation, run command “terraform -help”
Steps to install on Windows
- Run terraform.exe to install terraform.
- Go to Control Panel -> System -> System settings -> Environment Variables.
- Scroll down in system variables until you find PATH.
- Click edit and change accordingly.
- BE SURE to include a semicolon at the end of the previous as that is the delimiter, i.e. c:\path;c:\terraform
- Launch a new console for the settings to take effect.
- In order to verify installation, run command “terraform -help”
What are all the basic commands of Terraform?
Below are main commands used in terraform
- terraform init
- This is the first command we run in terraform.
- Command is used to initialise directory containing Terraform configuration files.
- Command will automatically find, download, and install the necessary provider plugins mentioned in the configurations.
- terraform fmt
- Command is used to rewrite Terraform configuration files to a canonical format and style.
- It does linting
- It makes code more readable format
- terraform plan
- Command creates an execution plan.
- Checks the current status with the existing backend / local state file.
- Indicates any differences between the current infrastructure and the current code.
- This is just a dry run, it doesn’t actually create any resources.
- terraform apply
- This command actually creates all the resources referenced in the Terraform configuration files.
- Depending on the number of resources, it will take time to create those resources.
- terraform destroy
- Command is a convenient way to destroy all resources managed by the Terraform configuration.
- This process is irreversible. Once the command is run, Terraform starts to destroy all resources.
Reference urls of Terraform
https://www.terraform.io/intro/index.html
https://learn.hashicorp.com/terraform?utm_source=terraform_io