Terraform and CI/CD explained: infrastructure as code and release pipelines
Terraform is a tool that describes cloud infrastructure, such as networks, servers and databases, in text files that are reviewed and versioned like application code. CI/CD is the pipeline that automatically tests every change and releases it to staging and production. Together they mean that both the application and the environment it runs on change only through reviewed pull requests, with a record of who changed what and a way to roll back.

Two tools for one problem
Most production incidents follow a change. Someone edited a firewall rule in the console, deployed from a laptop or ran a database script by hand. The change worked, or it did not, and afterward nobody could say exactly what was done.
Infrastructure as code and CI/CD attack that problem from two sides. Terraform puts the environment in version control. The pipeline puts the release process in version control. After both are in place, every change to production has an author, a reviewer, a test result and a way back.
They are separate tools and you can adopt either one first. Most teams should start with the pipeline, for reasons covered below.
Infrastructure as code with Terraform
How it works
You write files that declare what should exist: a network, a database with a given size, a storage bucket that is not public. Terraform compares that declaration with what exists in your cloud account and works out the difference.
Four terms cover most of it.
- Provider. A plugin that knows how to talk to one platform, such as AWS, Azure, Google Cloud or Cloudflare.
- State. Terraform’s record of the resources it manages and their current settings. It is how the tool knows what it created.
- Plan. A preview of what will be created, changed or destroyed if the code is applied. Nothing changes at this step.
- Apply. The step that makes the changes.
The plan is the important part. A reviewer reads “this will replace the production database” before it happens, not after.
What goes wrong without discipline
Terraform does not make infrastructure safe by itself. The common failures are organizational.
| Problem | What it looks like | Fix |
|---|---|---|
| State on a laptop | One engineer holds the only record of what is managed | A remote backend with locking and encryption |
| One state for everything | A staging change can touch production | State split by environment |
| Drift | Someone fixed an incident in the console, and the code no longer matches reality | A scheduled plan that reports differences |
| One root module | Every change plans the whole estate, slowly | Small modules, one root configuration per environment |
| Apply rights for everyone | Any laptop with credentials can change production | Apply only from the pipeline, after approval |
Importing what already exists
Most companies arrive with resources built by clicking. They do not need to be recreated. Terraform can import an existing resource into state, and the code is then written to match it. The check is a plan that shows no changes. That is the proof that the code describes what is really running.
Terraform, OpenTofu and the licence
HashiCorp announced on August 10, 2023 that future releases of its products would move from the Mozilla Public License 2.0 to the Business Source License 1.1, a source-available licence that restricts competing commercial offerings. In response, a community fork named OpenTofu was created. OpenTofu describes itself as a drop-in replacement for Terraform and is under the Linux Foundation’s stewardship.
For a company managing its own infrastructure, both work, and the configuration language is largely the same. The choice turns on your legal team’s reading of the licence, the registry and tooling you depend on, and which features each project has added since the fork. Pin the version either way.
CI/CD: the release pipeline
Continuous integration
CI runs on every pull request. Typical checks, ordered so the fastest failures come first:
- Formatting and linting
- Type checks
- Unit tests
- Build
- Integration tests
- Database migration validation
- Dependency and secret scanning
A failing check blocks the merge. That rule is the whole point. A pipeline people can bypass is a suggestion.
Continuous delivery
After a merge, the pipeline releases the change.
| Stage | Trigger | What happens |
|---|---|---|
| Deploy to staging | Merge to the main branch | The built artifact and any migrations run against the staging environment |
| Verification | Automatic | Smoke tests and health checks confirm the release works |
| Deploy to production | Manual approval or a tagged release | The same artifact that ran on staging is released |
| Rollback | A failed check or a human decision | The previous version is restored through a written, practiced step |
Two details matter. The artifact is built once and promoted, so production runs exactly what staging tested. And staging and production are separate, with their own databases, secrets and credentials, so a test cannot reach live data.
Database migrations and mobile releases
Two kinds of change escape pipelines most often.
Schema changes. A migration run by hand against production is the riskiest release a team makes. Migrations belong in version control, validated in CI and run on staging first. The practices behind this are covered on our database consulting page.
Mobile builds. Store builds made on one developer’s laptop depend on that laptop. Builds for iOS and Android should come from CI, with signing credentials in a secret store.
How the two fit together
Terraform runs inside the pipeline. A pull request that changes infrastructure code triggers a plan, and the plan is posted on the pull request for the reviewer. After approval and merge, the pipeline runs apply with short-lived credentials. No engineer needs standing rights to change production from a laptop.
The result is one workflow for both kinds of change:
- Open a pull request.
- Automated checks run. For infrastructure, the plan is shown.
- A person reviews and approves.
- The pipeline applies or deploys, staging first.
- The change is recorded in version control with its author and reviewer.
That record is also what an auditor samples when asking how changes to production are approved.
An example from our own practice
Shai Goldenberg, our CTO, builds and runs a two-sided marketplace platform in production. It has 10 CI workflows in GitHub Actions across web, mobile and database changes. CI runs on every pull request, and staging and production are separate environments. The platform has gone through about 440 database migrations.
That is evidence for the pipeline half of this post. For the Terraform half we have no record of past results to show, no HashiCorp certification and no partner status. We say so on the service page, and Terraform work is scoped per project.
Where to start: a checklist
- Every repository has checks that run on each pull request, and a red check blocks the merge.
- Staging and production are separate, with separate databases, secrets and credentials.
- Deploys to staging happen on merge, without a manual step.
- Production deploys need an approval and release the artifact that staging tested.
- A rollback procedure is written down and has been run at least once.
- Database migrations are in version control and run on staging first.
- Secrets are held in a secret store, not in the repository.
- Infrastructure is described in code, with remote state split by environment.
- Infrastructure plans appear on pull requests, and apply runs only from the pipeline.
- A scheduled job reports drift between code and reality.
The first seven items are pipeline work and usually come first, because they protect every release from the first day. The last three are infrastructure as code. If your team also uses AI coding agents, the pipeline is where their output gets checked. Guard rules at the agent level are described in Claude Code hooks.
What to do next
Tick the checklist above for your main product. If the gaps are in the first seven items, our CI/CD consulting service starts with a pipeline review and builds pull request checks, deploy automation, the migration flow and mobile release builds. If the pipeline is sound and the gaps are in the last three, Terraform consulting brings hand-built resources under code, sets up remote state and puts plan and apply in CI. Both start at $25,000 at a fixed price per phase after a free one-hour scoping call, and both end with a handover to your engineers.