Cyberithub

How to Install TFLint (Terraform Linter) on Linux

Advertisements

In this article, we will see how to install TFLint on Linux. TFLint or terraform linter is a free and open source tool that helps us checking the quality and potential errors in terraform code. It is also used for  checking the consistency and best practices which in turn helps us make our terraform code clean and sustainable. For advanced error detection, you can add plugins which are compatible with major cloud providers such as AWS, Azure and GCP. TFLint can be easily installed on all the famous platforms such as Linux, MacOS and Windows. Here we will see the steps to install TFLint on Linux based systems.

 

How to Install TFLint(Terraform Linter) on Linux

How to Install TFLint (Terraform Linter) on Linux

Also Read: How to Install Snap on Ubuntu 22.04

Advertisements

Step 1: Prerequisites

a) You should have a running Linux Server.

b) You should have sudo or root access to run privileged commands.

Advertisements

c) You should have curl utility installed in your Server.

 

Step 2: Update Your Server

Before installing TFLint, it is essential to check for all the latest available updates and install them on your Server. If you are using Ubuntu/Debian based systems then you can do that by running sudo apt update && sudo apt upgrade command.

Advertisements
sudo apt update && sudo apt upgrade

If you are using RHEL/CentOS based systems then you can install all the latest available updates by running either sudo yum update && sudo yum upgrade or sudo dnf update && sudo dnf upgrade command.

sudo yum update && sudo yum upgrade
sudo dnf update && sudo dnf upgrade

 

Step 3: Install TFLint

You have to visit GitHub website and get the latest available command to download and install TFLint on Linux based systems.

Advertisements
cyberithub@ubuntu:~$ curl -s https://raw.githubusercontent.com/terraform-linters/tflint/master/install_linux.sh | sudo bash
[sudo] password for cyberithub:
arch=amd64
os=linux_amd64


====================================================
Looking up the latest version ...
Downloading TFLint v0.48.0
Downloaded successfully


====================================================
Unpacking /tmp/tflint.AK3akeSKxH/tflint.zip ...
Archive: /tmp/tflint.AK3akeSKxH/tflint.zip
inflating: /tmp/tflint.AK3akeSKxH/tflint
Installing /tmp/tflint.AK3akeSKxH/tflint to /usr/local/bin/ ...
'/tmp/tflint.AK3akeSKxH/tflint' -> '/usr/local/bin/tflint'
Cleaning temporary downloaded files directory /tmp/tflint.AK3akeSKxH ...


====================================================
Current tflint version
TFLint version 0.48.0
+ ruleset.terraform (0.4.0-bundled)

 

Step 4: Check Version

After successful installation, you can check the current installed version by using tflint --version command as shown below.

cyberithub@ubuntu:~$ tflint --version
TFLint version 0.48.0
+ ruleset.terraform (0.4.0-bundled)

 

Step 5: Install Plugin

Since TFLint always look for .tflint.hcl file in the current directory where it is suppose to run so we will create this file and add below contents to install plugin for AWS and Azure cloud provider.

cyberithub@ubuntu:~$ nano .tflint.hcl
plugin "aws" {
  enabled = true
  version = "0.24.0"
  source = "github.com/terraform-linters/tflint-ruleset-aws"
}

plugin "azurerm" {
  enabled = true
  version = "0.24.0"
  source = "github.com/terraform-linters/tflint-ruleset-azurerm"
}

Then run tflint --init command to download and install the plugins as shown below.

cyberithub@ubuntu:~$ tflint --init
Installing `aws` plugin...
Installed `aws` (source: github.com/terraform-linters/tflint-ruleset-aws, version: 0.24.0)
Installing `azurerm` plugin...
Installed `azurerm` (source: github.com/terraform-linters/tflint-ruleset-azurerm, version: 0.24.0)

 

Step 6: Check all the available options

You can also check all the options available with tflint utility using tflint --help command as shown below.

cyberithub@ubuntu:~$ tflint --help
Usage:
tflint --chdir=DIR/--recursive [OPTIONS]

Application Options:
  -v, --version                                               Print TFLint version
      --init                                                  Install plugins
      --langserver                                            Start language server
  -f, --format=[default|json|checkstyle|junit|compact|sarif]  Output format
  -c, --config=FILE                                           Config file name (default: .tflint.hcl)
      --ignore-module=SOURCE                                  Ignore module sources
      --enable-rule=RULE_NAME                                 Enable rules from the command line
      --disable-rule=RULE_NAME                                Disable rules from the command line
      --only=RULE_NAME                                        Enable only this rule, disabling all other defaults. Can be specified multiple times
      --enable-plugin=PLUGIN_NAME                             Enable plugins from the command line
      --var-file=FILE                                         Terraform variable file name
      --var='foo=bar'                                         Set a Terraform variable
      --module                                                Enable module inspection
      --no-module                                             Disable module inspection
      --chdir=DIR                                             Switch to a different working directory before executing the command
      --recursive                                             Run command in each directory recursively
      --filter=FILE                                           Filter issues by file names or globs
      --force                                                 Return zero exit status even if issues found
      --minimum-failure-severity=[error|warning|notice]       Sets minimum severity level for exiting with a non-zero error code
      --color                                                 Enable colorized output
      --no-color                                              Disable colorized output
      --fix                                                   Fix issues automatically

Help Options:
-h, --help Show this help message

Leave a Comment