It can be said with certainty that, at some point, you’ve interacted with the Cloud. If not, then you currently are! As you’re reading this article on Medium’s cloud servers, you are probably listening to Spotify’s music hosted on theirs while your photos are being backed up to Apple’s iCloud (if somehow you haven’t ran out of the generous 5GB).
Essentially, the Cloud is everywhere. And you should probably know how to use it. Maybe even know how to deploy your own applications on it.
Observing Cloud Adoption at Scale
Since 2006, with the advent of Amazon Web Services (AWS), the demand for cloud has been ever-increasing. Gradually, every big corporation is migrating all of their data and compute resources to various cloud services. However, there is still a high barrier to entry when it comes to hosting on the cloud at scale. A single instance is easy to provision and maintain manually, but it becomes increasingly difficult to do that as your organization’s data and resources grow.
As a business owner, you would not be happy to dissipate a huge amount of effort trying to provision multiple pieces of infrastructure and maintain them one by one. You want to spend more time developing your product than caring about the infrastructure and servers.
Moreover, a single server configuration change can take weeks before it is even replicated across all your instances. This can lead to situations where each instance may end up with a slightly different configuration leading to a phenomenon known as configuration drift.
Managing Cloud at Scale
So how can you tackle this problem of deploying and maintaining infrastructure at scale?
With Terraform. 🚀
Terraform is a server provisioning tool created by HashiCorp, creators of Vault and Packer), using the Go programming language. It uses HCL (Hashicorp Configuration Language) to provision and manage infrastructure across multiple providers, both in the public and private cloud.
Terraform is one of the many Infrastructure-As-Code (Iac) tools available that businesses can use to facilitate infrastructure management in the cloud at scale. These tools allow you to effectively express your infrastructure needs in the form of code, where just one file can contain the configuration for your servers, databases, lambda functions, etc.
According to 2016 State of DevOps Report, companies that are adopting DevOps practices, like IaC tools, are deploying 200 times more frequently, with 2,555 times faster lead times, and are recovering 24 times faster than their non-DevOps competitors.
Now that I’ve introduced Terraform and the concept of IaC tools, let’s answer a few questions that you may have.
1. How does using Infrastructure-As-Code (IaC) tools, such as Terraform, help a company grow quickly?
With faster and safer deployments.
IaC tools empower developers to manage infrastructure along with all the existing code. Developer teams are able to set structured and automated pipelines for infrastructure which leads to less error-prone and quicker deployments as manual maneuvering is minimized. Additionally, the same blocks of code can be used to create infrastructure for DEV and QA environments which helps in ensuring consistency with the production environment.
Furthermore, developers can leverage existing versioning tools to debug issues in the code for infrastructure configurations and create automated tests suites to identify configuration bugs before production deployments. This increases the reliability of new deployments and also makes rollbacks much easier.
Another significant advantage of using IAC tools is the restructuring of responsibilities between developers and sysadmins. With developers being in charge of writing and maintaining code for infrastructure, the dependence on sysadmins to monitor production deployments is reduced. This prevents sysadmins from getting overburdened and makes sure production-specific knowledge is not confined to just one job family.
According to 2016 State of DevOps Report, companies that are adopting DevOps practices such as IaC tools, are deploying 200 times more frequently, with 2,555 times faster lead times, and are recovering 24 times faster than their non-DevOps competitors.
You must be wondering “Sure, IaC tools sound great! But why just Terraform?”
2. How is it different from using other tools such as CloudFormation, Chef or Ansible?
While using any of the tools mentioned above can allow you to achieve the same end state, it is important to consider your intent, your requirements and the trade-offs you are willing to make before choosing a tool. Firstly to make this choice, you need to understand the difference between “configuration management” and “infrastructure orchestration”.
Configuration management refers to the act of installing and managing software on existing server instances. This includes installation of various packages, running bootstrap scripts and setting up configuration files for the server instance. Tools such as Ansible, SaltStack, Chef and Puppet are specifically designed for configuration management and offer various features that make it optimal for this use case. However, these configuration management tools are not that great when it comes to server provisioning.
On the other hand, infrastructure orchestrations tools are responsible for the provisioning of server instances while delegating configuration tasks to other tools such as the ones discussed above. These orchestration tools are designed to make it easier to provision servers at scale using features, such as declarative formatting and state management, which make it ideal for this use case. Terraform and Cloudformation are examples of a few tools that come under this umbrella.
3. What differentiates Terraform from Cloudformation?
When comparing Cloudformation with Terraform, the former is usually not a great choice. Cloudformation works only over AWS which restricts the users from using multiple cloud providers as part of the infrastructure. As Cloudformation is developed by AWS internally, it lacks backing from a large open source community which leads to slower bug fixes and limits the user to solutions only offered by AWS. Cloudformation code is also generally superfluous which makes it hard to manage and more vulnerable to errors when managing infrastructure on a large scale.
In contrast, Terraform is designed to be an ideal tool to manage infrastructure at scale. A few important features that support this use case are declarative style execution and inbuilt state management.
Declarative style execution allows Terraform users to simply state the end desired state in the configuration file and leave it up to terraform to figure out how to efficiently reach that state. The benefit of such an approach is that the configuration files capture the current state of the infrastructure. Simply reading through the terraform files can give you a detailed picture of all the infrastructure that has been deployed. Consequently, as the current state is always captured, it also increases the reusability of the code. If you are to ever to modify your infrastructure, you just need to make the desired changes in the config file and terraform figures it out on its own how to reach that state.
Inbuilt state management is another feature that allows the user and the system to keep track of infrastructure. These state files, managed by Terraform, are mappings of infrastructure as defined in the configuration files to provisioned infrastructure in the real world. Whenever the user makes any changes to the configuration files, terraform first verifies the status of the current infrastructure using the state file, makes the required changes and then stores the new state inside the file. By storing the state file to a remote S3 location, multiple teams can make changes to the infrastructure at once which allows for greater collaboration.
In conclusion, this article gives you a deep enough insight into why Terraform is one of the best tools in the market to manage cloud deployments at scale. In my next post, I will be giving you a brief tutorial of how to get started with Terraform and maybe teach you how to deploy an application on a cloud server.
Feel free to ask any questions that you may have about Terraform or if it’s the right tool to use for your infrastructure deployments.
Till then, happy reading folks!