XenonStack

DevOps

XenonStack Blog What Is Infrastructure as Code? Tools and Practices

and | Published | Updated

What Is Infrastructure as Code? Tools and Practices
22:16

Key takeaway

  • Infrastructure as code defines servers, networks and access in version-controlled files. Compare tools, trade-offs, governance and an adoption path.

Infrastructure as code (IaC) means describing servers, networks, storage, identities and access rules in text files that are version controlled, reviewed and applied by a tool, instead of being set up by hand in a console. The same files can build the same environment again, and every change leaves a record in Git. For a CTO or platform lead, the value is repeatable environments, reviewable change and an audit trail. Our overview of IaC in DevOps covers the delivery side in more depth.

This is the tool-neutral guide. It explains how IaC works, how the main tools differ and how to adopt it safely. When you are ready to go deep on one cloud, use our detailed guides on infrastructure as code on AWS with CloudFormation and CDK and infrastructure as code on Google Cloud after Deployment Manager. For Azure, see our guide to Azure Resource Manager.

What is infrastructure as code and what does it cover?

IaC describes the infrastructure an application runs on: virtual machines, storage, software stacks, network configuration, security settings, user accounts and access limits. Tools read the description, compare it with what exists and make the difference. Good IaC has these characteristics:

  • Consistent syntax, so configurations look alike across teams.
  • Version control, so changes are tracked, reviewed and can be rolled back.
  • Idempotence, so running the same code many times gives the same result. Ansible and Bicep both document this behaviour.
  • Integration with CI/CD pipelines, policy checks and cloud APIs.

Our infrastructure as code tools guide compares individual products in more detail.

How does infrastructure as code work?

The common workflow has the same shape in most tools. Terraform documents it as write, plan and apply, and CloudFormation change sets and Azure Bicep what-if previews follow the same idea.

  1. Write the desired state in declarative files, for example HCL, YAML, JSON or Bicep.
  2. Store the files in version control and review changes through pull requests.
  3. Plan or preview the change. The tool compares the files with the real environment and lists what it will create, update or delete.
  4. Test and check in a pipeline: syntax, unit or integration tests and policy checks. Our guide to CI/CD explains the pipeline side.
  5. Apply the approved plan in dependency order.
  6. Detect drift when the live environment no longer matches the code, then correct it through code.

What has changed in infrastructure as code recently?

Several changes affect which tool a new programme should start with. Check each current status before you commit.

ChangeWhat it means for your choiceCurrent status and source
Terraform licence changeLicence terms are now part of tool selection.HashiCorp announced on 10 August 2023 that it was moving future releases from MPL 2.0 to the Business Source License v1.1 (HashiCorp announcement).
OpenTofuAn open fork of Terraform is an alternative where licence terms matter.The OpenTofu project describes itself as a Terraform fork hosted under the Linux Foundation (OpenTofu FAQ).
Google Cloud Deployment ManagerTeams on Google Cloud need a migration plan.Google's Infrastructure Manager runs Terraform configurations as a managed service (Google Cloud documentation). Our GCP guide sets out the Deployment Manager retirement dates it takes from Google's deprecation page.
AWS OpsWorksChef and Puppet managed through OpsWorks need a new home.Our AWS guide reports OpsWorks Stacks, OpsWorks for Chef Automate and OpsWorks for Puppet Enterprise as end of life.
Azure BicepA concise language over ARM templates for Azure-only estates.Microsoft describes Bicep as a transparent abstraction over ARM JSON templates, with a what-if preview and no state file to manage (Microsoft Learn).

Declarative or imperative: which approach fits?

A declarative approach states the end result and lets the tool work out the steps. An imperative approach lists the steps. Most modern IaC tools are declarative, and Terraform, CloudFormation and Bicep all describe the desired end state.

ApproachWhen it fitsWatch for
DeclarativeRepeatable environments at scale, where reviewers want to read the intended end state.Needs people who understand the tool's model, including dependencies and state.
Imperative (scripts)Teams moving existing scripts into version control, or tasks where order matters.Scripts grow harder to maintain as the estate grows, and re-runs can have side effects unless written carefully.

Mutable or immutable infrastructure?

