Author avatar

Michael Levan

Infrastructure as Code: What It Is and Why You Should Be Automating It

Michael Levan

  • May 18, 2020
  • 5 Min read
  • 204 Views
  • May 18, 2020
  • 5 Min read
  • 204 Views

Introduction

Have you ever had to create a resource manually? Perhaps a virtual machine or a virtual network? Maybe some storage? Deploying resources in the cloud manually is cumbersome and error-prone. If you have to deploy more than one resource, you have to dedicate time to the deployment. What if you could write code in some of the most popular languages to automate the entire process for you?

In this guide, you will learn what Infrastructure-As-Code (IaC) is and three key reasons you should useit to make your life easier.

What is Infrastructure-As-Code?

Let's think about deploying a server, perhaps an EC2 instance. There's a lot that goes into it. To name a few key aspects:

  • The size of the EC2 instance
  • The name of the EC2 instance
  • Whether or not the EC2 instance will have a public IP address
  • What security group(s) it will use
  • Who will have access to the instance

These key aspects are very important—in fact, they can make or break an environment from a security perspective. It seems so straightforward, yet so full of errors. It's very easy to click the wrong security group or accidentally give an EC2 instance a public IP address and make it accessible to the world. Do you want to avoid that? Welcome to Infrastructure-As-Code.

IaC gives engineers the ability to define cloud resources, on-prem resources, and networks as code. You can specify in the code what size you want an instance to be, what CIDR a VPC should have, and the list goes on and on. IaC even works for serverless, for example, creating a Lambda function.

Let's delve into a few more reasons you should use IaC.

Reason 1: Code Doesn't Lie

Code does not lie. What does this mean? All of us, in some way, shape, or form have clicked the wrong button, and it's okay. Mistakes happen to the best of us. However, what if there was a way to know if a mistake occurred and how to fix it? Plenty of engineers have spent hours working on a problem only to realize it was a small change, but it took them hours to find it because there was no history.

When you implement IaC, you can store that code in source control, like GitHub. When you store code in source control, you have a history of the code. Any change that was made or any code that was written is all recorded in source control. Another great feature of source control is having the ability to specify where dev/testing code lives and where production-ready code lives. That way, you can test as much as you want without jeopardizing any amount of uptime. Something like this doesn't exist in a world where IaC isn't available and managing infrastructure manually is the only way.

Reason 2: Team Collaboration

When you are working on a team of engineers that are spread out around the world in different time zones, it becomes incredibly difficult to collaborate. If someone is three hours or six hours ahead of you, scheduling can be nearly impossible. Let's say that's not the case and all teammates work in the same time zone. What if someone is on vacation or out sick and you really want to share valuable information with them? If they aren't there to see or hear it, it'll be quite difficult to convey the message.

With IaC, you don't have to worry about that anymore. All of the integrations, implementations, and progress are written down, literally. You don't have to get someone on the phone or pull them out of a meeting. You can simply write some code, commit it to source control, and share it out with peers. Infrastructure-As-Code gives you the ability to collaborate in any environment, across any time zone, and around anyone's schedule.

Reason 3: It's Faster

You walk into the office one morning and someone has made a request: Development needs ten servers created to test a new application, and it's resource heavy, so they want to see how it scales. Wow, ten servers? That's a lot! Doing that manually will take a day or more to deploy and test before handing the servers over.

With IaC, you can do that in one deployment. The code you write can create ten servers, or 100 servers if the development team needs them. You no longer have to worry about manually creating any cloud resource when you start to use IaC. You can even schedule deployments and walk away from the keyboard and the deployments will still be running!

Welcome to CloudFormation

CloudFormation is a native Infrastructure-As-Code tool in AWS. It is written in a JSON or YAML format that allows you to deploy, manage, and configure any cloud resource available in AWS. The beautiful thing about CloudFormation is that it's built for both IT professionals and developers alike.

Many cloud vendors have IaC and automation support. Since this guide is part of a Pluralsight learning path about AWS CloudFormation, it focuses on that vendor.

Conclusion

In this guide, you learned what Infrastructure-As-Code is and why you should implement it. Not only does it save you time, but it allows for a better team environment with plenty of collaboration and helps you manage multiple cloud resources.

5