项目作者: terraform-linters

项目描述 :
A Pluggable Terraform Linter
高级语言: Go
项目地址: git://github.com/terraform-linters/tflint.git
创建时间: 2016-10-20T17:29:15Z
项目社区:https://github.com/terraform-linters/tflint

开源协议:Mozilla Public License 2.0

下载


TFLint

Build Status
GitHub release
Terraform Compatibility
License: MPL 2.0 + BUSL 1.1
Go Report Card
Homebrew

A Pluggable Terraform Linter

Features

TFLint is a framework and each feature is provided by plugins, the key features are as follows:

  • Find possible errors (like invalid instance types) for Major Cloud providers (AWS/Azure/GCP).
  • Warn about deprecated syntax, unused declarations.
  • Enforce best practices, naming conventions.

Installation

Bash script (Linux):

  1. curl -s https://raw.githubusercontent.com/terraform-linters/tflint/master/install_linux.sh | bash

Homebrew (macOS):

  1. brew install tflint

Chocolatey (Windows):

  1. choco install tflint

NOTE: The Chocolatey package is NOT directly maintained by the TFLint maintainers. The latest version is always available by manual installation.

Verification

Artifact Attestations are available that can be verified using the GitHub CLI.

  1. gh attestation verify checksums.txt -R terraform-linters/tflint
  2. sha256sum --ignore-missing -c checksums.txt

Cosign (Deprecated)

[!WARNING]
Cosign signatures are now deprecated. Please use GitHub CLI.

Cosign verify-blob command ensures that the release was built with GitHub Actions in this repository.

  1. cosign verify-blob --certificate=checksums.txt.pem --signature=checksums.txt.keyless.sig --certificate-identity-regexp="^https://github.com/terraform-linters/tflint" --certificate-oidc-issuer=https://token.actions.githubusercontent.com checksums.txt
  2. sha256sum --ignore-missing -c checksums.txt

Docker

Instead of installing directly, you can use the Docker image:

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

To download plugins, you can override the entrypoint to a shell (sh) to run --init and the main command in a single docker run command:

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

GitHub Actions

If you want to run on GitHub Actions, setup-tflint action is available.

Getting Started

First, enable rules for Terraform Language (e.g. warn about deprecated syntax, unused declarations). TFLint Ruleset for Terraform Language is bundled with TFLint, so you can use it without installing it separately.

The bundled plugin enables the “recommended” preset by default, but you can disable the plugin or use a different preset. Declare the plugin block in .tflint.hcl like this:

  1. plugin "terraform" {
  2. enabled = true
  3. preset = "recommended"
  4. }

See the tflint-ruleset-terraform documentation for more information.

Next, If you are using an AWS/Azure/GCP provider, it is a good idea to install the plugin and try it according to each usage:

If you want to extend TFLint with other plugins, you can declare the plugins in the config file and easily install them with tflint --init.

  1. plugin "foo" {
  2. enabled = true
  3. version = "0.1.0"
  4. source = "github.com/org/tflint-ruleset-foo"
  5. signing_key = <<-KEY
  6. -----BEGIN PGP PUBLIC KEY BLOCK-----
  7. mQINBFzpPOMBEADOat4P4z0jvXaYdhfy+UcGivb2XYgGSPQycTgeW1YuGLYdfrwz
  8. 9okJj9pMMWgt/HpW8WrJOLv7fGecFT3eIVGDOzyT8j2GIRJdXjv8ZbZIn1Q+1V72
  9. AkqlyThflWOZf8GFrOw+UAR1OASzR00EDxC9BqWtW5YZYfwFUQnmhxU+9Cd92e6i
  10. ...
  11. KEY
  12. }

See also Configuring Plugins.

You can discover plugins from other organizations on GitHub via the tflint-ruleset topic.

If you want to add custom rules that are not in existing plugins, you can build your own plugin or write your own policy in Rego. See Writing Plugins or OPA Ruleset.

Usage

TFLint inspects files under the current directory by default. You can change the behavior with the following options/arguments:

  1. $ tflint --help
  2. Usage:
  3. tflint --chdir=DIR/--recursive [OPTIONS]
  4. Application Options:
  5. -v, --version Print TFLint version
  6. --init Install plugins
  7. --langserver Start language server
  8. -f, --format=[default|json|checkstyle|junit|compact|sarif] Output format
  9. -c, --config=FILE Config file name (default: .tflint.hcl)
  10. --ignore-module=SOURCE Ignore module sources
  11. --enable-rule=RULE_NAME Enable rules from the command line
  12. --disable-rule=RULE_NAME Disable rules from the command line
  13. --only=RULE_NAME Enable only this rule, disabling all other defaults. Can be specified multiple times
  14. --enable-plugin=PLUGIN_NAME Enable plugins from the command line
  15. --var-file=FILE Terraform variable file name
  16. --var='foo=bar' Set a Terraform variable
  17. --call-module-type=[all|local|none] Types of module to call (default: local)
  18. --chdir=DIR Switch to a different working directory before executing the command
  19. --recursive Run command in each directory recursively
  20. --filter=FILE Filter issues by file names or globs
  21. --force Return zero exit status even if issues found
  22. --minimum-failure-severity=[error|warning|notice] Sets minimum severity level for exiting with a non-zero error code
  23. --color Enable colorized output
  24. --no-color Disable colorized output
  25. --fix Fix issues automatically
  26. --no-parallel-runners Disable per-runner parallelism
  27. --max-workers=N Set maximum number of workers in recursive inspection (default: number of CPUs)
  28. Help Options:
  29. -h, --help Show this help message

See User Guide for details.

Debugging

If you don’t get the expected behavior, you can see the detailed logs when running with TFLINT_LOG environment variable.

  1. $ TFLINT_LOG=debug tflint

Developing

See Developer Guide.

Security

If you find a security vulnerability, please refer our security policy.

License

Please note that although much of this project is licensed under MPL 2.0, some files in the terraform package are licensed under BUSL 1.1.

For the reasons stated above, the executable forms (release binaries) is bound by both licenses.

See also https://discuss.hashicorp.com/t/hashicorp-projects-changing-license-to-business-source-license-v1-1/57106/7

Stargazers over time

Stargazers over time