Find the Best Cosmetic Hospitals

Explore trusted cosmetic hospitals and make a confident choice for your transformation.

“Invest in yourself — your confidence is always worth it.”

Explore Cosmetic Hospitals

Start your journey today — compare options in one place.

Terraform Tutorials: TFLint, covering installation, configuration, usage

Comprehensive Guide to TFLint

Introduction to TFLint

TFLint is an open-source Terraform linter (static analysis tool) that checks Terraform configurations for errors, potential bugs, and stylistic or best-practice violations. It helps developers identify issues that Terraform’s built-in validation (terraform validate) might not catch, especially provider-specific problems like invalid AWS instance types or missing required Terraform versions.

Key Benefits of TFLint:

  • Early Error Detection – Catches issues before deployment, preventing costly failures.
  • Best Practice Enforcement – Ensures configurations align with Terraform and provider recommendations.
  • Security & Compliance Checks – Detects security risks like open security groups.
  • CI/CD Integration – Works in development workflows to maintain high-quality infrastructure as code (IaC).

Installation

TFLint is available for macOS, Linux, and Windows. You can install it using package managers or download the binary.

macOS (Homebrew):

brew install tflint

Linux:

curl -s https://raw.githubusercontent.com/terraform-linters/tflint/master/install_linux.sh | bash
Code language: JavaScript (javascript)

Alternatively, install it via Snap:

sudo snap install tflint

Windows (Chocolatey):

choco install tflint

Docker (Alternative):

docker run --rm -v $(pwd):/data -t ghcr.io/terraform-linters/tflint
Code language: JavaScript (javascript)

Verify Installation:

tflint --version

Basic Usage

TFLint is straightforward to use. Navigate to your Terraform project directory and run:

tflint

If using provider-specific rules, initialize plugins first:

tflint --init

Example Output:

1 issue(s) found:
Warning: terraform "required_version" attribute is required.


Code language: JavaScript (javascript)

Here is the normal table representation of the tflint --help options:

