IaC and Configuration Management
Infrastructure as code versus configuration management, Terraform versus Ansible, and how they're used together.
Two different jobs
Infrastructure as code (IaC) tools, such as Terraform, create the infrastructure: networks, servers, disks, and cloud databases. Configuration management tools, such as Ansible, set up what runs on it: operating system settings, database software, parameters, and users. Most automation uses both, one after the other.
Teams often talk about day 0 (design), day 1 (build and deploy), and day 2 (operate: patch, change, scale). Terraform's work is mostly day 1; Ansible and CI/CD carry on through day 2, for as long as the database runs.
Terraform and Ansible compared
| Terraform (infrastructure as code) | Ansible (configuration management) | |
|---|---|---|
| Main job | Create, change, and destroy infrastructure | Configure servers and software, and run operational tasks |
| Style | Declarative: describe what should exist | Task-based playbooks, mostly with declarative, idempotent modules |
| How it knows what exists | A state file records everything it manages | Checks each server live, every time it runs |
| Talks to | Cloud and platform APIs: OCI, AWS, Azure, VMware | Servers over SSH (or WinRM for Windows), plus some APIs |
| Preview | terraform plan | ansible-playbook --check --diff |
| Language | HCL (HashiCorp Configuration Language) | YAML |
| DBA examples | A DB server and its disks, an Autonomous Database, an RDS instance | Installing Oracle, patching, setting parameters, creating users, refreshes |
Here's the same database server seen through each tool. Terraform describes the server that should exist:
# Terraform (HCL): a database server should exist, with this shape
resource "oci_core_instance" "db01" {
display_name = "kofi-db01"
shape = "VM.Standard.E5.Flex"
shape_config {
ocpus = 2
memory_in_gbs = 32
}
# ...compartment, subnet, and image...
}
Ansible then describes how that server should be set up:
# Ansible (YAML): what should be true on the server
- hosts: db_servers
become: true
roles:
- os_baseline # kernel settings, packages, the oracle user
- oracle_install # Oracle software in /u01
- oracle_db # the database, parameters, users, backups
Where they overlap
The line isn't perfectly sharp. Ansible can create cloud resources, and Terraform can run simple setup scripts when a server starts. But each tool is strongest at its own job, and using the wrong one causes pain: Ansible doesn't track infrastructure the way Terraform's state does, and Terraform isn't built for ongoing changes inside a server. The common pattern is Terraform to build, Ansible to configure, run in sequence by a pipeline, as in Git in Practice.
For managed cloud databases, such as Autonomous Database or Amazon RDS, there's no server to configure, so Terraform often does most of the work, with SQL migrations through CI/CD for the schema.
Other tools you'll meet
| Infrastructure as code | Configuration management |
|---|---|
| OpenTofu, the open source fork of Terraform | Puppet |
| AWS CloudFormation, Azure Bicep, OCI Resource Manager | Chef |
| Pulumi, which uses programming languages such as Python | Salt |
The next two modules in this path cover Terraform and Ansible in depth.
Key takeaways
- Infrastructure as code builds the infrastructure; configuration management sets up what runs on it.
- Terraform is declarative, tracks what it manages in a state file, and previews changes with
terraform plan. - Ansible runs YAML playbooks over SSH, with idempotent modules, and previews with
--check. - Terraform is mostly day 1; Ansible and CI/CD carry on through day 2.
- The usual pattern: Terraform builds, Ansible configures, and CI/CD applies schema changes, all from one pipeline.