Terraform has become hot topic now days. In few years this tool has gain its popularity worldwide, many have adopted it as it has proven good progress which made this tool one of an essential tool of DevOps tool chain. Have a look the Google trend you will get picture how much popularity it has gain.
So What is Terraform why it so much popular?
Terraform is a one of the example of infrastructure as a code software developed by HashiCorp. It enable the user to build datacenter infrastructure with the help of high level configuration language on Private Cloud such as OpenStack or on Public Clouds like AWS, Microsoft Azure, Google Cloud Platform, IBM Cloud (formerly Bluemix), Oracle Cloud Infrastructure, or VMware vSphere Infrastructure.
With few commands or codes you can deploy or manage whole infrastructure in Cloud for example, below code will configure a server (instance) on Amazon Web Services:
provider "aws" {
region = "us-east-1"
}
resource "aws_instance" "example" {
ami = "ami-40d28157"
instance_type = "t2.micro"
}
And to deploy it, you just run one command:
> terraform apply
Terraform is more simple but it is more powerful which made it an emerging key player in the DevOps world. It automate the lot of System Admin tasks by removing tedious and manual work which is prone to human error. Good thing with these automate tasks is that it can be compliant with DevOps practices e.g., automated testing, continuous integration, continuous delivery
How Terraform works?
Terraform is an open source tool which is written in Go programming language. Terraform can easily be compiled with Go programming language in binary with same name that is Terraform. Terraform binary codes are easily to comprehend though you are not from programming background. Terraform can authenticate and connect with different cloud providers like AWS, Azure, Google Cloud, DigitalOcean, OpenStack etc. through API calls and API authentication mechanism (eg. API keys are used to authenticate with AWS) and can provision the infrastructure to cloud providers on your behalf.
Terraform configuration capable to make API calls it has text files that contain codes which defines what infrastructure you want to create. Codes may defines the compute resources at low level like instances, storage and networking also at high level it manage components such as DNS entries, SaaS features, etc. An example of Terraform configuration as below:
resource "aws_instance" "example" {
ami = "ami-40d28157"
instance_type = "t2.micro"
}
resource "dnsimple_record" "example" {
domain = "example.com"
name = "test"
value = "${aws_instance.example.public_ip}"
type = "A"
}
In above configuration you can see codes can create instance in AWS first and then after perform DNS entries in AWS Route53.
Figure: Terraform binary translates the contents of your configurations into API calls to cloud providers. To push terraform binary you only need a laptop or computer which connects with Cloud providers through API plugins Source: O’reilly
Key features of Terraform
Infrastructure as Code: The Infrastructure as a code is just like a programming scripts which is developed for automate the IT process. Codes are written in high level language or any descriptive language use to automate the series of static steps which must be repeated numerous times across multiple servers. Additionally infrastructure can be shared and re-used.
Execution Plans: This is called Terraform planning phase where it generates the execution plan. In execution plan phase it shows how Terraform will do when you call apply. This phase save from errors or mistakes which can occur when Terraform manipulates the infrastructure.
Resource Graph: Terraform builds a graph of all your resources, and parallelizes the creation and modification of any non-dependent resources. Because of this, Terraform builds infrastructure as efficiently as possible, and operators get insight into dependencies in their infrastructure.
Change Automation: With less human intervention complex changes can been applied with the help of execution plan and resource graph you will be ascertain for changes implemented by Terraform which avoid many possible human errors.
Reference Sources:
https://www.oreilly.com/library/view/terraform-up-and/9781491977071/ch01.html
https://medium.com/devopslinks/why-should-terraform-be-one-of-your-devops-tools-29ae15861b1f
https://www.terraform.io/intro/index.html