Must-Have Infrastructure as Code Tools
A small set of tools to make your Terraform coding journey smoother. Tools to Lint, visualize, document, and clean your Terraform HCL2 code.
Join the DZone community and get the full member experience.Join For Free
Here are some handy tools that made my Terraform coding journey smoother and should help your Terraform coding as well.
What Is Terraform?
For starters, Terraform is an infrastructure as a code (IaC) tool that helps you provision Cloud or On-premise resources through declarative configuration. Terraform uses HCL2 (Hashicorp Configuration Language).
HCL2 = HCL1 + HIL (Hashicorp Interpolation Language)
Check this GitHub repository to learn more about HIL.
Use Different Terraform Versions
If you are familiar with the Node.js world, different projects require different versions. So, I use
nvm(node version manager). Similarly, in our Terraform world, there are
tfenv to use different versions of Terraform for different projects or for testing your Terraform project with different versions of Terraform.
It helps to visualize your Terraform resources, modules, etc., to understand the flow and the connections.
I published an article that talks about various visualization tools associated with Terraform. It includes the inbuilt terraform graph.
Code Formatting, Code Navigation, Syntax Highlighting
You can always run Terraform commands to format and validate your HCL2 code like this:
Running these commands on a project with a complex folder structure becomes tiresome, as there can be multiple directories with *
- Visual Studio Code Extension to the rescue.
Hashicorp Terraform extension for Visual Studio Code
Terraform Language server is the official language server created and maintained by the creators of Terraform that provides IDE support.
Add support for the Terraform configuration language to editors that use the Language Server Protocol, like Sublime Text, vim, emacs, etc.
This is a Visual Studio Code extension. Adds syntax support for the Terraform and Terragrunt configuration language.
Terraform-docs generates documentation for Terraform modules in multiple formats. The tool lists modules, resources, inputs, outputs, providers, data resources, etc., The tool provides
--recursive flag to update submodules recursively.
Sample commands showing the
terraform-docs markdown . >>README.md
terraform-docs markdown table .
Check a sample markdown file generated using Terraform-docs. The Terraform is associated with this article.
As developers, we have a habit of forgetting things. Cleaning the code is one of the most important thing that we always forget. Terraform cleaner to the rescue.
Terraform Cleaner is a tool to detect Unused Variables and Locals in Your Modules. You can find the complete documentation in the article "Terraform Cleaner — A Tool to Detect Unused Variables and Locals in Your Modules."
terraform console command? How many times as developers would we have thought of evaluating a list of objects or any other expression without running
terraform plan or terraform apply commands? The
terraform console command helps you to evaluate and experiment with expressions on a terminal or command prompt. You can experiment with built-in terraform functions like slice, split, cat, etc., even before incorporating them into your HCL2 code.
Additionally, you can check other tools for security and compliance, validation, automation, etc., on the official Hashicorp documentation.
Also available are tools from the awesome-terraform GitHub repository.
Published at DZone with permission of Vidyasagar (Sarath Chandra) Machupalli, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.