Skip to main content

Terraform


HashiCorp Terraform is an infrastructure as code tool that lets you define both cloud and on-prem resources in human-readable configuration files that you can version, reuse, and share. You can then use a consistent workflow to provision and manage all of your infrastructure throughout its lifecycle.

The core Terraform workflow consists of three stages:

Write: You define resources, which may be across multiple cloud providers and services. For example, you might create a configuration to deploy an application on virtual machines in a Virtual Private Cloud (VPC) network with security groups and a load balancer.

Plan: Terraform creates an execution plan describing the infrastructure it will create, update, or destroy based on the existing infrastructure and your configuration.

Apply: On approval, Terraform performs the proposed operations in the correct order, respecting any resource dependencies. For example, if you update the properties of a VPC and change the number of virtual machines in that VPC, Terraform will recreate the VPC before scaling the virtual machines.

Why Terraform?


  • Infrastructure as a code
  • Multi cloud deployment
  • Automation of your Infrastructure
  • Manage Virtual machine images
  • Integrate with existing workflows
  • Maintain your Infrastructure in certain state (complaint)
  • Easy to Audit Infrastructure
  • Version control the Infrastructure change history

In short, Uses Infrastructure as a code to provision and manage any cloud, infrastructure, or service.

Terraform Basics

Terraform Project Structure

tip
  • The main.tf file contains the Terraform configuration of the resources to be provisioned.
  • The variables.tf file contains the declaration of the variables.
  • The terraform.tfvars file contains the values of the variables.