What Is Terraform?
Terraform Basics: Configuration and Providers
What is Terraform? It is an infrastructure as code tool, created by HashiCorp, that describes cloud resources in configuration files and then creates or changes them to match. Its files are written in HashiCorp Configuration Language (HCL), a readable syntax designed for describing infrastructure.
A Terraform configuration declares resources such as virtual machines, networks, DNS records and databases. To manage them, Terraform uses providers, which are plugins that translate those declarations into calls to a specific platform's API. Providers exist for the major cloud platforms and for many other services, so one tool can work across more than one environment.
Terraform is one tool within the wider practice of infrastructure as code. Its license changed in 2023, and community forks such as OpenTofu have since appeared. The concepts described here apply to Terraform and its forks alike.
The Plan and Apply Cycle and State
Terraform works in two main steps. First it produces a plan, which compares the configuration with what Terraform already knows and shows which resources will be created, changed or destroyed. Then it applies the plan, carrying out the changes once someone has reviewed them.
To make that comparison, Terraform relies on a state file. The state maps each resource in the configuration to the real object in the cloud account. Without it, Terraform has no reliable record of what it created. State can also contain sensitive values, so it should be stored securely and access should be limited.
The plan step is the key safety feature. Reviewing a plan before applying it shows the impact of a change before any live resource is touched, which matters most in shared environments.
Where Terraform Fits in Multi-Cloud Setups
Because providers are plugins, one Terraform workflow can manage resources in several clouds. This is one reason it appears in multi-cloud strategies, where a company uses more than one public cloud provider. See what a multi-cloud strategy involves.
The reach is not complete, however. Each provider exposes its own resource types, names and features, so the configuration for a load balancer on one platform is not the same as on another. Teams also build modules, which are shared code packages, and habits around one tool. These can make moving away from Terraform, or from one provider, slower than it first appears. For more on this, read how vendor lock-in happens.
Frequently asked questions
Is Terraform the same as Ansible?
No. Terraform focuses on provisioning infrastructure, meaning creating the servers, networks and databases themselves. Configuration management tools such as Ansible focus more on what is installed and set up inside a machine once it exists. Teams often use both, with Terraform building the environment and another tool configuring it.
What is a Terraform state file?
The state file is Terraform's record of which real resources belong to a configuration and what their current attributes are. Terraform reads it during planning to decide what must change. Because it can contain sensitive values such as generated secrets, it should be protected and never shared in public places.