-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

HashiCorp Terraform Associate (003) Exam Guide
By :

Terraform is an IaC tool that lets you create and manage your infrastructure by writing code in a simple language called HashiCorp Configuration Language (HCL).
The following section describes the features of Terraform and explains how the problems of manual provisioning and other IaC options are solved by Terraform.
We will explore the primary features of Terraform in this section.
A tool that is very specifically oriented toward a particular platform becomes highly dependent on the features of the platform and hinders customers’ ability to switch to another platform when they want to. It is very important for an IaC tool to be cloud-/vendor-agnostic (i.e., able to run on any cloud without getting tied to a single cloud/vendor) for such customers. Unlike many IaC tools provided by cloud vendors, Terraform is fully cloud-/vendor-agnostic and works with all the major cloud providers and also the majority of other vendors.
Terraform was launched by HashiCorp in 2014 when the IT industry used either scripts, cloud-specific tools, or configuration management tools for infrastructure automation. It pioneered a new way of solving the infra-automation problem and brought in multi-cloud support. This was done by using a declarative approach to provisioning infrastructure, along with having “current state and desired state” as the central idea, where Terraform assesses the current infrastructure state with the desired state of infrastructure as defined by the user and then makes relevant changes to change the current state to the desired state. Trust in the HashiCorp brand prompted customers to use Terraform in production even before the general availability of version 1.0, which was announced in 2021. The tool has only improved with newer releases, by adding more features, such as HCP Terraform integration, moved blocks for code refactoring, support for Open Policy Agent (OPA), the ability to import manually created resources, testing frameworks, and so on, and integration with new partners.
Terraform can be used to provision and manage resources on any of the cloud platforms and SaaS offerings. Terraform already has thousands of partners integrated with it. Partners typically integrate with Terraform by creating a plugin that is downloaded by the customer along with the Terraform binary. There is a new set of partners who have products for code scanning, observability, cost management, security, and so on. If you want to support the automation of your product via Terraform, you can write your own custom provider plugin.
Procedural and declarative ways of coding are an important consideration in understanding IaC.
In the procedural style, the focus is on clearly defining the steps to achieve the desired end state. Ad hoc scripts and tools such as Ansible and Chef are all procedural language-based. In contrast, declarative style only requires you to outline the end state and the tool takes care of driving the workflow to this end. Terraform uses a declarative approach for infrastructure automation. Hence, the code is easier to write for a newbie.
When you run the same command/instruction multiple times and achieve the same result as you got the first time, the command/instruction is called idempotent. Terraform is idempotent. For example, if you have a Terraform file that creates an EC2 instance (a virtual machine in AWS) and you run it for the first time, it will create an EC2 instance. Running it a second or third time will not create additional instances as the desired state has already been achieved.
Terraform supports two formats to write and manage configuration files: JSON and HashiCorp Configuration Language (HCL).
JSON is typically used by systems for parsing but is tough for humans. In contrast, HCL is very easy to learn and implement even for someone with no programming background.
The Terraform code written for infrastructure management is managed using a source code management tool such as Git. This code is pushed to platforms such as GitHub, GitLab, and so on to keep it in a central location. Storing it centrally helps with team collaborations, rolling back to previous versions in case of issues with the latest version, and creating a pipeline for automated infrastructure deployment.
Manual provisioning of infrastructure is manageable for a simple use case. When you are dealing with the creation of thousands of resources, the manual method will cause delays and errors, and will also be expensive. Automation solves all these problems.
You may be tempted to do things manually, but anything that needs to be done more than once should be considered for automation. There is a one-time investment of time while you write the code that will then bring you the benefits of automation when you have to provision the same or similar resource multiple times.
Documentation is crucial to explain the current state of your architecture and resources, but it gets out of date quickly in the cloud world. When Terraform is used for full management of the infrastructure, the Terraform code itself can give you the latest state of the resource or the solution that is deployed. Please note that using Terraform does not take away the need for documentation but can help to reduce exhaustive documentation.
Terraform is widely used and supported by the community. Whenever cloud vendors add new features to existing products or launch new services, the community quickly adds them to Terraform and creates a merge request with the owners of the repo. Any bugs are also quickly detected and raised with the owners of the plugin for a fix.