Introduction to Infrastructure as Code
Infrastructure as Code (IaC) is the process of configuring and managing the infrastructure through a descriptive model. It is all about treating your infrastructure configuration and provisioning in the same way you treat your application source code. The configuration modules are typically stored in version control systems in very well-documented code formats which provides greater accuracy, reduces errors, and increases speed and consistency.
IAC is one of the most important DevOps practices used in conjunction with continuous delivery. The benefits that lead many businesses to migrate to IAC are changeless infrastructure, an increase in the speed of delivery, scalability, cost savings, and risk mitigation.
IaC allows DevOps teams to use different tools and approaches to automatically control and customize the required infrastructure, instead of manually configuring the servers and operating systems. With the increase in the number of production and delivery cycles, the use of Infrastructure as Code (IaC) tools has changed the way software engineers design, test, and release their applications.
Automation tools that promote the IaC best practices are necessary to make the process of building and configuring the infrastructure more competitive and effective, reducing the costs and effort involved.
Click to know about 6 Principles of Infrastructure as Code
What are the approaches for writing Infrastructure as Code?
The approaches are for writing Infrastructure as Code
- Declarative Approach
- Imperative Approach
The distinction between declarative, imperative, and intelligent approaches is 'what' vs. 'how' vs. 'why.'
Declarative (functional): The declarative approach defines the desired state of the target, i.e., What should be the target's actual configuration. The steps to set up a server are not defined. Instead, the list of requirements or third-party software needed to set up the infrastructure or server is defined.
Imperative (Procedural): The imperative approach defines the commands that must be executed to achieve the desired result. The imperative focuses on how the infrastructure is to be changed to meet the desired result.
HashiCorp Terraform is the most popular and open-source tool for infrastructure automation. It helps in configuring, provisioning, and managing the infrastructure as code. With terraform, you can easily plan and create IaC across multiple infrastructure providers with the same workflow. It uses the declarative approach to define the required infrastructure as code. Terraform allows users to have a pre-execution check to validate whether the configurations meet the result expectations or not, before updating or provisioning the infrastructure. It enables users to have their desired infrastructure across multiple cloud providers through a single and consistent CLI workflow. You can easily provision different environments using the same configuration and manage the full lifecycle of your desired infrastructure; thus reducing human errors and increasing automation in the infrastructure provisioning and management process
Ansible was developed by RedHat with an idea to promote simplicity. It contributes towards IT modernization and helps DevOps teams to have faster, more reliable, and coordinated application deployments. You can easily establish multiple identical environments with security baselines without having to worry about the fulfillment of compliance requirements. As far as business is concerned, Ansible brings in a competitive advantage by providing time for bringing in innovation and strategy within the organization and aligning IT with the business needs.
Ansible is considered to be the simplest way to automate the provision, configuration, and management of applications and IT infrastructure. Ansible enables users to execute playbooks to create and manage the required infrastructure resources. It does not use agents and can connect to servers and run commands over SSH. Its code is written in YAML as Ansible Playbooks, making it very easy to understand and deploy the configurations. You can even expand the features of Ansible by writing your own Ansible modules and plugins.
Read more about What Is Ansible? | How Ansible Works?
AWS CloudFormation is an embedded IaC tool within the AWS cloud platform that provides you with an easy way to quickly and efficiently provision and manage a collection of multiple related AWS and even third-party resources using Infrastructure as Code. It allows you to implement all the required best practices of DevOps and GitOps. With CloudFormation, you can easily manage the scaling of your resources and even automate further resource management by integrating CloudFormation with other required AWS resources. Besides this, AWS CloudFormation also allows you to use its open-source CLI to build your own resource providers in order to provision and manage the third-party application resources along with the native AWS resources.
The models and templates for CloudFormation are written in YAML or JSON format. You just need to code your desired infrastructure from scratch with the suitable template language and use the AWS CloudFormation to provision and manage the stack and resources that you have defined in the template. CloudFormation also uses Rollback Triggers to restore infrastructure stacks to a previously deployed state if errors are observed, to ensure that deployment and upgrading of infrastructure are achieved in a controlled manner.
Azure Resource Manager
Azure Resource Manager is the service provided for the deployment and management of Azure resources. It is an Azure specific IaC tool that allows resources to be deployed, maintained, and tracked in a single collective action rather than individually. It natively incorporates Role-Based Access Control (RBAC) into the resource management mechanism to allow users to apply control of access to all resources within a resource category.
Resource Manager allows you to use declarative templates instead of scripts to manage your infrastructure. With Azure resource manager, you can easily redeploy your infrastructure solution multiple times throughout the application development lifecycle by effortlessly maintaining consistency in the state.
Google Cloud Deployment Manager
Google Cloud Deployment Manager is an infrastructure deployment service provided by GCP to automate the creation, configuration, provisioning, and management of resources on Google Cloud Platform. You can easily create a set of Google cloud resources and then manage them conveniently as a single unit. Using YAML or Python, you can build models, preview what changes will be made before deploying, and view your deployments in a console user interface.
This Infrastructure as Code tool uses a declarative language approach to specify what the configuration is supposed to be and let the system figure out the rest. Google Cloud Deployment Manager provides simultaneous deployments of many resources at once, controls the order of resource creation, and creates resource definition dependencies too. Deployment configurations are treated as code and those deployments can easily be repeated over and over again by maintaining consistency in their state.
Chef can be counted among the industry’s most notable IaC tools. Chef uses the procedural style language wherein the user has to write the code and step-by-step specify the way to achieve the desired state. It is dependent on the user for the determination of an optimal deployment process. Using its Ruby-based DSL, Chef allows you to create recipes and cookbooks. These recipes and cookbooks specify the exact steps required to achieve the desired configuration of your applications and utilities on existing servers.
This infrastructure management tool highly focuses on the deployment and modeling of a scalable and secure infrastructure automation process across any desired environment. With Chef, DevOps teams can provision and deploy on-demand infrastructure with ease. Chef is one of the most common configuration management solutions used by enterprises in their processes of continuous integration and delivery.
Puppet is yet another open-source configuration management tool that is most commonly used to pull the strings on a number of application servers at once. It also uses a Ruby-based DSL like chef, where you can describe your infrastructure's desired end state. The primary difference between Puppet and Chef is that it uses a declarative approach, where you just have to decide, how the configurations you want look like, and then Puppet finds out how to get there.
Puppet is referred to a set of IAC tools that are used to deliver your infrastructures quickly and on a secure scale. It offers a wide group of developers who have built modules that help extend the functionality of the software. Puppet integrates with almost all the leading cloud Infrastructure as Code platform providers such as AWS, Azure, Google Cloud, and VMware, enabling multiple cloud automation.
Click to know in depth about Puppet
SaltStack is an open-source configuration management tool based on Python that offers a simple solution for provisioning, deploying, and configuring infrastructure on any platform at a very fast rate.
SaltStack focuses on the automation of infrastructure, security, and network within the organization. It is an easy-to-use IaC tool that proves to be very useful during the mitigation and remediation of common infrastructure issues. It is a secure and cost-efficient IaC solution that provides automation and orchestration and reduces manual effort. It has the capability to automatically detect problems with event triggers and return back to the desired state if required. Salt even has SSH support that can support agentless mode. It has a scheduler that lets you specify how often the managed servers should run your code.
( R )?ex
(R)?ex or Rex is an easy to use automation framework that doesn’t enforce any model of its own on the user. With rex, it’s your choice to use any combination of declarative or imperative approach, push or pull management style, local or remote execution, etc. It is an open-source deployment and configuration management platform that is just all about Perl Coding using which you can seamlessly extend the modules as per your requirement. It’s SSH support to control remote hosts makes it easy to onboard and use effectively to automate the repeatable tasks; thus saving human effort and time.
Vagrant is yet another one of the best IaC tools, developed by the Terraform creators, HashiCorp. The difference is that Vagrant focuses on building computing environments that use a limited number of virtual machines, rather than massive cloud infrastructure environments that can span hundreds or thousands of servers over several cloud providers.
HashiCorp Vagrant is a simple, yet powerful tool that is focused on making development environments easier. It promotes the use of unified workflows by leveraging the creation of declarative configuration files containing all the required configuration details. It enforces state consistency across environments and supports integration with existing configuration management tools like Puppet, Chef, SaltStack, Ansible, etc.
How to choose best IaC Tools?
There are different types of tools in IAC because not the same tool can perform all the tasks. The tools are defined in three main categories :
- Infrastructure provisioning
- Configuration of Provisioned infrastructure
- Application deployment
And the phases in which they automate tasks :
- Initial Setup phase
- Maintaining phase
There is one more category in which we can divide the tools is “how they
- Declarative or imperative
- Mutable or Immutable
- Agent or Agentless
We have several tools available to automate the infrastructure, and we have divided the tools into different categories. Now let us understand when we should choose which IAC tool.
For configuration Management vs. Provisioning
Ansible, Chef, Puppet, and salt stack are configuration management tools that can install and configure the applications on existing infrastructures. Whereas terraform and cloud formation are infrastructure provisioning tools, they can be used to provision the servers and other infrastructure like load balancers, databases, networking configuration. Some tools can perform both tasks. For example, Terraform can do both infrastructure provisioning as well application deployment.
For Mutable Infrastructure vs. Immutable Infrastructure
Chef, Puppet, Ansible, and SaltStack are all mutable infrastructure tools by nature. If you configure these tools to install a new version of an existing package or software, it will install the software update on your existing servers and make the changes in real-time.
Whereas for a tool like Terraform (an immutable IAC tool), every “change” is a new server deployment.
For Procedural vs. Declarative
Chef and Ansible follow the procedural approach as we have to write code that specifies the step-by-step to achieve the target state. Terraform, CloudFormation, SaltStack, and Puppet all use a declarative method, in which we write code that defines the target state we want to achieve, and the IAC tool figures out how to get there.
For Agent vs. Agentless
Chef, Puppet, and SaltStack are agent-based tools that involve the installation of an agent on the target computer. This agent usually runs in the background on the target machine and carries out the operations necessary to achieve the goal.
On the other hand, No agents are needed for Ansible, CloudFormation, or Terraform. Some of them need agents, but these are usually included in the infrastructure we use.
For Provisioning and Configuration Management
Ansible and Terraform are the tools that can perform both provisioning and Configuration management. Ansible and Terraform can work together. We can use Terraform for provisioning of infrastructure, databases, load balancer, network topology, etc. Ansible can be used to deploy applications on top of these infrastructures.
The only tool that satisfies all of our requirements is Terraform.
We believe that IAC is the future of computing resource provisioning and management. While it comes with its own set of implementation challenges, the benefits it delivers, in the long run, surpass the hurdles it faces at present. The IT and DevOps teams are set to greatly benefit from Infrastructure as Code (IAC).
IAC tools prove to be the key components in making this implementation possible. The above list provides you with some of the top IaC tools in the market today. This list is certainly not exhaustive but will definitely help you to get a starting point in this field.
- Read More about GCP for Infrastructure As Code - Tools
- Discover more about Solutions for Infrastructure and Applications Modernization