Table of Contents
Successful deployment of stable software involves a lot of things to be fixed not just when code is working on your system, it has passed the code reviews, until it is delivered to the end user successfully. Before software gets delivered to users seamlessly it involves a lot of work to be accomplished such as making it work on production servers, making code resilient to attackers and spikes or outages, having backend infrastructure intact and so on.
Over several years since we moved from heavily deployed hardware-based data centres to cloud platforms, with the emergence of DevOps framework the intent is to have software/ application be always available in deployable state. Ultimate goal is to automate as much as possible of the software delivery process which means managing your infrastructure not by clicking around a web page or manual execution of shell commands but using code. This concept is typically referred to as ‘infrastructure as a code’.
In today’s article we would venture more in detail about Terraform which is infrastructure as a code solution, learn about its architecture and how it works, its features and use cases etc.
What is Terraform?
The concept of ‘Terraform’ tool is based on the idea of ‘infrastructure as a code’ which you can write and execute to define, deploy and update your infrastructure. All aspects of operations are treated as software including hardware (e.g., setting up physical servers). The key is to manage everything as a code be it servers, databases, storage, networks, log files, application configuration, documentation, automated tests, deployment processes and so on.
There are four ad hoc categories of IaC tools namely:
- Ad Hoc scripts,
- configuration management tools,
- server templating tools and
- server provisioning tools
Terraform falls under fourth category.
Terraform is an open-source tool by Hashicorp and written in Go programming language. The Go code compiles down into a single library , one binary for each of the supported operating systems. These binaries can be used to deploy infrastructure from your laptop or a build server. Terraform binary makes API calls to one or more providers such as AWS, Azure, Google cloud, OpenStack etc. Terraform management capability allows it to handle low level and high-level components such as networking, storage, compute instances, SaaS features, DNS entries etc.
Features of Terraform
- Entire deployment process can be automated and developers can pick up their own deployment as required
- Automated process is more consistent, repeatable, safe and free from manual process errors
- State of infrastructure can be stored in source files which anyone can read so no dependency on system admin
- Version control can be maintained in efficient manner as IaC files can be stored with version information
- Infrastructure can be packaged into reusable modules
- Building and management of multi-tier applications
- Configuration, creation, provisioning and bootstrapping of software demo on diverse cloud providers such as Google, AWS etc.
The key components of Terraform architecture are described below:
Terraform core is responsible for creation of dependency graphs and reading configuration. It has heavy dependency on current graph theory for dependency management.
Plugins can be defined as the external individual static binaries. The core of terraform communicates with plugins by RPC interface during planning and implementation phases. The most common type of Terraform plugin are provider plugins which implement resources along with any basic create, read, write , update and delete (CRUD API) to communicate various 3rd party services.
It is a third party component and external API or service. Core of Terraform interacts with the Terraform provider for performing any operations and in turn plugins will communicate with upstream API. Core of Terraform does not require understanding of API and Terraform plugin does not require understanding graph theory and this establishes a clear corner separation.
How does Terraform work?
Terraform allows infrastructure to be expressed as code in a simple, human readable language HCL (Hashicorp Configuration language). Terraform CLI reads configuration files and provides execution plans for changes which will be reviewed to ensure they are secure and then applied and provisioned.
Extensible providers allow management of a broad range of resources inclusive of hardware, IaaS, PaaS and SaaS services. You write code and Terraform reads it through API calls and establishes the described state. With Terraform provider we can manage the entire cloud infrastructure – virtual machines, bare metal servers, drives, firewall groups, load balancers, networks, floating IP address, reserved IP address and so on.
Quick facts !
Hashicorp Terraform has a market share of 4.82% in the configuration management market.