Mutable infrastructure is changed in place after it is built. Immutable infrastructure is never edited: a change means building a replacement and retiring the old one. Immutable patterns reduce configuration drift, because nothing is patched by hand, but they need good image pipelines and automated rollout. Mutable patterns suit small, stable estates where replacement is costly, but they need drift detection and strict change control.

Which IaC tool fits which job?

Tools fall into two groups. Provisioning tools create the infrastructure itself. Configuration management tools install and manage software on it. Many teams use one of each.

Two-column diagram mapping jobs (multi-cloud provisioning, AWS, Azure, server configuration) to tools (Terraform or OpenTofu, CloudFormation and CDK, Bicep, Ansible).
ToolRoleWhen it fitsCurrent status
TerraformProvisioning, declarative, multi-cloud through providersOne workflow across several clouds and on-premises resources.Source available under the Business Source License since August 2023.
OpenTofuProvisioning, Terraform forkTerraform-style workflow where an open governance model matters.Hosted under the Linux Foundation.
AWS CloudFormation and CDKProvisioning on AWSAWS-only estates that want native stack management and rollback. CDK adds general-purpose languages. See our AWS guide.Active. OpsWorks has reached end of life.
Azure Bicep and ARM templatesProvisioning on AzureAzure-only estates. See our Azure guide.Bicep is free and open source and supported by Microsoft.
Google Cloud Infrastructure ManagerManaged Terraform on Google CloudTeams leaving Deployment Manager. See our GCP guide.Active, runs Terraform configurations.
AnsibleConfiguration management and automationConfiguring servers and applications over SSH without installing an agent.Documented as agentless, with YAML playbooks and idempotent runs.
Chef and PuppetConfiguration managementExisting estates that already run them. See our Puppet guide.Check each vendor's current product page before a new adoption.

What are the benefits of infrastructure as code?

  • Standardisation. One set of rules replaces many hand-made variations, which removes a common source of mistakes.
  • Change control. Infrastructure files are reviewed, versioned and can be reverted to an earlier state.
  • Speed. Development, test and production environments can be created from the same definitions.
  • Knowledge sharing. The code documents how the environment is built, so new team members can read it rather than rely on memory.
  • Reliability. Software, not people, makes the change, so the result is more predictable.
  • Better delivery pipelines. Developers, QA and security can create matching environments in CI/CD.

Treat these as capabilities to measure in your own environment. We do not quote a percentage gain, because it depends on the starting point.

Which best practices matter most?

  • Codify everything you can. Treat the files as the single source of truth for what runs.
  • Keep code in version control and use branches and pull requests for peer review.
  • Test and deploy through CI/CD with unit, integration and security checks run on every change.
  • Modularise. Reusable modules give consistent environments and let you limit who can change which component.
  • Keep documentation short. The code describes the setup, so write only diagrams and runbooks for people new to the process.
  • Close the console. Manual changes create drift, so route them through code.

For containerised estates, see our guide to infrastructure as code and containers.

How do you govern, secure and control the cost of IaC?

Code does not make infrastructure safe by itself. It makes the rules checkable. Put security and policy checks in the pipeline so a non-compliant change fails before it reaches production. Our guides on IaC security, policy as code and compliance as code cover the controls in depth.

  • Access. Give pipelines and engineers the least privilege they need, and separate who can write code from who can approve and apply it.
  • Secrets and state. Keep secrets out of the files, and restrict access to state, which Terraform calls a source of truth for the environment.
  • Policy. Encode rules on network exposure, encryption and tagging as automated checks.
  • Cost. Tag resources in code so spend can be traced to teams, and review plans for unexpected additions before applying them.
  • Evidence. Pull requests, plans and pipeline logs give auditors a record of who changed what and why.

As teams add AI agents that propose or apply infrastructure changes, the same discipline matters more. ElixirData Context OS keeps governed context, versioned policy and decision traces in one decision layer above AI agents, and AgentGRC keeps autonomous agent actions inside policy, with the audit trail risk teams need.

