Save your private cloud like code — Intro to Infrastructure as Code
There are various ways to get different resources in the cloud. For example, you can use cloud provider’s website to create a virtual machine. This can also be done using command-line-interface (CLI) and REST API.
Apart from virtual machines, you can have database services, pipelines, various networking components and other resources. All of these resources combined creates your infrastructure. All of these resources can be created using command-line, REST API and cloud provider’s website.
An example of creating a virtual machine using AWS CLI can be found at cli-services-ec2-instances.html. With some modifications, the same command can be used to create an identical virtual machine in a different subnet/region.
Assume that you have created all of your resources in US region using CLI. If you make changes to the CLI commands and run it in Asia region, you will have an identical copy of your US resources. If you have 100s of resources then you may have 100s of commands. Managing all these can be really tricky. But you have backup of your infrastructure. Instead of saving commands, how about defining your resources in JSON/YAML file as following:
As long as the YAML/JSON file is structured properly, Cloud Provider would parse it and create resources. If you want to create another virtual machine, just throw it in the YAML/JSON file and give it to the cloud provider. One can also store these files in a repository. Essentially, bunch of YAML/JSON files can represent your infrastructure in a private cloud. This is called Infrastructure-as-code (IaC). AWS has it’s own tool to define IaC which is called CloudFormation. For more information on CloudFormation checkout https://jigarr.medium.com/infrastructure-as-code-cloudformation-1d7478fe25d2
Different cloud provider has different syntax to create a virtual machine. A virtual machine is called an EC2 instance in AWS, Compute Engine in Google Cloud and droplet in DigitalOcean. Usually end-user just wants to create a virtual machine and start using it. Wouldn’t it be awesome if you have standard way to write YAML/JSON file and create a Virtual Machine in any cloud platform of your choice? This is exactly what Terraform does. It can support various different resources and various cloud providers.
In this post we reviewed,
- Infrastructure as Code (IaC)
- CloudFormation
- Template — JSON/YAML file that outlines various resources to create
References
CloudFormation concepts — cfn-whatis-concepts.html