Skip to content

Commit

Permalink
Remove terraform_version option
Browse files Browse the repository at this point in the history
  • Loading branch information
wata727 committed Jun 9, 2019
1 parent bb89f97 commit 669f7a1
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 137 deletions.
7 changes: 0 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ The config file is written in [HCL](https://github.com/hashicorp/hcl), and you c

```hcl
config {
terraform_version = "0.12.0"
deep_check = true
aws_credentials = {
Expand Down Expand Up @@ -288,12 +287,6 @@ If you want to inspect only a specific configuration file, not all files, you ca
$ tflint main.tf
```

### Terraform Version

You can set the version of Terraform you are using. If it is set, TFLint will detect issues according to it.

NOTE: This option is now no longer used and will be removed in the future.

## Debugging

If you don't get the expected behavior, you can see the detailed logs when running with `TFLINT_LOG` environment variable.
Expand Down
11 changes: 5 additions & 6 deletions cmd/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,10 @@ func (opts *Options) toConfig() *tflint.Config {
Profile: opts.AwsProfile,
Region: opts.AwsRegion,
},
IgnoreModule: ignoreModule,
IgnoreRule: ignoreRule,
Varfile: varfile,
Variables: opts.Variables,
TerraformVersion: "",
Rules: map[string]*tflint.RuleConfig{},
IgnoreModule: ignoreModule,
IgnoreRule: ignoreRule,
Varfile: varfile,
Variables: opts.Variables,
Rules: map[string]*tflint.RuleConfig{},
}
}
112 changes: 52 additions & 60 deletions cmd/option_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@ func Test_toConfig(t *testing.T) {
Name: "--deep",
Command: "./tflint --deep",
Expected: &tflint.Config{
DeepCheck: true,
AwsCredentials: client.AwsCredentials{},
IgnoreModule: map[string]bool{},
IgnoreRule: map[string]bool{},
Varfile: []string{},
Variables: []string{},
TerraformVersion: "",
Rules: map[string]*tflint.RuleConfig{},
DeepCheck: true,
AwsCredentials: client.AwsCredentials{},
IgnoreModule: map[string]bool{},
IgnoreRule: map[string]bool{},
Varfile: []string{},
Variables: []string{},
Rules: map[string]*tflint.RuleConfig{},
},
},
{
Expand All @@ -45,12 +44,11 @@ func Test_toConfig(t *testing.T) {
SecretKey: "AWS_SECRET_ACCESS_KEY",
Region: "us-east-1",
},
IgnoreModule: map[string]bool{},
IgnoreRule: map[string]bool{},
Varfile: []string{},
Variables: []string{},
TerraformVersion: "",
Rules: map[string]*tflint.RuleConfig{},
IgnoreModule: map[string]bool{},
IgnoreRule: map[string]bool{},
Varfile: []string{},
Variables: []string{},
Rules: map[string]*tflint.RuleConfig{},
},
},
{
Expand All @@ -62,82 +60,76 @@ func Test_toConfig(t *testing.T) {
Profile: "production",
Region: "us-east-1",
},
IgnoreModule: map[string]bool{},
IgnoreRule: map[string]bool{},
Varfile: []string{},
Variables: []string{},
TerraformVersion: "",
Rules: map[string]*tflint.RuleConfig{},
IgnoreModule: map[string]bool{},
IgnoreRule: map[string]bool{},
Varfile: []string{},
Variables: []string{},
Rules: map[string]*tflint.RuleConfig{},
},
},
{
Name: "--ignore-module",
Command: "./tflint --ignore-module module1,module2",
Expected: &tflint.Config{
DeepCheck: false,
AwsCredentials: client.AwsCredentials{},
IgnoreModule: map[string]bool{"module1": true, "module2": true},
IgnoreRule: map[string]bool{},
Varfile: []string{},
Variables: []string{},
TerraformVersion: "",
Rules: map[string]*tflint.RuleConfig{},
DeepCheck: false,
AwsCredentials: client.AwsCredentials{},
IgnoreModule: map[string]bool{"module1": true, "module2": true},
IgnoreRule: map[string]bool{},
Varfile: []string{},
Variables: []string{},
Rules: map[string]*tflint.RuleConfig{},
},
},
{
Name: "--ignore-rule",
Command: "./tflint --ignore-rule rule1,rule2",
Expected: &tflint.Config{
DeepCheck: false,
AwsCredentials: client.AwsCredentials{},
IgnoreModule: map[string]bool{},
IgnoreRule: map[string]bool{"rule1": true, "rule2": true},
Varfile: []string{},
Variables: []string{},
TerraformVersion: "",
Rules: map[string]*tflint.RuleConfig{},
DeepCheck: false,
AwsCredentials: client.AwsCredentials{},
IgnoreModule: map[string]bool{},
IgnoreRule: map[string]bool{"rule1": true, "rule2": true},
Varfile: []string{},
Variables: []string{},
Rules: map[string]*tflint.RuleConfig{},
},
},
{
Name: "--var-file",
Command: "./tflint --var-file example1.tfvars,example2.tfvars",
Expected: &tflint.Config{
DeepCheck: false,
AwsCredentials: client.AwsCredentials{},
IgnoreModule: map[string]bool{},
IgnoreRule: map[string]bool{},
Varfile: []string{"example1.tfvars", "example2.tfvars"},
Variables: []string{},
TerraformVersion: "",
Rules: map[string]*tflint.RuleConfig{},
DeepCheck: false,
AwsCredentials: client.AwsCredentials{},
IgnoreModule: map[string]bool{},
IgnoreRule: map[string]bool{},
Varfile: []string{"example1.tfvars", "example2.tfvars"},
Variables: []string{},
Rules: map[string]*tflint.RuleConfig{},
},
},
{
Name: "--var",
Command: "./tflint --var foo=bar --var bar=baz",
Expected: &tflint.Config{
DeepCheck: false,
AwsCredentials: client.AwsCredentials{},
IgnoreModule: map[string]bool{},
IgnoreRule: map[string]bool{},
Varfile: []string{},
Variables: []string{"foo=bar", "bar=baz"},
TerraformVersion: "",
Rules: map[string]*tflint.RuleConfig{},
DeepCheck: false,
AwsCredentials: client.AwsCredentials{},
IgnoreModule: map[string]bool{},
IgnoreRule: map[string]bool{},
Varfile: []string{},
Variables: []string{"foo=bar", "bar=baz"},
Rules: map[string]*tflint.RuleConfig{},
},
},
{
Name: "--fast",
Command: "./tflint --fast",
Expected: &tflint.Config{
DeepCheck: false,
AwsCredentials: client.AwsCredentials{},
IgnoreModule: map[string]bool{},
IgnoreRule: map[string]bool{"aws_instance_invalid_ami": true},
Varfile: []string{},
Variables: []string{},
TerraformVersion: "",
Rules: map[string]*tflint.RuleConfig{},
DeepCheck: false,
AwsCredentials: client.AwsCredentials{},
IgnoreModule: map[string]bool{},
IgnoreRule: map[string]bool{"aws_instance_invalid_ami": true},
Varfile: []string{},
Variables: []string{},
Rules: map[string]*tflint.RuleConfig{},
},
},
}
Expand Down
58 changes: 26 additions & 32 deletions tflint/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tflint

