Terraform Explained

Terraform is an Infrastructure-as-Code (IaC) service that enables you to provision resources using code, meaning you can thoroughly and efficiently configure deployments and environments using code.

Infrastructure-as-Code made easy

Terraform allows you to edit, update, and version your infrastructure through code. Having your infrastructure deployed through the code, enables you to repeat deployments and solutions using that same code in the future. This allows you not only to have repeatable IPs, but also disposable deployments, which will be covered in more detail in later sections.

Terraform has been compared to AWS CloudFormation, which is an AWS service that allows you to use code to provision, update and version resources on your AWS cloud infrastructure. Terraform is a AWS Partner Network (APN) Advanced Technology Partner, and is known for choosing AWS cloud as their preferred cloud infrastructure.

 

Terraform is a product of Hashicorp, it is Hashicorp’s IaC tool. Manually defining your resources and infrastructure through code comes with many benefits, that include things like the ability to manage infrastructures across multiple cloud platforms, a configuration language that is easy to read and write in and the ability to track, version and collaborate on your configuration.

Compatibility and platform affinity are great benefits that come with using Terraform, considering Terraform utilizes Application Programming Interfaces (API) in order to interact and integrate with many different platforms and services.
The link below will show the extended list of provider APIs that Terraform supports:
https://registry.terraform.io/browse/providers

 

Variables

Terraform utilizes variables to make provisioning and defining resources easier, while also making the overall code cleaner and more efficient to use. Terraform variables are written using its own JSON-type syntax known as HCl (Hashicorp language), additionally Terraform still has support for JSON.

Terraform makes use of input and output variables, and these can be seen as function arguments and function return values respectively. With variables you are able to reference different modules or pieces of code from areas in your configuration, making it easier to make changes and edits to the configuration.

 

Modules

Modules are used for grouping your code and your Terraform configuration files in a more logical and tidy manner, giving your configuration more structure and allowing you to re-use certain modules in other projects. Terraform is able to use output variables to reference certain modules in your configuration, this removes the complications that come with having endless lines of code. By doing this, your code becomes compartmentalized and structured in a way that makes more complex architectures much simpler to work on and understand.

Terraform will only run files ending in .tf, meaning your modules won’t be affected,  considering they will be kept in their own subdirectories. This means that your code can be broken down into smaller chunks to serve the larger configuration and deployment plan, and through using variables to make changes to the main .tf file you can control which modules are being referenced and used in the deployment. 

 

Commands

Terraform has many commands to make the deployment of your environment more efficient, while greatly reducing any room for error. 

Some of the main commands for the Terraform CLI would include:

 

  •   Init Prepare your working directory for other commands
  •   Validate Check whether the configuration is valid
  •   Plan Show changes required by the current configuration
  •   Apply Create or update infrastructure
  •   Destroy Destroy previously-created infrastructure

For a more in-depth look at the commands refer to:
https://www.terraform.io/cli/commands

When using the Terraform CLI you can always use the -help command for assistance, but you can also use the -help command after another command to find out more about that specific command. Example: terraform init -help

 

Multi-tier Applications

Multi-tier Architectures are becoming more and more prevalent in the current technological landscape we see ourselves in today. Terraform works very well with multi-tier architectures, as it understands the dependencies and the priorities of different resources in different infrastructures. A simple example of this would be when it is creating resources it will know to create the subnets before creating any web servers, and to link those web servers to the corresponding web nodes. This ability to realize dependencies extends to all the different dependencies of the different platforms supported by Terraform.

Terraform can also make testing your production environment easier. By sharing the production environment’s configuration code with something like a “development” or “testing environment”, you are able to quickly spin up a testing environment that is up to date with the production environment. Then once any testing is completed you can simply destroy that testing environment, this makes these configurations reusable and disposable at the same time.

 

Collaboration

When using Terraform Cloud, which is free for up to five users, you can share your state with other users in your team. With Terraform’s remote state backends, it allows you to collaborate with your teammates in a stable environment that enables multiple users to work on the same configurations. Additionally you can connect Terraform with different version control systems (VCSs), such as GitHub, giving you version control that helps prevent any overwrites or deletes to the configuration.  

Contact CloudZA to discuss how we can assist you in modernizing you infrastructure deployments with Terraform.

Related Articles

Benefits of a Hybrid Cloud solution

Benefits of a Hybrid Cloud solution

Hybrid cloud solutions allows organizations to benefit from the security advantages of your on-premise environment as well as the flexibility of the public cloud.  Hybrid Cloud - The best pathway to becoming Cloud-Native Many companies have the goal of becoming...

CloudZA partnership with 3CX

CloudZA partnership with 3CX

CloudZA are now official partners with 3CX. By being partnered with 3CX, CloudZA is able to modernize your business communication system with a PBX that was designed with the remote workforce in mind.

Storing Data with Amazon S3

Storing Data with Amazon S3

Amazon Simple Storage Service (Amazon S3) is one of the best object storage solutions in the industry at the moment. It offers a plethora of different S3 Storage Classes to choose from, and each one serves a different purpose that is generally based on the frequency...