What is infrastructure as code (IaC)? (original) (raw)

By

Published: May 05, 2025

Infrastructure as code (IaC) is an IT practice that codifies and manages underlying IT infrastructure as software. It enables developers and operations teams to automatically manage, monitor and provision resources instead of manually configuring hardware devices, operating systems (OSes), applications and services. IaC is also referred to as programmable or software-defined infrastructure.

The concept of IaC is similar to programming scripts, which automate IT processes. However, scripts are primarily used to automate a series of static steps repeated numerous times across multiple servers. IaC uses higher-level, descriptive language to code more versatile and adaptive provisioning and deployment processes.

For example, the IaC capabilities included with the IT management and configuration tool Ansible can install a MySQL server, verify that it is running properly, create a user account and password, set up a new database and remove unneeded databases.

The code-based infrastructure automation process resembles software design practices, where application development teams develop declarative code, control code versions, test iterations and limit deployment until the software is approved for production.

IaC also shares the same goal of abstracting IT resources as cloud computing, but it automates the entire process -- from provisioning and configuration to deployment and management. IaC is also used to provision and manage cloud infrastructure, using the cloud provider's application programming interfaces (APIs) to access and interact with the provider's resources and services.

How does infrastructure as code work?

In the simplest terms, IaC uses software code to provision and manage an IT infrastructure. By using code to define a desired IT outcome, organizations can improve infrastructure consistency, security, automation and performance.

Much time and effort are involved in manually provisioning and configuring servers, storage, networks, Oses, applications, and other devices and services, such as databases, load balancers and firewalls. It can take hours -- even days -- for a human to provide a suitable deployment environment for an enterprise workload and data. Human error can creep into many aspects of this manual effort, leading to the following problems:

IaC embodies all the instructions needed to build and deploy a desired IT environment as a software entity. Developers and IT staff can create detailed instructions to assess the steps required and measure the code's outcomes.

The infrastructure code delivers reproducible results and can be executed at the push of a button or in response to specific conditions. It brings a high level of automation to provisioning and management.

Change is easier to manage because any modifications to the infrastructure code result in a new version that is well documented and can be managed with any standard version control system. If a problem arises due to a change, it can be corrected by running a previously known-good version of the code. This simplifies troubleshooting and improves compliance and security for the business.

The following four basic types of IaC are often used in tandem:

  1. Scripts are often used to automate simple ad hoc tasks.
  2. Configuration management code defines and automates the installation and configuration of devices such as servers.
  3. Provisioning code automates setting up an overall infrastructure, tying together varied aspects of the environment.
  4. Container code relies on templates to define image files with libraries and dependencies needed to deploy and execute an application.

The IaC process typically involves the following three steps:

  1. A developer uses domain-specific language to create specifications for the desired infrastructure.
  2. The specification files are sent or staged to a server or repository, such as GitHub, or an API.
  3. The IaC platform uses the specification files, either automatically or on demand, to create and configure the intended infrastructure.

A chart showing IaC principles, features and results.

IaC enables IT teams to translate into code a data center's physical resources, services and discrete configurations to automatically provision and manage those resources.

IaC approaches: Declarative vs. imperative

Infrastructure-as-code tools operate using declarative and imperative approaches.

Declarative approach

A declarative programming approach outlines the desired, intended state of the infrastructure but does not explicitly list the steps to reach that state. It declares an intended goal and allows the underlying IaC tools to decide how those goals are implemented. A commonly known declarative programming language is Structured Query Language (SQL). Amazon Web Services (AWS) CloudFormation templates, among others, are written in the declarative style of infrastructure as code.

Imperative approach

An imperative programming approach defines commands that enable the infrastructure to reach the desired state. It defines the precise steps and their order to achieve a desired outcome and does not deviate from those steps. Object-oriented languages, like C++ and Java, can be used for imperative programming. A tool such as Chef can be used declaratively but also imperatively as needed.

In both approaches, IaC is configured on a template, where the user specifies the resources needed for each server in the infrastructure. The template is used to verify that a system is configured correctly or has been set up appropriately. Templates can be constructed as a set of layers of resources, such as in AWS CloudFormation, which makes a stack.

IaC best practices

IaC involves infrastructure configuration and infrastructure management with high levels of automation. While there is no universal approach to deploying and using IaC, numerous best practices help streamline these deployments. Standard IaC best practices include the following:

Immutable vs. mutable infrastructure

Mutable infrastructure refers to changing components in production, while the overall service or application operates normally. Immutable infrastructure assembles and sets components and resources to create a full service or app. If a change is required for any component, it is not changed or reconfigured; it is all updated and effectively redeployed in an instance. A new iteration is assembled, tested, validated and launched, while the old iteration is discontinued and its resources are released for reuse.

Immutable infrastructure has gained favor, particularly for cloud and microservices environments, which are highly scalable and involve many interdependent components and services. Any one-off updates to address specific issues can cause configuration drift that cascades as updates are rapidly pushed to production. Reissuing sets of immutable services and components is more efficient than patching and reconfiguring individual infrastructure components. IaC emphasizes using immutable infrastructure techniques, though immutability is not a prerequisite for IaC.

Benefits and challenges of infrastructure as code

There are many benefits associated with IaC, from automation efficiency to its flexibility to align with other modern IT practices. Other IaC benefits include the following:

Despite its benefits, IaC also poses some disadvantages, including the following:

IaC tools configure and automate infrastructure provisioning. These automation tools can automatically execute infrastructure deployment, such as servers with orchestration functionality. They can also configure and monitor previously provisioned systems.

IaC tools enforce the setup from the template using push or pull methods. In the push method, a centralized server sends the desired configuration to a specific system or systems. The pull method is initiated by a request to a centralized server from a system or systems in the infrastructure. Tools are typically designed by default for push or pull deployment of code, but they can be set up for specific instances to do the opposite. These tools should also be able to roll back changes to the code in case of unexpected problems from an update.

The following are examples of IaC tools:

Some tools rely on a domain-specific language, while others use a standard template format, such as JSON and YAML.

Organizations should consider the target deployment and select a tool for that environment. For example, AWS CloudFormation is designed to provision and manage infrastructure on AWS and works with other AWS offerings. Similarly, Microsoft Azure Resource Manager manages infrastructure on the Azure platform, while Google Cloud Deployment Manager is Google's infrastructure deployment service. Alternatively, Chef works with on-premises servers and multiple cloud provider infrastructure-as-a-service offerings.

IT operations can go beyond IaC and take a code-based approach to managing all their resources. Learn how everything as code works, and see if it's right for your organization.

Continue Reading About What is infrastructure as code (IaC)?

Dig Deeper on Systems automation and orchestration