Areeb Abdul Ghani
Areeb Abdul Ghani's blog

Areeb Abdul Ghani's blog

Infrastructure as Code

Infrastructure as Code

Areeb Abdul Ghani's photo
Areeb Abdul Ghani
·Oct 6, 2022·

4 min read

Subscribe to my newsletter and never miss my upcoming articles

What is infrastructure as code, and why do we need it?

Let's start with understanding the problem If you don't have infrastructure as code

  • If you provision your servers manually, and install your software manually, then this is how things would look like.

Screenshot 2022-10-05 211510.png • In a manual approach, you'll start with provisioning a server. So let's say you are using the cloud. Probably you would provision a virtual server from the cloud.

• You would then go ahead and manually install some software on it. Maybe something like Java, maybe Tomcat, and then you would need to configure the software manually. So you need to configure Tomcat, and then you'd go ahead and deploy your application.

Screenshot 2022-10-05 213129.png • When it comes to the microservices architecture, You might have tons of applications. You might have a lot of microservices, you would have several instances of these microservices. And each of these microservices might be developed in different technologies.

• All of these microservices might be in Java the other one might be in Python, and the other microservices might be developed using JavaScript.

Screenshot 2022-10-05 213453.png • In such kind of a varied environment, The manual approach is very - very difficult to implement. This will not only slow down your application teams but also is error-prone.

• How do we fix it? The way can fix it. It's by going for infrastructure as code.

• The main concept behind infrastructure as code, is to treat your infrastructure the same way, as you treat your application code. Just like you create a deployable unit from your code. You need to create the infrastructure from code and configuration.

• If you implement your infrastructure as code properly, your infrastructure team can focus on value-added work, rather than focusing on routine work of installing servers. If you're able to automate your infrastructure, you'd be having less number of errors and you'll be able to quickly recover from failures.

Screenshot 2022-10-05 214228.png • The added advantage of using infrastructure as code, is that if you have multiple environment for each of these microservices, and multiple instances for each of these environments. image.png • If you use infrastructure as code, you can be confident that these servers are consistent. The most important steps in infrastructure as code are provisioning a server, and customizing the software on the server. Screenshot 2022-10-05 214607.png

• The most popular tool for provisioning servers is terraform. There are also cloud specific alternatives to terraform, like AWS cloud formation with terraform. You can create a number of resources in the cloud like virtual servers, load balancers databases, networking, configuration - all that just from your terraform configuration. So provisioning tools like terraform will help you to create a server based on a template, which might be created by tools. Or AWS also provides something called a Amazon machine image. image.png • The next important step in infrastructure as code, is something called configuration management. Configuration management is all about managing the software which is installed on your servers. Once you provisioned this server, you would want to install the right software, and configure it the way you'd want to do it.

• The tools which will help you to do that are called configuration management tools. image.png • The most popular configuration management tools are Ansible, chef, and puppet.

• So you can use terraform to provision hundreds of servers on the cloud, and you can use Ansible to configure all the servers with the software you do want. image.png • Once you have the servers provisioned, and the software configured on them, you can deploy your applications onto these servers, using either Jenkins. Or as Azure DevOps, you can deploy applications as part of your continuous deployment pipelines, to these servers.

• In these steps, we quickly looked at why infrastructure as code is important and we looked at the various tools that are important as part of infrastructure as code.

Also i found a great blog on Terraform vs. Ansible : Key Differences and Comparison of Tools

It was a good read for me on these topics

• Orchestration vs. Configuration Management

• Declarative vs. Procedural

• Mutable vs. Immutable

• State Management

• Thanks for reading and i would love to connect with you guys on Socials

• Any feedbacks are welcome!!

Did you find this article valuable?

Support Areeb Abdul Ghani by becoming a sponsor. Any amount is appreciated!

See recent sponsors Learn more about Hashnode Sponsors
 
Share this