Skip to content

Commit

Permalink
Add --recursive option
Browse files Browse the repository at this point in the history
  • Loading branch information
wata727 committed Dec 18, 2022
1 parent d14a804 commit 24c32ad
Show file tree
Hide file tree
Showing 23 changed files with 463 additions and 112 deletions.
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

0 comments on commit 24c32ad

Please sign in to comment.