What is Infrastructure as Code and Why Should You Use It?
November 3, 2022
Infrastructure as Code (IaC) is a software development practice that describes the definition and configuration of cloud infrastructure – networks, servers, storage, etc. – in code. This software code can then be used to automatically provision infrastructure resources through virtualization technologies like Amazon Web Services (AWS). In this article, we’ll tell you everything you need to know about IaC and why you should start using it today!
According to research from TechTarget's Enterprise Strategy Group (ESG), only 34% of the average developer's time is spent on net-new innovation. I'm looking to increase that number as I'll explain in this article.
Your resources are valuable
Chances are, you're currently employed by a start-up or scale-up company that provides a digital product such as an app or web service. The founders started the business because they had an original idea and knew there was an audience for it. In the months and years following, they managed to build a group of gifted individuals all working together toward one common goal: creating success for their product.
Focusing on what makes you unique
The thing is, no matter how unique your app or online service may be, many of the underlying server infrastructure requirements are the same (or at least similar) for thousands of other tech companies out there. You're still going to need an infrastructure, though - and it will need to be reliable, secure and scalable.
In today's world where everything is cloud-based, spinning up a web stack yourself has actually become relatively easy. And yet... something about throwing an internal team in charge of that doesn't feel right. Not when you consider the cost for scaling up and maintenance - both growing over time - with an ever-growing customer base. You’d rather spend that time on your unique product and customers.
The drawbacks of outsourcing infrastructure
A logical step would be to find a reliable cloud partner who can create and manage your cloud infrastructure. They will be able to design an optimal stack for you, based exactly on what you need. They'll also take care of provisioning and managing it. Sounds great, right?
There's a big drawback: the way many cloud partners work is that they will use the management console from your cloud provider (like AWS) in order to deploy infrastructure components and make necessary changes manually—or if they're not doing it through the console, they might use the command line or API, which means essentially that everything is being done manually as well.
Black box
Your infrastructure becomes a black box at this point - meaning you are 100% reliant on your cloud partner when it comes to incidents and new requirements because they are the only ones who know what they did. So there are potential risks involved here.
- What if you decide you’re not fully happy with your cloud partner and want to move on?
- What if you are low on resources and can’t afford hiring someone anymore?
- What if they are busy but you need to upgrade a server right now?
- What if they go bankrupt or get acquired by a competitor?
Enter: Infrastructure as Code.
What is Infrastructure as Code (IaC)
Infrastructure as code is a way to manage and provision your cloud infrastructure by writing it out in code instead of doing it manually. Kind of like how you might get the recipe for your favorite pumpkin pie from your local bakery—you’ll know exactly what’s inside and how to make it yourself.
With IaC, every single component of your infrastructure (web server to database)—no matter how big or small—is written out in an editable configuration file, called a template. If you want just one large template, then go ahead! Or if you want something more modular depending on your business needs, easy as pie!
The benefits of IaC
Because it’s code, you can use version control systems like Git to track every change made to your infrastructure (when and by whom) over time. Other benefits include increased speed of deployment, less likelihood of making mistakes, repeatability, consistency and reduced cost.
For example, you can decide to create fully separated staging, testing and production environments using the same set of code combined with just a few variables. Once you’re fully satisfied with your staging environment you can deploy an exact same copy in a different environment in a matter of minutes.
Example tools and example code
There are several languages and tools that can be used to provision your infrastructure with code. Examples are:
- Amazon AWS has its own language called Cloudformation.
- HashiCorp created Terraform to function as a cloud agnostic solution.
- Chef by Progress Software
- Puppet by Puppet Labs
- RedHat Ansible
Here’s an excerpt of a Cloudformation script that deploys a web server:
Of course the above example is missing context, but just to show you that you won’t need hundreds lines of code to add a server.
Continuous integration and delivery
IaC is the perfect solution for establishing a Continuous Integration / Continuous Delivery (CI/CD) pipeline. Once set up, your development team can manage your infrastructure as part of their regular software development process. And with automated deployments, DevOps teams are now able to update existing components or even create entirely new stacks themselves. Your infrastructure is not a black box anymore but fully managed by your own team with minimal effort.
Conclusions
Using Infrastructure as Code is a way to safeguard your infrastructure. Instead of only living in the minds of (possibly external) systems engineers, you now have an all-encompassing and intricate blueprint at your fingertips. This will prove invaluable when vendors, employees, or business needs change over time.
IaC also saves considerable amounts of time because development teams can build portions of infrastructure themselves and update them according to needs. And lastly it allows staff members to spend more time on what makes their company special - increasing chances their business succeeds and beats the competition.
Next steps
Now we hear you thinking; but who’s going to write our initial templates? Well, at Skripted that’s exactly what we do! Reach out for a quote.
About the author
Join my mailing list
Stay up to date with everything Skripted.
Sign up for periodic updates on #IaC techniques, interesting AWS services and serverless.