Most cloud environments start the same way: someone clicks through a console to create a network, a database and a few servers. It works, until you need a second environment that matches the first, or need to know who changed a firewall rule last month, or need to rebuild after a mistake. Infrastructure as code (IaC) solves those problems by describing infrastructure in files that can be reviewed, versioned and applied repeatably.
This article explains the core ideas, compares three widely used tools, and offers a practical adoption checklist.
What infrastructure as code means
With IaC, you describe the resources you want, such as networks, compute, databases, queues and access rules, in configuration files. A tool reads those files, works out what needs to change in the real environment, and makes those changes.
The benefits come from treating infrastructure like application code:
- Repeatability. The same files create matching development, staging and production environments.
- Reviewability. Changes go through pull requests, so a second person sees a firewall change before it happens.
- History. Version control records what changed, when and by whom.
- Recovery. If an environment is damaged, you can recreate it from the files rather than from memory.
The core workflow: write, plan, apply
HashiCorp’s documentation describes Terraform’s workflow in three stages, and OpenTofu’s documentation describes the same three:
- Write. Define the resources you want in human-readable configuration files.
- Plan. The tool compares your configuration with the real infrastructure and produces an execution plan listing what it will create, update or destroy.
- Apply. After you approve the plan, the tool makes the changes in the correct dependency order.
The plan step is the safety net. Reviewing it before every apply is the single most important IaC habit, because it shows when a small edit would actually replace or delete a resource.
Three common tools
Terraform
Terraform, from HashiCorp, is an IaC tool for building, changing and versioning both cloud and on-premises resources. It works with platforms through providers, plugins that talk to each platform’s API, and HashiCorp notes that thousands of providers are published on the Terraform Registry. That makes Terraform a common choice when infrastructure spans more than one cloud or includes SaaS services.
OpenTofu
OpenTofu is an IaC tool that, by its own description, lets you define cloud and on-premises resources in human-readable configuration files, using the same write, plan and apply workflow and a state file as the source of truth. Its documentation is published by OpenTofu, a Series of LF Projects, LLC. If you are choosing between Terraform and OpenTofu, compare licensing, provider support and feature roadmaps against your own needs at the time you decide.
AWS CloudFormation
CloudFormation is AWS’s own service for modeling and provisioning AWS resources. You write a template describing the resources, and CloudFormation creates them together as a stack, which you can update or delete as a single unit. Two features are worth knowing early:
- Change sets let you preview how a proposed change will affect running resources, including whether critical resources would be deleted or replaced, before you execute it.
- Drift detection identifies stack resources whose configuration has been changed outside CloudFormation, so you can bring them back in line with the template.
How to choose
| Question | Leans toward |
|---|---|
| Are you AWS-only and want a native, managed service? | CloudFormation |
| Do you manage several clouds or SaaS platforms together? | Terraform or OpenTofu |
| Does your organization prefer a particular license or governance model? | Compare Terraform and OpenTofu directly |
| Do you already have a large codebase in one tool? | Usually stay with it |
Understanding state
Terraform and OpenTofu keep a state file that maps the resources in your configuration to the real objects in your environment. HashiCorp’s documentation makes several points that shape how teams should handle it:
- By default, state is stored locally in a file named
terraform.tfstate. - Local state makes collaboration hard, so HashiCorp recommends storing state in HCP Terraform or a remote backend.
- State can contain sensitive values, so storing it where access is not controlled risks exposing secrets.
- Storage that supports state locking prevents two people from applying conflicting changes at the same time.
CloudFormation works differently: you manage stacks through the AWS service rather than a state file you store yourself, and drift detection plays the role of checking that real resources still match the template.
An adoption checklist
- Start small. Codify one new environment or one well-understood component rather than everything at once.
- Use remote state with locking from the first day, with access restricted to the people and pipelines that need it.
- Keep secrets out of configuration files. Reference a secrets manager instead, and remember state may still hold sensitive values.
- Review every plan or change set in the pull request before it is applied.
- Apply through a pipeline, not from laptops, so every change is logged and repeatable.
- Split by lifecycle. Keep long-lived foundations, such as networks, separate from frequently changing application resources.
- Use modules or nested templates for patterns you repeat, such as a standard database or service.
- Detect drift. Run regular plans or drift detection to spot changes made outside the code.
- Import what already exists gradually, so console-built resources come under management without being recreated.
- Document conventions for naming, tagging and folder structure.
Common pitfalls
- Manual “quick fixes” in the console that the next apply silently reverts or that cause drift.
- One giant configuration where a small change requires planning the entire estate.
- State files in source control or on shared drives, exposing secrets and inviting conflicts.
- Skipping plan review because “it is only a tag change”, until it is not.
How Devacon can help
We design cloud environments on AWS, Azure and GCP and codify them with infrastructure as code, including remote state, pipelines that plan and apply changes, and drift checks. A typical engagement starts with one environment and a reusable module set, then extends to the rest of the estate. Learn more about our cloud and infrastructure services.
Sources
- HashiCorp Developer: What is Terraform?
- HashiCorp Developer: Terraform state
- OpenTofu documentation: What is OpenTofu?
- AWS CloudFormation User Guide: What is CloudFormation?
- AWS CloudFormation User Guide: Update CloudFormation stacks using change sets
- AWS CloudFormation User Guide: Detect unmanaged configuration changes with drift detection
Facts in this article were checked against the sources above on November 17, 2026. Standards and products change, so check the source before relying on a detail. Related service: Cloud & Infrastructure.