Publish AI, ML & data-science insights to a global community of data professionals.

Infrastructure as Code

Managing infrastructure resources with code

During my journey in engineering I realised that the tools we use will always change, as a consequence of the continuous advancements in technology. And I think we all need to accept this reality in order to be able to keep up to speed with technologies that can truly impact the way we build systems and applications.

Over the last decade, most companies around the globe had to go through a tech lifting (aka digital transformation) and move from on-premises infrastructure to cloud. And I believe the biggest struggle in such projects is to actually convince people that a new technology (such as cloud) should be managed in a different way compared to what you were used to. One of the best tools that can help you manage cloud (and even on-prem) resources is Infrastructure as Code.


What is Infrastructure as Code (IaC)

Infrastructure as Code, is a methodology adopted by DevOps and lets teams manage infrastructure resources (such as compute, storage and network resources) programmatically. In other words, IaC can help you define and deploy infrastructure as part of a continuous delivery mechanism.

Like pretty much everything in technology, IaC tools evolved fairly quickly and most modern tools now use code that is both human and machine readable. And this is a very important feature since it enables reusability of various infrastructure components.

Infrastructure as Code on Google Trends - Source: Author
Infrastructure as Code on Google Trends – Source: Author

Advantages of IaC

The biggest advantage of Infrastructure as Code paradigm is consistency. Without IaC, organisations need to maintain the infrastructure resource deployment or modification in a manual way.

This means that at some point it will be extremely hard to reproduce this configuration since some ad-hoc steps were required whilst some others were executed in a different order. Infrastructure as Code enforces consistency by allowing users to represent infrastructure environments using code. Therefore, the deployment and modification of resources will always be consistent and idempotent (i.e. every time a specific operation gets executed, the same result will be generated).

Additionally, IaC tools will save you time and energy that would have been otherwise been spent on the manual deployment of changes. Modern IaC tools make use of declarative code files in which users can describe the end state of the infrastructure within an organisation. This means that you shouldn’t worry too much about the underlying logic since the required actions in order to get to that end state will be performed automatically by the IaC tool.

Furthermore, IaC tools usually offer mechanisms to enhance reusability. This feature makes your code base less verbose and more readable while at the same time team members are encouraged to apply best practices.

Another big advantage of IaC is collaboration. Since the infrastructure resources are defined in configuration files it means that these files can be version controlled. At any given time, the team is able to collaborate together in order to modify an environment and even be able to see the history (from commits) of an infrastructure resource. This makes debugging much easier and accurate.


with Terraform

One of the most popular IaC tool in the DevOps world is HashiCorp Terraform, an open-source tool you can use to define and update your infrastructure resources within declarative configuration files.

The tool can be used to define both on-prem and cloud resources and manage the lifecycle of your organisation’s infrastructure. Essentially, the Terraform workflow consists of three different steps namely, write, plan and apply.

  • Write: This steps involves the resource definition (either on-prem or cloud). These resources can be low-level components such as storage and compute or even higher level components such as SaaS and DNS entries.
  • Plan: In this step, Terraform will prepare an execution plan in which all the steps involved will be described. These steps could be related to the creation, update or deletion of resources based on the changes that were made in the previous step.
  • Apply: In this last step, Terraform will perform (upon user confirmation/approval) the operations described in the planning step. For example if you update a Virtual Private Cloud network then Terraform recreate the resource based on the new configuration.

In fact, the Terraform community has written more than 1700 different providers that can be used to manage tons of different type of resources. Additionally, the tool allows users to define their own custom modules that can also enhance reusability in your code base.

Apart from the IaC functionality, Terraform can also be used for multi-cloud deployments, Kubernetes and network infrastructure management, Policy as Code (PoC) and virtual machine image management.


Other IaC Tools

Ansible is another popular tool that offers IT automation.

It handles configuration management, application deployment, cloud provisioning, ad-hoc task execution, network automation, and multi-node orchestration. Ansible makes complex changes like zero-downtime rolling updates with load balancers easy

Chef also offers Infrastructure Management Automation tools:

Chef® Infrastructure Management™ enables DevOps teams to model and deploy secure and scalable infrastructure automation across any cloud, VM, and/or physical infrastructure.

Apart from third-party tools, some cloud providers offer native IaC tools.

Deployment Manager is the native IaC management tool on Google Cloud Platform and can help you automate the management of infrastructure resources on the Cloud.

Microsoft Azure provides a native support for Infrastructure as Code with Azure Resource Manager (ARM) that lets developers define infrastructure resources as ARM templates.


Final Thoughts

Infrastructure as Code is one of the methodologies that can truly impact the way teams build, test and maintain systems and applications. Various tools exist that can help you define infrastructure and deploy resources continuously and consistently.

IaC can help you move away from manual configuration and deployment of infrastructure resources and offer an automated – and most importantly consistent – way for doing so.

Additionally, with IaC you are able to version control the files in which infrastructure resources are defined as well as to enforce best practices such as modularity and code reusability.

Finally, we went trough some of the most popular and commonly used Infrastructure as Code tools including Terraform, Ansible, Chef and even some tools offered natively by Cloud providers such as Amazon, Google and Microsoft.


Become a member and read every story on Medium. Your membership fee directly supports me and other writers you read. You’ll also get full access to every story on Medium.

Join Medium with my referral link – Giorgos Myrianthous


Related articles you may also like

Diagrams as a Code in Python


Apache Airflow Architecture


Docker Image vs Container


Towards Data Science is a community publication. Submit your insights to reach our global audience and earn through the TDS Author Payment Program.

Write for TDS

Related Articles