OptionDescription
-v, --versionPrint TFLint version
--initInstall plugins
--langserverStart language server
`-f, –format=[defaultjson
-c, --config=FILEConfig file name (default: .tflint.hcl)
--ignore-module=SOURCEIgnore module sources
--enable-rule=RULE_NAMEEnable rules from the command line
--disable-rule=RULE_NAMEDisable rules from the command line
--only=RULE_NAMEEnable only this rule, disabling all others (can be specified multiple times)
--enable-plugin=PLUGIN_NAMEEnable plugins from the command line
--var-file=FILETerraform variable file name
--var='foo=bar'Set a Terraform variable
`–call-module-type=[alllocal
--chdir=DIRSwitch to a different working directory before executing the command
--recursiveRun command in each directory recursively
--filter=FILEFilter issues by file names or globs
--forceReturn zero exit status even if issues are found
`–minimum-failure-severity=[errorwarning
--colorEnable colorized output
--no-colorDisable colorized output
--fixFix issues automatically
--no-parallel-runnersDisable per-runner parallelism
--max-workers=NSet maximum number of workers in recursive inspection (default: number of CPUs)
-h, --helpShow this help message

This table provides a clean and structured reference for TFLint command-line options. 🚀 Let me know if you need any modifications!

Configuration

TFLint can be customized using a .tflint.hcl configuration file.

Example .tflint.hcl Configuration:

tflint {
  required_version = ">= 0.50"
}

config {
  format = "compact"
  plugin_dir = "~/.tflint.d/plugins"
  call_module_type = "local"
}

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

rule "terraform_required_version" {
  enabled = false
}
Code language: JavaScript (javascript)

Rules and Plugins

TFLint has built-in Terraform language rules and provider-specific plugins.

Built-in Rules:

  • Required Terraform Version – Ensures required_version is defined.
  • Type Constraints – Checks explicit type constraints on variables.
  • Deprecated Syntax – Flags usage of removed Terraform features.
  • Unused Declarations – Identifies unused variables and outputs.

Provider Plugins:

  • AWS Plugin – Checks instance types, security group configurations, and more.
  • Azure Plugin – Validates Azure-specific configurations.
  • GCP Plugin – Ensures Google Cloud best practices.

Enabling a Plugin:

plugin "aws" {
  enabled = true
  version = "0.24.1"
  source  = "github.com/terraform-linters/tflint-ruleset-aws"
}
Code language: JavaScript (javascript)

Run:

tflint --init

CI/CD Integration

TFLint should be incorporated into CI/CD pipelines to enforce Terraform quality standards.

GitHub Actions Example:

jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: tflint --init
      - run: tflint

GitLab CI Example:

lint:terraform:
  image: terraform-linters/tflint:latest
  script:
    - tflint --init
    - tflint

Best Practices

  1. Run TFLint Early – Use it during development, not just in CI/CD.
  2. Customize Rules – Enable or disable rules in .tflint.hcl based on project needs.
  3. Use Provider Plugins – AWS, Azure, and GCP plugins catch cloud-specific issues.
  4. Inline Rule Ignoring – Use # tflint-ignore: rule_name for exceptions.
  5. Enforce in CI/CD – Make TFLint a required step before merging code.
  6. Keep TFLint Updated – Regularly update TFLint and its plugins.
  7. Combine with Other Tools – Use it alongside terraform fmt, terraform validate, and security scanners like tfsec.

Conclusion

TFLint is an essential tool for ensuring Terraform code quality, catching errors early, enforcing best practices, and integrating seamlessly into CI/CD workflows. Implement it in your Terraform projects to maintain consistent and error-free infrastructure as code.

Here’s a comprehensive tutorial for using TFLint, a powerful linter for Terraform code:

Installation

  1. Install TFLint using one of the following methods:
  • macOS: brew install tflint
  • Windows: choco install tflint
  • Linux: curl -s https://raw.githubusercontent.com/terraform-linters/tflint/master/install_linux.sh | bash13
  1. Verify the installation by running: texttflint --version

Setup and Configuration

  1. Navigate to your Terraform project directory.
  2. Create a .tflint.hcl configuration file in your project root: textplugin "terraform" { enabled = true preset = "recommended" }
  3. Initialize TFLint in your project: texttflint --init This command will download and install necessary plugins based on your configuration1.

Using TFLint

  1. Run TFLint in your project directory: texttflint This will scan your Terraform files and report any issues it finds1.
  2. For a more detailed report, use the JSON format: texttflint --format=json

Adding Cloud Provider Plugins

To lint configurations for specific cloud providers, add the relevant plugins to your .tflint.hcl file:

textplugin "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"
}

After adding plugins, run tflint --init again to download and install them2.

Advanced Usage

  1. To run TFLint recursively in subdirectories: texttflint --recursive
  2. To enable specific rules from the command line: texttflint --enable-rule=aws_resource_missing_tags
  3. To disable specific rules: texttflint --disable-rule=terraform_deprecated_syntax
  4. To use a custom configuration file: texttflint --config=custom_tflint.hcl

Integrating with CI/CD

For GitHub Actions, you can use the setup-tflint action:

text- uses: terraform-linters/setup-tflint@v3
  name: Setup TFLint
- run: tflint

Docker Usage

If you prefer using Docker, you can run TFLint without installation:

textdocker run --rm -v $(pwd):/data -t ghcr.io/terraform-linters/tflint

To download plugins and run TFLint in a single command:

textdocker run --rm -v $(pwd):/data -t --entrypoint /bin/sh ghcr.io/terraform-linters/tflint -c "tflint --init && tflint"

By following this tutorial, you’ll be able to effectively use TFLint to improve the quality and reliability of your Terraform code.

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals
I'm Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms. I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.

Related Posts

Team Foundation Server 2015 Installation Guide (SQL Express + Update 3)

Install Team Foundation Server 2015 using the original Microsoft download paths, with clear guidance for online, offline, and ISO-based setup. This revised guide also includes an installation workflow, command example, and practical pitfalls to avoid.

Read More

How to Access a Running Docker Container Shell: docker exec vs docker attach

Need a shell inside a running container that is already in detached mode? This updated guide shows the correct workflow, compares docker exec and docker attach, and explains when SSH does and does not make sense.

Read More

Host Your Own NuGet Feed: Local Source vs NuGet.Server vs NuGetGallery

Learn how to host a private NuGet feed using three practical approaches: a local folder source, NuGet.Server, and NuGetGallery. This revised guide includes setup steps, command examples, and a workflow diagram to help you choose the right model.

Read More

Publish NuGet Packages to NuGet.org: CLI Steps, Workflow, and CI Example

Learn how to publish a NuGet package to NuGet.org using either nuget.exe or the dotnet CLI. This revised guide includes a workflow diagram, command comparison, and a CI-friendly example.

Read More

How to Create NuGet Packages with nuget.exe (Assembly, .nuspec, and .csproj Methods)

Learn three practical ways to build NuGet packages using nuget.exe: from an existing assembly, from a convention-based folder layout, or directly from a Visual Studio project. This guide includes commands, folder conventions, token behavior, and common pitfalls.

Read More

Virtualization in DevOps: Using Vagrant, Docker, and Cloud Platforms Together

This guide explains how VM-based workflows, containers, and cloud platforms complement each other in DevOps. It includes a practical workflow, trade-off table, and command examples for day-to-day use.

Read More
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
0
Would love your thoughts, please comment.x
()
x