Learn the basics of using Terraform for cloud-agnostic infrastructure provisioning.
Terraform is an open-source Infrastructure as Code (IaC) tool created by HashiCorp. It allows users to define and provision infrastructure using a high-level, declarative configuration language known as HashiCorp Configuration Language (HCL), or optionally JSON. One of Terraform's key strengths is that it is 'cloud-agnostic'. It uses 'providers' to interact with the APIs of various cloud platforms (like AWS, Azure, GCP), SaaS providers, and other services. This means you can use the same workflow to manage infrastructure across multiple clouds. The core Terraform workflow consists of three stages: 'Write', 'Plan', and 'Apply'. In the 'Write' stage, you define your infrastructure in `.tf` configuration files. For example, you might define a virtual network and a virtual machine. In the 'Plan' stage, you run the `terraform plan` command. Terraform creates an execution plan, which shows you exactly what it will do to reach your desired state—what resources will be created, updated, or destroyed. This is a crucial safety step that lets you review changes before they are made. In the 'Apply' stage, you run the `terraform apply` command. Terraform executes the plan, making the necessary API calls to the cloud provider to create and configure the resources. Terraform also creates a 'state file', which maps the resources in your configuration to the real-world resources, allowing it to manage their lifecycle.