diff --git a/cmd/cli.go b/cmd/cli.go index 6151e9f41..4a72471f4 100644 --- a/cmd/cli.go +++ b/cmd/cli.go @@ -140,6 +140,12 @@ func unknownOptionHandler(option string, arg flags.SplitArgument, args []string) if option == "loglevel" { return []string{}, errors.New("--loglevel option was removed in v0.40.0. Please set TFLINT_LOG environment variables instead") } + if option == "module" { + return []string{}, errors.New("--module option was removed in v0.54.0. Use --call-module-type=all instead") + } + if option == "no-module" { + return []string{}, errors.New("--no-module option was removed in v0.54.0. Use --call-module-type=none instead") + } return []string{}, fmt.Errorf(`--%s is unknown option. Please run "tflint --help"`, option) } diff --git a/cmd/option.go b/cmd/option.go index 2ad4fb223..8c31edcbf 100644 --- a/cmd/option.go +++ b/cmd/option.go @@ -3,7 +3,6 @@ package cmd import ( "fmt" "log" - "os" "strings" "github.com/terraform-linters/tflint/terraform" @@ -24,8 +23,6 @@ type Options struct { EnablePlugins []string `long:"enable-plugin" description:"Enable plugins from the command line" value-name:"PLUGIN_NAME"` Varfiles []string `long:"var-file" description:"Terraform variable file name" value-name:"FILE"` Variables []string `long:"var" description:"Set a Terraform variable" value-name:"'foo=bar'"` - Module *bool `long:"module" description:"Enable module inspection" hidden:"true"` - NoModule *bool `long:"no-module" description:"Disable module inspection" hidden:"true"` CallModuleType *string `long:"call-module-type" description:"Types of module to call (default: local)" choice:"all" choice:"local" choice:"none"` Chdir string `long:"chdir" description:"Switch to a different working directory before executing the command" value-name:"DIR"` Recursive bool `long:"recursive" description:"Run command in each directory recursively"` @@ -61,17 +58,6 @@ func (opts *Options) toConfig() *tflint.Config { callModuleType := terraform.CallLocalModule callModuleTypeSet := false - // --call-module-type takes precedence over --module/--no-module. This is for backward compatibility. - if opts.Module != nil { - fmt.Fprintln(os.Stderr, "WARNING: --module is deprecated. Use --call-module-type=all instead.") - callModuleType = terraform.CallAllModule - callModuleTypeSet = true - } - if opts.NoModule != nil { - fmt.Fprintln(os.Stderr, "WARNING: --no-module is deprecated. Use --call-module-type=none instead.") - callModuleType = terraform.CallNoModule - callModuleTypeSet = true - } if opts.CallModuleType != nil { var err error callModuleType, err = terraform.AsCallModuleType(*opts.CallModuleType) @@ -192,12 +178,6 @@ func (opts *Options) toWorkerCommands(workingDir string) []string { for _, variable := range opts.Variables { commands = append(commands, fmt.Sprintf("--var=%s", variable)) } - if opts.Module != nil && *opts.Module { - commands = append(commands, "--module") - } - if opts.NoModule != nil && *opts.NoModule { - commands = append(commands, "--no-module") - } if opts.CallModuleType != nil { commands = append(commands, fmt.Sprintf("--call-module-type=%s", *opts.CallModuleType)) } diff --git a/cmd/option_test.go b/cmd/option_test.go index a6be55388..fdd2e4ec6 100644 --- a/cmd/option_test.go +++ b/cmd/option_test.go @@ -37,51 +37,6 @@ func Test_toConfig(t *testing.T) { Plugins: map[string]*tflint.PluginConfig{}, }, }, - { - Name: "--module", - Command: "./tflint --module", - Expected: &tflint.Config{ - CallModuleType: terraform.CallAllModule, - CallModuleTypeSet: true, - Force: false, - IgnoreModules: map[string]bool{}, - Varfiles: []string{}, - Variables: []string{}, - DisabledByDefault: false, - Rules: map[string]*tflint.RuleConfig{}, - Plugins: map[string]*tflint.PluginConfig{}, - }, - }, - { - Name: "--no-module", - Command: "./tflint --no-module", - Expected: &tflint.Config{ - CallModuleType: terraform.CallNoModule, - CallModuleTypeSet: true, - Force: false, - IgnoreModules: map[string]bool{}, - Varfiles: []string{}, - Variables: []string{}, - DisabledByDefault: false, - Rules: map[string]*tflint.RuleConfig{}, - Plugins: map[string]*tflint.PluginConfig{}, - }, - }, - { - Name: "--module and --call-module-type", - Command: "./tflint --module --call-module-type none", - Expected: &tflint.Config{ - CallModuleType: terraform.CallNoModule, - CallModuleTypeSet: true, - Force: false, - IgnoreModules: map[string]bool{}, - Varfiles: []string{}, - Variables: []string{}, - DisabledByDefault: false, - Rules: map[string]*tflint.RuleConfig{}, - Plugins: map[string]*tflint.PluginConfig{}, - }, - }, { Name: "--force", Command: "./tflint --force", @@ -340,8 +295,6 @@ func Test_toWorkerCommands(t *testing.T) { "--var-file=example2.tfvars", "--var=foo=bar", "--var=bar=baz", - "--module", - "--no-module", "--call-module-type=all", "--chdir=dir", "--recursive", @@ -378,8 +331,6 @@ func Test_toWorkerCommands(t *testing.T) { "--var-file=example2.tfvars", "--var=foo=bar", "--var=bar=baz", - "--module", - "--no-module", "--call-module-type=all", "--chdir=subdir", // "--chdir=dir", // "--recursive", diff --git a/integrationtest/cli/cli_test.go b/integrationtest/cli/cli_test.go index 1cff3633f..414dc550c 100644 --- a/integrationtest/cli/cli_test.go +++ b/integrationtest/cli/cli_test.go @@ -161,6 +161,20 @@ func TestIntegration(t *testing.T) { status: cmd.ExitCodeError, stderr: "--loglevel option was removed in v0.40.0. Please set TFLINT_LOG environment variables instead", }, + { + name: "removed --module option", + command: "./tflint --module", + dir: "no_issues", + status: cmd.ExitCodeError, + stderr: "--module option was removed in v0.54.0. Use --call-module-type=all instead", + }, + { + name: "removed --no-module option", + command: "./tflint --no-module", + dir: "no_issues", + status: cmd.ExitCodeError, + stderr: "--no-module option was removed in v0.54.0. Use --call-module-type=none instead", + }, { name: "invalid options", command: "./tflint --unknown", diff --git a/tflint/config.go b/tflint/config.go index c0462a37c..d627e15bd 100644 --- a/tflint/config.go +++ b/tflint/config.go @@ -42,7 +42,6 @@ var configSchema = &hcl.BodySchema{ var innerConfigSchema = &hcl.BodySchema{ Attributes: []hcl.AttributeSchema{ - {Name: "module"}, {Name: "call_module_type"}, {Name: "force"}, {Name: "ignore_module"}, @@ -51,6 +50,9 @@ var innerConfigSchema = &hcl.BodySchema{ {Name: "disabled_by_default"}, {Name: "plugin_dir"}, {Name: "format"}, + + // Removed attributes + {Name: "module"}, }, } @@ -249,25 +251,6 @@ func loadConfig(file afero.File) (*Config, error) { return config, err } - // "module" attribute is deprecated. Use "call_module_type" instead. - // This is for backward compatibility. - case "module": - fmt.Fprintf(os.Stderr, "WARNING: \"module\" attribute in %s is deprecated. Use \"call_module_type\" instead.\n", file.Name()) - if config.CallModuleTypeSet { - // If "call_module_type" is set, ignore "module" attribute - continue - } - var module bool - config.CallModuleTypeSet = true - if err := gohcl.DecodeExpression(attr.Expr, nil, &module); err != nil { - return config, err - } - if module { - config.CallModuleType = terraform.CallAllModule - } else { - config.CallModuleType = terraform.CallNoModule - } - case "force": config.ForceSet = true if err := gohcl.DecodeExpression(attr.Expr, nil, &config.Force); err != nil { @@ -317,6 +300,10 @@ func loadConfig(file afero.File) (*Config, error) { return config, fmt.Errorf("%s is invalid format. Allowed formats are: %s", config.Format, strings.Join(validFormats, ", ")) } + // Removed attributes + case "module": + return config, fmt.Errorf(`"module" attribute was removed in v0.54.0. Use "call_module_type" instead`) + default: panic("never happened") } diff --git a/tflint/config_test.go b/tflint/config_test.go index e4d40bb8c..3510435cc 100644 --- a/tflint/config_test.go +++ b/tflint/config_test.go @@ -417,34 +417,6 @@ config { }, errCheck: neverHappend, }, - { - name: "prefer call_module_type over module", - file: "config.hcl", - files: map[string]string{ - "config.hcl": ` -config { - call_module_type = "none" - module = true -}`, - }, - want: &Config{ - CallModuleType: terraform.CallNoModule, - CallModuleTypeSet: true, - Force: false, - IgnoreModules: map[string]bool{}, - Varfiles: []string{}, - Variables: []string{}, - DisabledByDefault: false, - Rules: map[string]*RuleConfig{}, - Plugins: map[string]*PluginConfig{ - "terraform": { - Name: "terraform", - Enabled: true, - }, - }, - }, - errCheck: neverHappend, - }, { name: "valid required_version", file: "config.hcl", @@ -487,6 +459,19 @@ tflint { return err == nil || err.Error() != `config.hcl:6,1-7: Multiple "tflint" blocks are not allowed; The "tflint" block is already found in config.hcl:2,1-7, but found the second one.` }, }, + { + name: "removed module attribute", + file: "config.hcl", + files: map[string]string{ + "config.hcl": ` +config { + module = true +}`, + }, + errCheck: func(err error) bool { + return err == nil || err.Error() != `"module" attribute was removed in v0.54.0. Use "call_module_type" instead` + }, + }, } for _, test := range tests {