Terraform

What is Terraform?

Terraform is an open-source tool created by the Hashi Corp. It is a declarative coding tool that works as Infrastructure as a Code (IaC). Terraform enables developers to use high-level configuration language HCL that describes the “end state” cloud or on-premise infrastructure to run an application. After describing the end states, it rolls out a plan for reaching the end state and accordingly provides the infrastructure.

By using a simple syntax, Terraform can provision infrastructure across multiple clouds and on-premises data centers. Further, if the configuration changes it can safely re-provision infrastructure to the configuration changes. And all this happens automatically, hence it reduces the chance of human error.

Components of Terraform:

  • Configurations: Terraform configuration is the text file that contains the infrastructure resource definition. This configuration can be written in the Terraform format using the .tf extension or in JSON format using the .tf.json extension.
  • Providers: Terraform takes advantage of the multiple providers to talk to back-end platforms and services like AWS, Azure, DigitalOcean, Docker, or OpenStack.
  • Resources: Resources are the primary building blocks of the Terraform configuration. Once you define a configuration, in reality, you define one or more resources. Since these resources are provider-specific, you need to use each resource differently. For example, a resource for AWS can be different than a resource for Azure. It is also a flaw in Terraform because to shift to a new resource you need to recreate the configuration.
  • Variables: Using variables you can make Terraform configurations more portable and flexible. To use the variables you just need to change the value of these variables, and you can use a single configuration multiple times. However, you must know that this configuration is restricted to a specific provider.

Benefits of Terraform:

  • Orchestration and Configuration:  The primary goal of all the configuration management tools was to manage server configuration so that the installation and management of the software, already existed in the server or virtual machine, can be done easily. Contrary, Terraform focuses on server provisioning. Once you treat the whole cloud infrastructure as a code and all the parameters are combined in a configuration file, all the team members can easily collaborate like any other code.
  • Multi-Provider: This is the most incredible feature of the Terraform because it supports multi-cloud orchestration such as AWS, Azure, OpenStack, etc. as well as on-premises deployments. The multi-provider facility makes Terraform a helpful tool because you can use two different resources from the two different cloud providers at the same time.
  • Immutable Infrastructure: When you run software updates on the server using Chef, Salt, Puppet, and Ansible chances are it can lead to a configuration drift, which further leads to bugs that are responsible for security breaches. However, Terraform addresses this issue using an immutable structure approach where every configuration change leads to a separate configuration. It means the deployment of a new server and the provisioning of the old one. By using this method, updating the development environment becomes very smooth and bug-free, and you can return to the old configuration easily.
  • Syntax:  Terraform uses a custom language called HCL. This language is designed to make it human-readable and at the same time, it is machine friendly as well.
  • Dry Run: The best advantage of Terraform is that it supports “Plan”. By looking at the terraform file, it determines the changes that you are going to make in the infrastructure before you make those changes.
  • Client-Only Architecture: Terraform takes advantage of the cloud provider’s API to provision infrastructure that in turn eliminates the need for additional checks and also running the configuration management in a separate server. Ansible also does this but there are some limitations. However, Terraform works with service provider’s APIs and explore varieties of options that make it secure, reliable, and easy to use.
  • Super Portability: Terraform is extremely helpful when it comes to portability. To describe the infrastructure for multiple cloud providers you need only one tool and language. Thus migrating to a different vendor becomes hassle-free.
  • How Tata Implemented Infrastructure as a Code Using Terraform?

    TCL’s one of the customers was a non-banking, asset finance company registered with the Reserve Bank of India. Their key businesses include vehicle loans and leasing, housing loans, and insurance. Its IT services were primarily hosted on-premises. But pretty soon they migrated to Amazon Web Services because of the increased operational costs of managing a data center, the high lead time for augmenting IT infrastructure, the high rate of staff turnover, the surging data security cost, and more.

    Since the customer had no experience of using automation tools, TCL deployed AWS with an automation approach using Terraform for provisioning DevOps and management.

    With the help of Terraform, the company achieved:

    • Cloud vendor independence and portability when needed, with the least efforts.
    • Stable, easily customized deployment.
    • Secure infrastructure and data.
    • Code build and release management tasks automated.
    • All infrastructure deployment tasks are automated to minimize the impact of staff turnover.

    Terraform Vs. Ansible

    To assess one’s true potential, you need to compare it with its rival. Terraform is the closest rival of the Ansible, and to find out the best between the two, you must compare these two tools so that you can easily decide which tool is right for you. The table below will help choose the best.

    Basis of comparison

    Terraform

    Ansible

    Type

    Terraform is an orchestration tool.

    Ansible is a configuration management tool.

    Infrastructure

    Provides support for immutable infrastructure.

    Provides support for mutable infrastructure.

    Language

    Terraform follows a declarative language.

    Ansible follows a procedural language.

    VM provisioning, networking, and storage management

    Terraform provides comprehensive VM provisioning, storage, and network management.

    Ansible provides partial VM provisioning, storage, and storage management.

    Packaging and templating

    Terraform provides partial support for packaging and templating.

    Ansible provides complete support for packaging and templating.

    Lifecycle management

    Terraform relies on lifecycle management heavily.

    Ansible does not have lifecycle management.

    Conclusion

    There are lots of configuration management tools available in the market but none of them is as helpful as Terraform. Apart from assisting system administrators while adjusting to the configuration changes, it can provision infrastructure on multiple platforms (cloud and on-premises).