Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --recursive option #1622

Merged
merged 3 commits into from
Dec 20, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ Application Options:
--module Inspect modules
--chdir=DIR Switch to a different working directory before running inspection
--force Return zero exit status even if issues found
--recursive Inspect directories recursively
--color Enable colorized output
--no-color Disable colorized output

Expand All @@ -150,16 +151,6 @@ Help Options:

See [User Guide](docs/user-guide) for details.

## FAQ

### Does TFLint check modules recursively?
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.

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.

### Do I need to install Terraform for TFLint to work?
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).

## Debugging

If you don't get the expected behavior, you can see the detailed logs when running with `TFLINT_LOG` environment variable.
Expand Down
21 changes: 15 additions & 6 deletions cmd/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,25 @@ type CLI struct {
// outStream and errStream are the stdout and stderr
// to write message from the CLI.
outStream, errStream io.Writer
loader *terraform.Loader
formatter *formatter.Formatter
originalWorkingDir string
sources map[string][]byte

// fields for each module
config *tflint.Config
loader *terraform.Loader
formatter *formatter.Formatter
}

// NewCLI returns new CLI initialized by input streams
func NewCLI(outStream io.Writer, errStream io.Writer) *CLI {
func NewCLI(outStream io.Writer, errStream io.Writer) (*CLI, error) {
wd, err := os.Getwd()

return &CLI{
outStream: outStream,
errStream: errStream,
}
outStream: outStream,
errStream: errStream,
originalWorkingDir: wd,
sources: map[string][]byte{},
}, err
}

// Run invokes the CLI with the given arguments.
Expand Down
4 changes: 4 additions & 0 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ func (cli *CLI) init(opts Options) int {
fmt.Fprintf(cli.errStream, "Cannot use --chdir with --init\n")
return ExitCodeError
}
if opts.Recursive {
fmt.Fprintf(cli.errStream, "Cannot use --recursive with --init\n")
return ExitCodeError
}

cfg, err := tflint.LoadConfig(afero.Afero{Fs: afero.NewOsFs()}, opts.Config)
if err != nil {
Expand Down
Loading