Elevate Your Terraform Game: Helpful Tools for Linux Users"

Rob

Administrator
Staff member
Joined
Oct 27, 2011
Messages
1,219
Reaction score
2,262
Credits
3,555
As a popular infrastructure as code tool, Terraform has revolutionized the way software developers deploy and manage cloud resources. However, Terraform's command-line interface can be overwhelming for new users, and seasoned users may find themselves repeating the same tasks over and over again. Thankfully, there are a variety of tools available to make working with Terraform much easier. In this article, we'll explore some of the most popular tools for Terraform users, including tfswitch, Terragrunt, Atlantis, Sentinel, tflint, tfenv, and Terraform Landscape.

tfswitch
tfswitch is a tool that simplifies the process of managing multiple versions of Terraform. With tfswitch, you can quickly switch between different versions of Terraform for different projects. This makes it easy to ensure that your code is compatible with the version of Terraform you're using. Here's how to install tfswitch on Linux:

1. Download the latest binary for your architecture from the tfswitch releases page on GitHub. For example, if you're using a 64-bit Linux machine, you'll want to download the tfswitch_linux_amd64 binary.
2. Unarchive the tar.gz file:
tar zxvf terraform-switcher_0.13.1308_linux_amd64.tar.gz
3. Move the binary to your $PATH. For example, you could move it to /usr/local/bin with the following command:
sudo mv tfswitch /usr/local/bin/

Once you've installed tfswitch, you can use it to switch between different versions of Terraform. For example, if you want to switch to version 1.4.5, you can run the following command:
tfswitch 1.4.5
You can also list available versions by typing:
tfswitch -l

Terragrunt
Terragrunt is a thin wrapper for Terraform that provides extra functionality like locking state files and managing multiple environments. Terragrunt also makes it easy to reuse code across different Terraform projects. Here's how to install and use Terragrunt on Linux:

1. Download the latest Terragrunt binary for your architecture from the Terragrunt releases page on GitHub.
2. Move the binary to your $PATH. For example, you could move it to /usr/local/bin with the following command:
sudo mv terragrunt_linux_amd64 /usr/local/bin/
3. Make the binary executable:
sudo chmod +x /usr/local/bin/terragrunt_linux_amd64
4. Make a quick symlink to it for ease of use:
sudo ln -s /usr/local/bin/terragrunt_linux_amd64 /usr/local/bin/terragrunt

Once you've installed Terragrunt, you can use it to manage your Terraform projects. Terragrunt uses the same syntax as Terraform, so you can simply replace the terraform command with terragrunt to run Terraform commands with Terragrunt.

To use Terragrunt, you'll need to create a Terragrunt configuration file, which uses the HCL syntax. The Terragrunt configuration file specifies the location of your Terraform code and any additional settings you want to apply to your Terraform runs. Here's a basic example of a Terragrunt configuration file:

Code:
terragrunt = {
  include {
    path = "${find_in_parent_folders()}"
  }
}

terraform {
  source = "../modules/vpc"
}

In this example, the Terragrunt configuration file includes all files named terragrunt.hcl in the parent folders, and sets the Terraform source to a module located in a directory named 'modules/vpc' relative to the location of the Terragrunt configuration file.

Terragrunt supports a wide range of configuration options, including remote state management, environment variables, and multiple backend configurations. You can learn more about Terragrunt configuration options by reading the Terragrunt documentation.

Atlantis
Atlantis is a tool that allows for automated Terraform workflows, including automated pull request reviews and merging of Terraform code. Atlantis is particularly useful for teams that want to enforce best practices for Terraform code and ensure that changes are thoroughly reviewed before being applied. Here's how to install Atlantis on Linux:

1. Download the latest Atlantis binary for your architecture from the Atlantis releases page on GitHub.
2. Unzip the archive:
unzip atlantis_linux_amd64.zip
3. Move the binary to your $PATH. For example, you could move it to /usr/local/bin with the following command:
sudo mv atlantis /usr/local/bin/