import (
"errors"
"fmt"
"log"
"os"
Expand Down Expand Up @@ -29,14 +30,13 @@ type rawConfig struct {

// Config describes the behavior of TFLint
type Config struct {
DeepCheck bool
AwsCredentials client.AwsCredentials
IgnoreModule map[string]bool
IgnoreRule map[string]bool
Varfile []string
Variables []string
TerraformVersion string
Rules map[string]*RuleConfig
DeepCheck bool
AwsCredentials client.AwsCredentials
IgnoreModule map[string]bool
IgnoreRule map[string]bool
Varfile []string
Variables []string
Rules map[string]*RuleConfig
}

// RuleConfig is a TFLint's rule config
Expand All @@ -49,14 +49,13 @@ type RuleConfig struct {
// It is mainly used for testing
func EmptyConfig() *Config {
return &Config{
DeepCheck: false,
AwsCredentials: client.AwsCredentials{},
IgnoreModule: map[string]bool{},
IgnoreRule: map[string]bool{},
Varfile: []string{},
Variables: []string{},
TerraformVersion: "",
Rules: map[string]*RuleConfig{},
DeepCheck: false,
AwsCredentials: client.AwsCredentials{},
IgnoreModule: map[string]bool{},
IgnoreRule: map[string]bool{},
Varfile: []string{},
Variables: []string{},
Rules: map[string]*RuleConfig{},
}
}

Expand Down Expand Up @@ -126,10 +125,6 @@ func (c *Config) Merge(other *Config) *Config {
ret.Varfile = append(ret.Varfile, other.Varfile...)
ret.Variables = append(ret.Variables, other.Variables...)

if other.TerraformVersion != "" {
ret.TerraformVersion = other.TerraformVersion
}

ret.Rules = mergeRuleMap(ret.Rules, other.Rules)

return ret
Expand Down Expand Up @@ -159,14 +154,13 @@ func (c *Config) copy() *Config {
}

return &Config{
DeepCheck: c.DeepCheck,
AwsCredentials: c.AwsCredentials,
IgnoreModule: ignoreModule,
IgnoreRule: ignoreRule,
Varfile: varfile,
Variables: variables,
TerraformVersion: c.TerraformVersion,
Rules: rules,
DeepCheck: c.DeepCheck,
AwsCredentials: c.AwsCredentials,
IgnoreModule: ignoreModule,
IgnoreRule: ignoreRule,
Varfile: varfile,
Variables: variables,
Rules: rules,
}
}

Expand All @@ -184,14 +178,17 @@ func loadConfigFromFile(file string) (*Config, error) {
return nil, diags
}

if raw.Config != nil && raw.Config.TerraformVersion != nil {
return nil, errors.New("`terraform_version` was removed in v0.9.0 because the option is no longer used")
}

cfg := raw.toConfig()
log.Printf("[DEBUG] Config loaded")
log.Printf("[DEBUG] DeepCheck: %t", cfg.DeepCheck)
log.Printf("[DEBUG] IgnoreModule: %#v", cfg.IgnoreModule)
log.Printf("[DEBUG] IgnoreRule: %#v", cfg.IgnoreRule)
log.Printf("[DEBUG] Varfile: %#v", cfg.Varfile)
log.Printf("[DEBUG] Variables: %#v", cfg.Variables)
log.Printf("[DEBUG] TerraformVersion: %s", cfg.TerraformVersion)
log.Printf("[DEBUG] Rules: %#v", cfg.Rules)

return raw.toConfig(), nil
Expand Down Expand Up @@ -246,9 +243,6 @@ func (raw *rawConfig) toConfig() *Config {
if rc.Variables != nil {
ret.Variables = *rc.Variables
}
if rc.TerraformVersion != nil {
ret.TerraformVersion = *rc.TerraformVersion
}
}

for _, r := range raw.Rules {
Expand Down
Loading

0 comments on commit 669f7a1

Please sign in to comment.