Introduction
As the name says, Infrastructure as code, it means creating your infrastructure with the help of code. Now you might think if I can create the resources and design my infrastructure by signing into my cloud providers account such as AWS, Google etc which is super easy and interactive, then why do I have to write code for this as well? As we go along the post we would be uncovering the real benefits of creating you infra via code vs the web UI 😊
Lets take an example of AWS in this post. There was a reason behind Amazon creating AWS to support their growing business in various horizons and as days went by, AWS became one of the go to place for many major organisation for cloud solutions. At the time of writing this post, AWS stands as the most profitable business for the Amazon. But here come a twist, at least what I feel after logging into my AWS account, I kind of go lost as to where to start from. So many options and wide variety of services that AWS provides that you tend to keep searching for things. After so much struggle lets say you manage to setup your development environment by spinning up a bunch of EC2 instances, setting up queues, database, S3 buckets etc etc, As days pass by, now you have to setup you new UAT environment 🥺 . As of writing this post, I have noticed that AWS sometimes change their UI as well as change some options here and there.
Nowadays instead of creating the infra by web UI, people have started creating the infrastructure via code. Instead of searching through so many options and creating an S3 bucket or an EC2 instance through UI , writing code is much more simpler
Benefits of Infrastructure as code (IaC)
Configuration Consistency and Resuse
We can create an environment using the same set of configuration used for initial environment setup. Chances of human error for environment setup would be less as compared to creating via the web UI. If you have done this using UI, you would tend to forget some setup steps. Imagine if there was no code, the engineer sets up the complex environment and left the organization some day. Imagine how difficult it would be for the new engineer to figure out how it was setup.
Infrastructure Automation
We are automating the whole process of infrastructure rather than using the manual steps to configure via the Web UI. This reduces the risk on human error.
GitOps
Not only are we creating infra via code, but this code is being maintained in version control system. It will be leveraged or improved by multiple people. Once we push the new changes, build pipeline is run which provisions the infra for you, hence this becomes he part of the build process. Same process of code reviews and pull requests can be followed here as well like we do for our application code base. We can change back and forth with the versions maintained if there are any issues with the infra.
Terraform
Terraform is Infrastructure as a code tool that you can use to work with any of the the current available cloud providers platforms. Terraform is open source and uses Hashicorp configuration language (HCL) to define resources. Terraform makes sure that whatever code you write it will make sure that it will call the corresponding cloud provider API’s and provision those resources. Sometimes the properties can be different because each cloud provider probably expects is own unique set of values to provision a source. We write code for multiple cloud providers in the same file and Terraform is responsible to create the resources with the right cloud providers.
I hope you liked this post. Happy Learning 😊