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

Remove deprecated --module/--no-module and module attribute #2036

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 6 additions & 0 deletions cmd/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.52.0. Use --call-module-type=all instead")
}
if option == "no-module" {
return []string{}, errors.New("--no-module option was removed in v0.52.0. Use --call-module-type=none instead")
}
return []string{}, fmt.Errorf(`--%s is unknown option. Please run "tflint --help"`, option)
}

Expand Down
20 changes: 0 additions & 20 deletions cmd/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package cmd
import (
"fmt"
"log"
"os"
"strings"

"github.com/terraform-linters/tflint/terraform"
Expand All @@ -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"`
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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))
}
Expand Down
49 changes: 0 additions & 49 deletions cmd/option_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
14 changes: 14 additions & 0 deletions integrationtest/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.52.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.52.0. Use --call-module-type=none instead",
},
{
name: "invalid options",
command: "./tflint --unknown",
Expand Down
27 changes: 7 additions & 20 deletions tflint/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand All @@ -51,6 +50,9 @@ var innerConfigSchema = &hcl.BodySchema{
{Name: "disabled_by_default"},
{Name: "plugin_dir"},
{Name: "format"},

// Removed attributes
{Name: "module"},
},
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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.52.0. Use "call_module_type" instead`)

default:
panic("never happened")
}
Expand Down
41 changes: 13 additions & 28 deletions tflint/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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.52.0. Use "call_module_type" instead`
},
},
}

for _, test := range tests {
Expand Down
Loading