Once you've installed Atlantis, you can use it to automate your Terraform workflows. Atlantis integrates with popular source code management tools like GitHub and GitLab, allowing you to trigger Terraform runs automatically when pull requests are opened or updated. Atlantis also provides a web interface for managing Terraform runs and reviewing changes, making it easy to collaborate with your team on Terraform projects.

Sentinel
Sentinel is a policy as code framework that lets you define and enforce policy rules for your Terraform code. Sentinel policies are written in the Sentinel language and can be used to ensure that your infrastructure code meets security and compliance requirements. Here's how to install Sentinel on Linux:

1. Download the latest Sentinel binary for your architecture from the Sentinel releases page on HashiCorp's website.
2. Unzip the archive:
unzip sentinel_0.21.0_linux_amd64.zip
3. Move the binary to your $PATH. For example, you could move it to /usr/local/bin with the following command:
sudo mv sentinel /usr/local/bin/

Once you've installed Sentinel, you can use it to write policy rules for your Terraform code. Sentinel has a variety of built-in policies, and you can also write your own policies to meet your specific needs. To enforce policies with Sentinel, you can integrate it with your Terraform workflow using the Sentinel CLI or the Sentinel Enterprise API.

tflint
tflint is a linter for Terraform code that checks for errors, best practices, and style violations. tflint can help you catch errors early in the development process and ensure that your Terraform code is easy to read and maintain. Here's how to install tflint on Linux:

1. Download the latest tflint binary for your architecture from the tflint releases page on GitHub.
2. Unzip the archive:
unzip tflint_linux_amd64.zip
3. Move the binary to your $PATH. For example, you could move it to /usr/local/bin with the following command:
sudo mv tflint /usr/local/bin/

Once you've installed tflint, you can use it to lint your Terraform code by running the tflint command in your Terraform project directory. tflint will check your code for errors and best practices and provide feedback on how to improve your code.

tfenv
tfenv is a tool that allows you to manage multiple versions of Terraform on your machine. Similar to tfswitch, tfenv lets you easily switch between different versions of Terraform for different projects. Here's how to install tfenv on Linux:

1. Clone the tfenv repository from GitHub:
git clone --depth=1 https://github.com/tfutils/tfenv.git ~/.tfenv
2. Add the tfenv bin directory to your $PATH. For example, you could add the following line to your .bashrc file:
export PATH="$HOME/.tfenv/bin:$PATH"
3. Reload your shell:
exec "$SHELL"

Once you've installed tfenv, you can use it to switch between different versions of Terraform. For example, if you want to switch to version 1.4.5, you can run the following command:
tfenv install 1.4.5
This will download and install the specified version of Terraform, and you can then use it in your project by running the terraform command.

Terraform Landscape
Terraform Landscape is a tool that provides a visual representation of your Terraform code, making it easier to understand and navigate. Terraform Landscape can help you identify patterns and potential issues in your code and make it easier to maintain over time. Here's how to install and use Terraform Landscape on Linux:

1. Install Terraform Landscape by running the following command:
gem install terraform_landscape
2. To generate a visual representation of your Terraform code, you can pipe the output of a Terraform plan command into the landscape command. For example:
terraform plan | landscape
This will output an ASCII art representation of your Terraform plan that you can view in your terminal.

Conclusion

I personally use tfswitch all of the time, the others i'm learning about now. These are some of the most popular tools for working with Terraform on Linux. Please let me know in the comments if you've used some of these and what you think about them. Also, what are some other tools that you use that may not have been included in the article?
 
Last edited:


Nice write up. My only experience so far with IaC is with AWS Cloudformation. They also have something called the CDK (cloud development kit) which basically lets you write IaC in typical programming languages.

What are you doing with Terraform project-wise or at work? Also what work role is typically writing these scripts where you work... ie: Sysadmins, developers, devops, etc?
 

Members online


Top