Infrastructure as Code, or IaC, is the practice of automatically provisioning and configuring infrastructure using code and scripts. IaC allows developers to automate the creation of environments to generate infrastructure components rather than setting up the necessary systems and devices manually.
In the past, system administrators had to painstakingly provision and configure all the hardware and software required to run applications by hand. This process is untenable in modern software delivery and software development where teams are expected to deploy hundreds of apps a day. IaC lets teams automatically spin up networks, databases, virtual machines and any other infrastructure components to create the cloud environment they need to test and run their apps.
IaC is an essential DevOps practice. Automation and agile processes need available IT infrastructure to run and test code. Having to physically configure an environment every time a developer wants to develop, test or deploy software would counteract the speed that DevOps practices bring. With IaC, developers can set up infrastructure in minutes, with all of its configuration files versioned to ensure consistency across IT environments.
In the following sections, we’ll look at why IaC is important for organizations, the many benefits it offers and how you can get started implementing it in your company.
IaC is important because it makes the provisioning of infrastructure easier, faster and more scalable. To understand this, it’s necessary to look at the workings of infrastructure management.
Historically, developers, testers and other infrastructure consumers had to file a ticket or email a request whenever they wanted to provision infrastructure resources. The IT operations team would review and log all the tickets in the queue, then manually allocate the requested resources for each one. While time-consuming, the process was sufficient because most organizations didn’t have a lot of infrastructure to manage. It wouldn’t be uncommon for a single virtual machine, for example, to live in a company’s data center for years or for teams to conduct manual configuration of infrastructure or other manual processes in the environment.
Infrastructure today is much more dynamic, thanks to automation tools and API-driven cloud infrastructure that enable resource provisioning in days or weeks instead of months and years. Organizations can scale up infrastructure for peak hours or seasons and scale it back down when demand returns to normal levels. This elasticity makes it impractical to manage infrastructure manually, as it would require submitting thousands of tickets every day to increase or decrease workload capacity as needed and waiting for admins to fulfill those requests.
IaC solves this problem by replacing manual interaction with an interface that automatically provisions and configures infrastructure. Users can run a script to spin up a thousand machines for peak workload times and run it again to tear them down when demand is lower. With this approach, DevOps teams can create servers, deploy operating systems, set up data storage and configure all other infrastructure components they need on demand.
The increasing need for building and deploying applications and delivering customer value more quickly makes IaC a critical tool for most organizations.
IaC offers many benefits to organizations, including:
Mutable and immutable are two different types of infrastructure environments. Mutable simply means the infrastructure can be modified after it has been provisioned — to accommodate a new server, for example — while immutable means it can’t.
The main advantage of a mutable infrastructure is that it allows developers to customize existing servers to specific apps or development needs rather than requiring them to establish new ones. By extension, this allows the infrastructure to meet the needs of each user.
But this changeable nature sets up some significant drawbacks. Because each server is uniquely configured, it’s more difficult to diagnose and manage each one, a condition called “configuration drift.” Also, because server changes aren’t typically documented, it also hinders version tracking, making it harder to find and reproduce technical issues.
Immutable environments are more rigid, requiring infrastructure components to match particular specifications. Once the infrastructure is built, ad-hoc modifications can’t be made; any needed server changes will necessitate construction of entirely new infrastructure based on updated requirements and the removal of the old infrastructure. This practically eliminates the problem of configuration drift, while making it easier to identify and resolve technical issues, and ensuring testing consistency from development through production.
Immutable IaC is increasingly essential for DevOps teams. Together, the concepts of immutable infrastructure and IaC enable consistent environments that accelerate the DevOps process and reduce delays in the delivery pipeline. This allows teams to focus more on innovating than spending time taking care of infrastructure.
IaC is supported largely by open-source tools such as HashiCorp Terraform, Red Hat Ansible and Helm, as well as Chef, Puppet and Salstack. Open-source IaC tools use coding language that allows users to provision and manage infrastructure across multiple cloud vendors and that are compatible with other open-source solutions. By contrast, the big cloud vendors include proprietary IaC code tools as part of their cloud computing ecosystems, such as AWS CloudFormation for AWS Cloud and Azure Resource Manager for Microsoft Azure. These tools have the advantage of being designed specifically for their respective cloud platforms, but their closed approach can result in vendor lock-in for the user.
IaC tools vary in the details of how they work, but they all take one of two approaches to infrastructure automation — declarative or imperative. It’s important to understand the differences between these two programming language styles when selecting an IaC tool.
With the declarative approach, the user “declares” what the provisioned infrastructure should look like by specifying a list of resources and required properties. Then the IaC tool installs and configures all the infrastructure components and manages code versioning. With the imperative approach, users specify a list of commands they want the IaC to run so the infrastructure will be provisioned step by step. Put simply, declarative programming lets users say what infrastructure resources they want, and imperative programming lets them say how they want the infrastructure resources created.
Although both approaches can be used to create the desired infrastructure, there are some differences to consider. To understand them clearly, let’s discuss how each approach handles instructions illustrated by the example of taking a taxi to the airport. A declarative instruction would be to tell the driver, “Get me to the airport by 11 a.m.” Here, you’ve stated your desired outcome, and it’s up to the taxi driver to determine the best route, speed and other factors to get you there on time.
An imperative approach, on the other hand, would be to give the driver explicit instructions on how to get you to the airport by 11 a.m. For example, “Pick me up at 10:15 a.m., take a left at the corner, get on the freeway and accelerate to 65 mph … ” Both of these approaches will get you where you need to go, but the second approach doesn’t leave much wiggle room if the driver encounters an unexpected obstacle, like a road detour or a car accident on the freeway. Declarative and imperative instruction work much the same way in IaC.
Declarative tools handle all the complexities of provisioning your desired infrastructure. However, you’ll have little insight into why it made the choices it did without consulting the tool’s administrator. An imperative approach gives you more control over how your infrastructure is provisioned, but it requires more work from the developer, and its reliance on explicitness means if it encounters an obstacle at any step, you’ll have to stop and work out the solution — which can make this approach tough to manage at scale. The “best” style depends on several factors, such as how much code you’re writing, the likelihood you’ll be updating the infrastructure down the road, and how much control you require over the way changes are made to your cloud services.
Terraform is a popular open-source, cloud-agnostic IaC tool that uses declarative programming and a high-level configuration language called HCL (HashiCorp Configuration Language) to define and provision infrastructure for running an application.
In essence, Terraform works by reading the code describing the infrastructure’s “end state” and creating a graph depicting the listed resources and their relationships to each other. It then compares this graph against the resources in the cloud and generates a plan that outlines what changes will be applied to the cloud and in what order to achieve that state, then executes that plan to provision the infrastructure.
Terraform is popular with developers for several reasons:
Terraform uses a three-step core workflow. The workflow is the same whether an individual is working alone on infrastructure or collaborating with a team, but there are additional practices in each step when multiple people are working together.
This core workflow for teams is a recurring loop that is used for each change, which can occur several times per day or week.
There are many best practices for better infrastructure provisioning with Terraform. Here are just a few:
IaC will likely become the standard for provisioning, managing and orchestrating compute resources. The traditional approach of procuring, installing and configuring hardware along with applying the right configuration management tools that integrate it into a new environment is no longer practical as organizations demand more flexible and responsive infrastructure. Cloud-native development and virtualization have helped eliminate the problem of managing physical hardware, and IaC takes the next step of letting developers automate infrastructure provisioning on demand. IaC facilitates faster time to market, reduced costs and improved ROI, positioning it as an essential component of DevOps.
IaC can help your organization speed up its infrastructure provisioning processes and lifecycle, maintain consistency across development environments, and free your IT teams to spend more time on higher-value activities. If you need to deliver at speed and scale, IaC can provide the foundation for doing so now and for years to come.
See an error or have a suggestion? Please let us know by emailing ssg-blogs@splunk.com.
This posting does not necessarily represent Splunk's position, strategies or opinion.
The Splunk platform removes the barriers between data and action, empowering observability, IT and security teams to ensure their organizations are secure, resilient and innovative.
Founded in 2003, Splunk is a global company — with over 7,500 employees, Splunkers have received over 1,020 patents to date and availability in 21 regions around the world — and offers an open, extensible data platform that supports shared data across any environment so that all teams in an organization can get end-to-end visibility, with context, for every interaction and business process. Build a strong data foundation with Splunk.