Skip to content

Commit f6bc263

Browse files
authored
Revise documentation (#1025)
1 parent 82c66b0 commit f6bc263

30 files changed

+321
-999
lines changed

Diff for: README.md

+30-74
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,65 @@
11
# TFLint
22
[![Build Status](https://github.com/terraform-linters/tflint/workflows/build/badge.svg?branch=master)](https://github.com/terraform-linters/tflint/actions)
33
[![GitHub release](https://img.shields.io/github/release/terraform-linters/tflint.svg)](https://github.com/terraform-linters/tflint/releases/latest)
4-
[![Terraform Compatibility](https://img.shields.io/badge/terraform-%3E%3D%200.12-blue)](docs/guides/compatibility.md)
4+
[![Terraform Compatibility](https://img.shields.io/badge/terraform-%3E%3D%200.12-blue)](docs/user-guide/compatibility.md)
55
[![Docker Hub](https://img.shields.io/badge/docker-ready-blue.svg)](https://hub.docker.com/r/wata727/tflint/)
66
[![License: MPL 2.0](https://img.shields.io/badge/License-MPL%202.0-blue.svg)](LICENSE)
77
[![Go Report Card](https://goreportcard.com/badge/github.com/terraform-linters/tflint)](https://goreportcard.com/report/github.com/terraform-linters/tflint)
88
[![Homebrew](https://img.shields.io/badge/dynamic/json.svg?url=https://formulae.brew.sh/api/formula/tflint.json&query=$.versions.stable&label=homebrew)](https://formulae.brew.sh/formula/tflint)
99

10-
TFLint is a [Terraform](https://www.terraform.io/) linter focused on possible errors, best practices, etc.
10+
A Pluggable [Terraform](https://www.terraform.io/) Linter
1111

12-
## Why TFLint is required?
13-
14-
Terraform is a great tool for Infrastructure as Code. However, many of these tools don't validate provider-specific issues. For example, see the following configuration file:
15-
16-
```hcl
17-
resource "aws_instance" "foo" {
18-
ami = "ami-0ff8a91507f77f867"
19-
instance_type = "t1.2xlarge" # invalid type!
20-
}
21-
```
22-
23-
Since `t1.2xlarge` is a nonexistent instance type, an error will occur when you run `terraform apply`. But `terraform plan` and `terraform validate` cannot find this possible error beforehand. That's because it's an AWS provider-specific issue and it's valid as a Terraform configuration.
12+
## Features
2413

25-
TFLint finds such errors in advance:
14+
TFLint is a framework and each feature is provided by plugins, the key features are as follows:
2615

27-
![demo](docs/assets/demo.gif)
16+
- Find possible errors (like illegal instance types) for Major Cloud providers (AWS/Azure/GCP).
17+
- Warn about deprecated syntax, unused declarations.
18+
- Enforce best practices, naming conventions.
2819

2920
## Installation
3021

31-
You can download the binary built for your architecture from [the latest release](https://github.com/terraform-linters/tflint/releases/latest). The following is an example of installation on macOS:
22+
Bash script (Linux):
3223

3324
```console
34-
$ curl --location https://github.com/terraform-linters/tflint/releases/download/v0.22.0/tflint_darwin_amd64.zip --output tflint_darwin_amd64.zip
35-
$ unzip tflint_darwin_amd64.zip
36-
Archive: tflint_darwin_amd64.zip
37-
inflating: tflint
38-
$ install tflint /usr/local/bin
39-
$ tflint -v
25+
$ curl https://raw.githubusercontent.com/terraform-linters/tflint/master/install_linux.sh | bash
4026
```
4127

42-
For Linux based OS, you can use the [`install_linux.sh`](https://raw.githubusercontent.com/terraform-linters/tflint/master/install_linux.sh) to automate the installation process, or try the following oneliner to download latest binary for AMD64 architecture.
43-
```
44-
$ curl -L "$(curl -Ls https://api.github.com/repos/terraform-linters/tflint/releases/latest | grep -o -E "https://.+?_linux_amd64.zip")" -o tflint.zip && unzip tflint.zip && rm tflint.zip
45-
```
46-
47-
### Homebrew
48-
49-
macOS users can also use [Homebrew](https://brew.sh) to install TFLint:
28+
Homebrew (macOS):
5029

5130
```console
5231
$ brew install tflint
5332
```
5433

55-
### Chocolatey
56-
57-
Windows users can use [Chocolatey](https://chocolatey.org):
34+
Chocolatey (Windows):
5835

5936
```cmd
6037
choco install tflint
6138
```
6239

63-
### Docker
64-
65-
You can also use [TFLint via Docker](https://hub.docker.com/r/wata727/tflint/).
40+
Docker:
6641

6742
```console
6843
$ docker run --rm -v $(pwd):/data -t wata727/tflint
6944
```
7045

71-
## Features
72-
73-
700+ rules are available. See [Rules](docs/rules).
74-
75-
## Providers
76-
77-
TFLint supports multiple providers via plugins. The following is the Major Cloud support status.
46+
Please note that this Docker image is not suitable for production CI/CD pipelines.
7847

79-
|name|status|description|
80-
|---|---|---|
81-
|[AWS](https://github.com/terraform-linters/tflint-ruleset-aws)|Available|Inspections for AWS resources are now built into TFLint. So, it is not necessary to install the plugin separately. In the future, these will be cut out to the plugin, but all are in progress.|
82-
|[Azure](https://github.com/terraform-linters/tflint-ruleset-azurerm)|Experimental|Experimental support has been started. You can inspect Azure resources by installing the plugin.|
83-
|[Google Cloud Platform](https://github.com/terraform-linters/tflint-ruleset-google)|Experimental|Experimental support has been started. You can inspect GCP resources by installing the plugin.|
48+
## Getting Started
8449

85-
Please see the [documentation](docs/guides/extend.md) about the plugin system.
50+
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:
8651

87-
## Limitations
52+
- [Amazon Web Services](https://github.com/terraform-linters/tflint-ruleset-aws)
53+
- [Microsoft Azure](https://github.com/terraform-linters/tflint-ruleset-azurerm)
54+
- [Google Cloud Platform](https://github.com/terraform-linters/tflint-ruleset-google)
8855

89-
TFLint load configurations in the same way as Terraform v0.13. This means that it cannot inspect configurations that cannot be parsed on Terraform v0.13.
56+
For AWS users, you can use the bundled plugin built into the TFLint binary without installing the plugin separately for backward compatibility.
9057

91-
See [Compatibility with Terraform](docs/guides/compatibility.md) for details.
58+
Rules for the Terraform Language is built into the TFLint binary, so you don't need to install any plugins. Please see [Rules](docs/rules) for a list of available rules.
9259

9360
## Usage
9461

95-
TFLint inspects all configurations under the current directory by default. You can also change the behavior with the following options:
62+
TFLint inspects files under the current directory by default. You can change the behavior with the following options/arguments:
9663

9764
```
9865
$ tflint --help
@@ -111,12 +78,6 @@ Application Options:
11178
--var-file=FILE Terraform variable file name
11279
--var='foo=bar' Set a Terraform variable
11380
--module Inspect modules
114-
--deep Enable deep check mode
115-
--aws-access-key=ACCESS_KEY AWS access key used in deep check mode
116-
--aws-secret-key=SECRET_KEY AWS secret key used in deep check mode
117-
--aws-profile=PROFILE AWS shared credential profile name used in deep check mode
118-
--aws-creds-file=FILE AWS shared credentials file path used in deep checking
119-
--aws-region=REGION AWS region used in deep check mode
12081
--force Return zero exit status even if issues found
12182
--no-color Disable colorized output
12283
--loglevel=[trace|debug|info|warn|error] Change the loglevel (default: none)
@@ -125,25 +86,20 @@ Help Options:
12586
-h, --help Show this help message
12687
```
12788

128-
See [User guide](docs/guides) for each option.
129-
130-
## Exit Statuses
131-
132-
TFLint returns the following exit statuses on exit:
133-
134-
- 0: No issues found
135-
- 2: Errors occurred
136-
- 3: No errors occurred, but issues found
89+
See [User Guide](docs/user-guide) for details.
13790

13891
## FAQ
92+
13993
### Does TFLint check modules recursively?
140-
- No. TFLint always checks only the current root module (no recursive check)
94+
No. TFLint always checks only the current root module (no recursive check). However, you can check calling child modules based on module arguments by enabling [Module Inspection](docs/user-guide/module-inspection.md). This allows you to check that you are not passing illegal values to the module.
95+
96+
Note that if you want to recursively inspect local modules, you need to run them in each directory. This is a limitation that occurs because Terraform always works for one directory. TFLint tries to emulate Terraform's semantics, so cannot perform recursive inspection.
14197

14298
### Do I need to install Terraform for TFLint to work?
143-
- No. TFLint works as a single binary because Terraform is embedded as a library. Note that this means that the version of Terraform used is determined for each TFLint version. See also [Compatibility with Terraform](docs/guides/compatibility.md).
99+
No. TFLint works as a single binary because Terraform is embedded as a library. Note that this means that the version of Terraform used is determined for each TFLint version. See also [Compatibility with Terraform](docs/user-guide/compatibility.md).
144100

145-
### TFLint causes a loading error in my code that is valid in Terraform. Why?
146-
- First, check the version of Terraform you are using. Terraform v0.12 introduced a major syntax change, and unfortunately TFLint only supports that new syntax.
101+
### TFLint reports a loading error in my code, but this is valid in Terraform. Why?
102+
First, check the version of Terraform and TFLint you are using. TFLint loads files differently than the installed Terraform, so an error can occur if the version of Terraform supported by TFLint is different from the installed Terraform.
147103

148104
## Debugging
149105

@@ -155,4 +111,4 @@ $ TFLINT_LOG=debug tflint
155111

156112
## Developing
157113

158-
See [Developer guide](docs/DEVELOPING.md).
114+
See [Developer Guide](docs/developer-guide).

Diff for: docs/DEVELOPING.md

-111
This file was deleted.

Diff for: docs/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# TFLint Documentation
22

3-
- [User guide](guides)
3+
- [User Guide](user-guide)
44
- [Rules](rules)
5-
- [Developer guide](DEVELOPING.md)
5+
- [Developer Guide](developer-guide)

Diff for: docs/assets/architecture.png

33.3 KB
Loading

Diff for: docs/assets/demo.gif

-281 KB
Binary file not shown.

Diff for: docs/developer-guide/README.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# TFLint Developer Guide
2+
3+
The goal of this guide is to quickly understand how TFLint works and to help more developers contribute.
4+
5+
## Table of Contents
6+
7+
- [Core Concept](core-concept.md)
8+
- [Architecture](architecture.md)
9+
- [Building TFLint](building.md)
10+
- [Writing Plugins](plugins.md)

Diff for: docs/developer-guide/architecture.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Architecture
2+
3+
![architecture](../assets/architecture.png)
4+
5+
TFLint rules are provided by plugins. The plugin is launched as another process and communicates over RPC. Inspection requests and configuration file fetching, expression evaluation, etc. are performed by bi-directional communication, and the host process and plugin process act as both a server and a client.
6+
7+
The plugin system is implemented by [go-plugin](https://github.com/hashicorp/go-plugin). Since it uses a `net/rpc` based implementation, it uses [hashicorp/yamux](https://github.com/hashicorp/yamux) for communication multiplexing. See also [the go-plugin architecture description](https://github.com/hashicorp/go-plugin#architecture).

Diff for: docs/developer-guide/building.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Building TFLint
2+
3+
Go 1.15 or higher is required to build TFLint from source code. Clone the source code and run the `make` command. Built binary will be placed in `dist` directory.
4+
5+
```console
6+
$ git clone https://github.com/terraform-linters/tflint.git
7+
$ cd tflint
8+
$ make
9+
mkdir -p dist
10+
go build -v -o dist/tflint
11+
```
12+
13+
## Run tests
14+
15+
If you change code, make sure that the tests you add and existing tests will be passed:
16+
17+
```console
18+
$ make test
19+
```
20+
21+
## Run E2E tests
22+
23+
You can check the actual CLI behavior by running the E2E tests. Since the E2E tests uses the installed `tflint` command, it is necessary to add the path into `$PATH` environment so that the binary built by `go install` can be referenced.
24+
25+
```console
26+
$ make e2e
27+
```

Diff for: docs/developer-guide/core-concept.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Core Concept
2+
3+
TFLint is just a thin wrapper of Terraform. Configuration loading and expression evaluation etc. depend on Terraform's internal API, and it only provides an interface to do them as a linter.
4+
5+
Rules are provided by plugins except some rules. Technically, the plugin is launched as another process, communicates via RPC, and receives inspection results from the plugin process.
6+
7+
There are important packages to understand its behavior:
8+
9+
- `tflint`
10+
- This package is the core of TFLint as a wrapper for Terraform. It allows accesses to `terraform/configs.Config` and `terraform/terraform.BuiltinEvalContext` and so on.
11+
- `plugin`
12+
- This package provides the TFLint plugin system. Includes plugin discovery, a server implementation responding to requests from plugins.
13+
- `cmd`
14+
- This package is the entrypoint of the app.

Diff for: docs/developer-guide/plugins.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Writing Plugins
2+
3+
If you want to add or change rules, you need to write plugins. When changing plugins, refer to the repository of each plugin and refer to how to build and install.
4+
5+
If you want to create a new plugin, please refer to [tflint-ruleset-template](https://github.com/terraform-linters/tflint-ruleset-template). The plugin can use [tflint-plugin-sdk](https://github.com/terraform-linters/tflint-plugin-sdk) to communicate with the host process. You can easily create a new repository from "Use this template".

0 commit comments

Comments
 (0)