What is a sensible adoption sequence?

  1. Pick one workload that is repeated often, such as a test environment, and codify it.
  2. Choose tools by cloud footprint, skills and licence position, using the table above.
  3. Put the code in Git with pull request review and a protected main branch.
  4. Add a pipeline that validates, plans and applies, with a human approval step for production.
  5. Add policy checks and drift detection in advisory mode, then enforce them.
  6. Extend to production and legacy estates in stages, and retire manual console changes.

What are the trade-offs, and when should you not use IaC?

  • Skills. Teams need to learn the tool, its state handling and its testing approach.
  • State and drift. Console edits outside the code create drift that the next run may overwrite.
  • Tool and licence risk. Licence changes and product retirements, as in the table above, can force a migration.
  • Overhead for tiny estates. A one-off proof of concept that will be deleted in a week may not justify the pipeline.
  • Imperative script sprawl. Ad hoc scripts grow harder to maintain as the estate grows.

To map one infrastructure change decision your agents should make, and the context and policy it depends on, book a Context Workshop. See what happens in the workshop.

Frequently asked questions

What is infrastructure as code?

It is the practice of defining servers, networks, storage and access rules in version-controlled files that a tool applies, instead of configuring them by hand.

What is the difference between declarative and imperative IaC?

Declarative IaC describes the desired end state and the tool works out the steps. Imperative IaC lists the steps to run. Terraform, CloudFormation and Bicep are declarative.

Which tool should we choose?

Start from your cloud footprint and skills. Terraform or OpenTofu suit multi-cloud estates, CloudFormation or CDK suit AWS, Bicep suits Azure, and Ansible handles configuration. Check licence terms and product status first.

Is Terraform still open source?

HashiCorp moved future releases from MPL 2.0 to the Business Source License v1.1 in August 2023. OpenTofu is a Terraform fork hosted under the Linux Foundation.

How do we stop configuration drift?

Route every change through code, run plan or drift checks on a schedule, and treat manual console edits as exceptions that must be brought back into the files.

Where do we go next for AWS or Google Cloud?

Read our guides on IaC on AWS and IaC on Google Cloud.

Sources: Terraform documentation, HashiCorp licence announcement, OpenTofu FAQ, Microsoft Learn: Bicep, AWS CloudFormation documentation, Google Cloud Infrastructure Manager, Ansible documentation.

Next Steps for Adopting IaC

Talk to our experts about implementing Infrastructure as Code (IaC), how industries and departments use IaC to automate infrastructure management, optimizing IT support, improving scalability, efficiency, and responsiveness across operations.

 

Follow XenonStack on LinkedIn: XenonStack on LinkedIn for new guides on agentic AI, data and platform engineering.

Ready to put AI agents to work? Explore ElixirClaw, the agentic OS platform to build, orchestrate and govern AI agents.

Table of Contents

navdeep-singh-gill

Navdeep Singh Gill

Global CEO and Founder of XenonStack

LinkedIn profile

Navdeep Singh Gill is serving as Chief Executive Officer and Product Architect at XenonStack. He holds expertise in building SaaS Platform for Decentralised Big Data management and Governance, AI Marketplace for Operationalising and Scaling. His incredible experience in AI Technologies and Big Data Engineering thrills him to write about different use cases and its approach to solutions.

Get the latest articles in your inbox

Subscribe Now

Interested in Solving your Challenges with XenonStack Team
Get Started

Get Started with your requirements and primary focus, that will help us to make your solution

Please Select your Industry
Banking
Fintech
Payment Providers
Wealth Management
Discrete Manufacturing
Semiconductor
Machinery Manufacturing / Automation
Appliances / Electrical / Electronics
Elevator Manufacturing
Defense & Space Manufacturing
Computers & Electronics / Industrial Machinery
Motor Vehicle Manufacturing
Food and Beverages
Distillery & Wines
Beverages
Shipping
Logistics
Mobility (EV / Public Transport)
Energy & Utilities
Hospitality
Digital Gaming Platforms
SportsTech with AI
Public Safety - Explosives
Public Safety - Firefighting
Public Safety - Surveillance
Public Safety - Others
Media Platforms
City Operations
Airlines & Aviation
Defense Warfare & Drones
Robotics Engineering
Drones Manufacturing
AI Labs for Colleges
AI MSP / Quantum / AGI Institutes
Retail Apparel and Fashion

Proceed Next