What Is Terraform
Picking up from Automation: what Terraform is, how it works with providers and state, its core benefits for DBAs, and what DBAs manage with it.
Picking up from Automation
In the Automation module, you saw that infrastructure as code (IaC) builds the infrastructure, and configuration management sets up what runs on it. Terraform is the most widely used IaC tool: you describe the databases, servers, and networks you want in text files, and Terraform creates them, changes them, and keeps them matching your description.
A quick recap from IaC and Configuration Management:
- Terraform provisions: networks, virtual machines, disks, and managed cloud databases, such as an Autonomous Database or an Amazon RDS instance.
- Ansible configures: what runs inside a server, such as installing Oracle and setting parameters.
- Terraform is declarative: you describe the end state, and it works out the steps.
This module goes deep on Terraform: what it is, its language, its core workflow, how it tracks what it has built, and how DBAs use it safely.
What Terraform is
Terraform was created by HashiCorp in 2014. You write configuration files, ending in .tf, in a simple language called HCL (HashiCorp Configuration Language). Terraform reads them, compares them with what already exists, and calls each platform's API to make reality match.
- Terraform core
- The
terraformprogram itself: reads your files, works out what needs to change, and runs the changes in the right order. - Providers
- Plugins that teach Terraform how to talk to a platform's API. There are providers for every major cloud, plus VMware, Kubernetes, GitHub, monitoring tools, and thousands more, published in the Terraform Registry.
- State
- A file in which Terraform records what it has built, so it knows next time what already exists. It's covered in State and Drift Detection.
Core benefits for DBAs
- Repeatability and version control
- Database infrastructure lives in Git, as code. Every change is proposed in a pull request, reviewed, and recorded. If a change causes trouble, you revert the commit and apply again. Building the same database twice gives the same result both times.
- Drift detection
- Running
terraform plancompares the code with what really exists, and shows any unauthorized or forgotten manual change made directly in production or in a cloud console, such as a resized database or a disabled backup. - Multi-environment parity
- Development, test, and production are built from the same code, with only the differences you choose, such as size, so they don't slowly drift apart. Problems found in test are far more likely to be the problems you'd find in production.
- Self-documenting infrastructure
- The code is the documentation of how each database is set up, and it's always current, unlike a diagram on a wiki.
- Speed and self-service
- A new environment takes minutes. Wrapped in a pipeline, it can be requested by application teams, within the standards DBAs build into the code.
- Safer changes
- Every change is previewed before it's made, so surprises, such as a change that would replace a database, are caught in review rather than in production.
What DBAs manage with Terraform
| Platform | Examples |
|---|---|
| OCI | Autonomous Databases, Base Database DB systems, Exadata VM clusters, backups, Data Guard associations, VCNs |
| AWS | RDS instances, Aurora clusters, parameter and option groups, subnet groups, security groups |
| Azure | Azure SQL servers and databases, PostgreSQL and MySQL Flexible Servers, private endpoints |
| On-premises and VMs | Virtual machines and disks on VMware or cloud compute, ready for Ansible to install the database |
| Around the database | Monitoring alarms, encryption keys, secrets, DNS names, and access policies |
Terraform is not the right tool for what's inside the database, such as tables, data, and most users. Schema changes belong to migration tools such as Liquibase, as covered in the Database CI/CD module.
Key takeaways
- Terraform is the most widely used IaC tool: you describe infrastructure in HCL files, and it makes reality match.
- Terraform core plans the changes, providers call each platform's API, and the state file records what was built.
- For DBAs, its core benefits are repeatability and version control, drift detection, and multi-environment parity.
- DBAs use it for managed cloud databases, database servers, and everything around them; schema changes belong to migration tools.
- OpenTofu is an open source fork with the same language and commands.