DEV Community

Cover image for The Beauty of Infrastructure as Code (IaC) and Why You Should Be Using it
Malchiel Ed Urias
Malchiel Ed Urias

Posted on

The Beauty of Infrastructure as Code (IaC) and Why You Should Be Using it

If you are a new entrant into the world of Cloud computing and DevOps and you are looking to know more about technologies to make your life and work a lot easier while still being efficient, then you just might have stumbled upon a very useful article.

I come from a CyberSecurity background and my exploration into the world of DevOps and cloud computing is a relatively new one so that would explain why Infrastructure as Code is a concept that I got excited about. Before my discovery I was quite comfortable manually spinning up instances and configuring VPCs manually, it was what I knew.

I have learned through this as well as many other experiences, that when developing yourself in tech, as much as it might be important to pick up various skills, one thing you shouldn’t forget to consider is how these skills would be applied in organizations that run large-scale projects and products. Usually, we pick up skills that could only be applied in smaller products, it is for this reason that I probably didn’t have a lot of extensive knowledge on Infrastructure as Code before now.

Now, what exactly is Infrastructure as Code?

Imagine, you would like to provision the IT infrastructure (servers, networks, etc.) for a product, you could simply just open up your AWS console (or that of your preferred cloud provider) and spin up a few EC2 instances (or virtual machines as the case may be) and begin from there, right? Right. Now imagine if this was a larger product with many more servers and possibly in separate environments and you would need to configure and set up these various services in different environments. Now a task that seemed straightforward at first now suddenly has many more complexities. Going ahead to provision manually would most definitely lead you into a lot of issues that may arise either immediately or later down the line.

These issues led to the introduction of Infrastructure as Code. IaC is the process of provisioning and managing IT infrastructure through the use of codes in the form of configuration specification files rather than manually configuring the infrastructure. It is simply the automation of manual configuration of Infrastructure. IaC provides a means to provision exactly the same configuration each time, thereby, reducing the risks of environmental drift and human errors.

How Does IaC Work

Now, some would think that IaC would simply be about putting a bunch of configuration code together and stuffing it away in some repository and the job is done but having a good knowledge of how IaC works and how different IaC tools function can come in very handy to your work. There are different styles in the way different IaC tools work and knowing the difference between declarative and imperative infrastructure as code can actually mean the difference between a happy DevOps engineer and a miserable one.

Going from our knowledge of different programming language paradigms, we can easily deduce what each of these IaC styles mean:

Declarative Infrastructure as Code: Declarative infrastructure as code involves declaring the desired outcome or result of a job instead of explicitly stating the steps to arrive at that result.

Imperative Infrastructure as Code: This on the other hand would involve specifying the steps and instructions to follow to arrive at the final result. This is very much the same when it comes to infrastructure as code.

The issue with imperative IaC however, is that if an issue that was not specified in the code occurs, it would lead to a crash because the program would have no idea what to do next.

The tools for IaC are of course categorized into two sections:

● Imperative Tools

● Declarative Tools

Imperative IaC Tools

These tools define the sequence of steps to set up infrastructure and enable it to reach the required state. System engineers have to write scripts to provision the infrastructure sequentially.

Compared to Declarative IaC tools, these tools are more tedious to use and less resistant to failures and errors. More effort would be required to keep these scripts up to date and reuse is usually more difficult.

Declarative IaC Tools

Declarative IaC tools, following the declarative approach, describe the desired outcome of the infrastructure without listing the sequential steps of arriving at that state. The IaC tools take in the requirements and automatically configure the necessary infrastructure.

Which to Use

Like many other things in the world of tech, there is no exact right or wrong one to use. It would usually depend on the situation. In a case where you would just need to configure a relatively small infrastructure that may not necessarily need any future updates, a simple imperative script is the way to go. However, if you need to build a more sophisticated infrastructure, you should use a declarative programming tool.

Some Popular IaC Tools

● Terraform

● Pulumi

● Puppet

● Ansible

● Chef

● SaltStack, and of course

● AWS Cloud Development Kit (CDK) which works with AWS Cloudformation

Benefits of IaC

Knowing the many problems that are related to manual infrastructure management, it is very obvious how much of a relief IaC can be but let’s explicitly look at some notable benefits of using IaC.

Some of these notable benefits of using IaC in setting up and maintaining your infrastructure would include:

● Speed: This is a major benefit that IaC provides. Engineers are now able to set up and manage complete infrastructures within minutes whereas it would have taken hours or even days to do had they used a manual approach

● Lower Cost: The use of IaC and Cloud Computing has benefitted numerous companies financially as the need to set up physical data centers, hire many engineers for operations, and purchase hardware is now unnecessary. Using services from your cloud providers and hiring a few engineers to run these reduce the cost of operations drastically.

● Efficiency: The use of codes instead of manual setups reduce the risk of human errors in infrastructure management. The same environment can be created exactly the same way through code but if done manually by a human, mistakes would almost be inevitable.

● Consistency: Manual processes are a recipe for mistakes. This is why the DevOps methodology advocates for automating everything. IaC eradicated the need for manual configuration almost completely. It guarantees that the same configuration is implemented in every case exactly the same way.

Conclusion

IaC has indeed revolutionized the way we think of infrastructure management, particularly cloud infrastructure. It has made tasks a lot easier and although it seems like just another non-mandatory trend, it is far from optional. IaC is fast becoming a necessity in businesses. The speed it provides to infrastructure management is a major fact in change management and organizations that embrace this would harness the ability to quickly adapt to changing business needs and requirements and those who don’t, well, they would eventually have to.

Remember, you snooze, you lose. Stay competitive.

Top comments (0)