From 0cc19e2068b9b41e594ed0659319ed03a0f7b5b7 Mon Sep 17 00:00:00 2001 From: Andrew Peabody Date: Tue, 13 Aug 2024 14:14:56 -0700 Subject: [PATCH] fix(tflint): rename plugin (#2516) --- ...go => terraform_required_version_range.go} | 36 +++++++++--------- .../terraform_required_version_range_test.go | 38 +++++++++++++++++++ .../rules/terraform_required_version_test.go | 38 ------------------- .../.expected/issues.json | 0 .../multiple-invalid-config}/.tflint.hcl | 2 +- .../multiple-invalid-config/main.tf | 0 .../multiple-invalid/.expected/issues.json | 0 .../multiple-invalid/main.tf | 0 .../.expected/issues.json | 0 .../multiple-valid-config-single/.tflint.hcl | 2 +- .../multiple-valid-config-single/main.tf | 0 .../.expected/issues.json | 0 .../multiple-valid-config}/.tflint.hcl | 2 +- .../multiple-valid-config/main.tf | 0 .../multiple-valid/.expected/issues.json | 0 .../multiple-valid/main.tf | 0 16 files changed, 59 insertions(+), 59 deletions(-) rename tflint-ruleset-blueprint/rules/{terraform_required_version.go => terraform_required_version_range.go} (77%) create mode 100644 tflint-ruleset-blueprint/rules/terraform_required_version_range_test.go delete mode 100644 tflint-ruleset-blueprint/rules/terraform_required_version_test.go rename tflint-ruleset-blueprint/rules/testdata/{terraform_required_version => terraform_required_version_range}/multiple-invalid-config/.expected/issues.json (100%) rename tflint-ruleset-blueprint/rules/testdata/{terraform_required_version/multiple-valid-config => terraform_required_version_range/multiple-invalid-config}/.tflint.hcl (61%) rename tflint-ruleset-blueprint/rules/testdata/{terraform_required_version => terraform_required_version_range}/multiple-invalid-config/main.tf (100%) rename tflint-ruleset-blueprint/rules/testdata/{terraform_required_version => terraform_required_version_range}/multiple-invalid/.expected/issues.json (100%) rename tflint-ruleset-blueprint/rules/testdata/{terraform_required_version => terraform_required_version_range}/multiple-invalid/main.tf (100%) rename tflint-ruleset-blueprint/rules/testdata/{terraform_required_version => terraform_required_version_range}/multiple-valid-config-single/.expected/issues.json (100%) rename tflint-ruleset-blueprint/rules/testdata/{terraform_required_version => terraform_required_version_range}/multiple-valid-config-single/.tflint.hcl (51%) rename tflint-ruleset-blueprint/rules/testdata/{terraform_required_version => terraform_required_version_range}/multiple-valid-config-single/main.tf (100%) rename tflint-ruleset-blueprint/rules/testdata/{terraform_required_version => terraform_required_version_range}/multiple-valid-config/.expected/issues.json (100%) rename tflint-ruleset-blueprint/rules/testdata/{terraform_required_version/multiple-invalid-config => terraform_required_version_range/multiple-valid-config}/.tflint.hcl (61%) rename tflint-ruleset-blueprint/rules/testdata/{terraform_required_version => terraform_required_version_range}/multiple-valid-config/main.tf (100%) rename tflint-ruleset-blueprint/rules/testdata/{terraform_required_version => terraform_required_version_range}/multiple-valid/.expected/issues.json (100%) rename tflint-ruleset-blueprint/rules/testdata/{terraform_required_version => terraform_required_version_range}/multiple-valid/main.tf (100%) diff --git a/tflint-ruleset-blueprint/rules/terraform_required_version.go b/tflint-ruleset-blueprint/rules/terraform_required_version_range.go similarity index 77% rename from tflint-ruleset-blueprint/rules/terraform_required_version.go rename to tflint-ruleset-blueprint/rules/terraform_required_version_range.go index 4c8572209f7..8f28d485c8b 100644 --- a/tflint-ruleset-blueprint/rules/terraform_required_version.go +++ b/tflint-ruleset-blueprint/rules/terraform_required_version_range.go @@ -12,55 +12,55 @@ import ( "github.com/terraform-linters/tflint-plugin-sdk/tflint" ) -// TerraformRequiredVersion checks if a module has a terraform required_version within valid range. -type TerraformRequiredVersion struct { +// TerraformRequiredVersionRange checks if a module has a terraform required_version within valid range. +type TerraformRequiredVersionRange struct { tflint.DefaultRule } -// TerraformRequiredVersionConfig is a config of TerraformRequiredVersion -type TerraformRequiredVersionConfig struct { +// TerraformRequiredVersionRangeConfig is a config of TerraformRequiredVersionRange +type TerraformRequiredVersionRangeConfig struct { MinVersion string `hclext:"min_version,optional"` MaxVersion string `hclext:"max_version,optional"` } -// NewTerraformRequiredVersion returns a new rule. -func NewTerraformRequiredVersion() *TerraformRequiredVersion { - return &TerraformRequiredVersion{} +// NewTerraformRequiredVersionRange returns a new rule. +func NewTerraformRequiredVersionRange() *TerraformRequiredVersionRange { + return &TerraformRequiredVersionRange{} } // Name returns the rule name. -func (r *TerraformRequiredVersion) Name() string { - return "terraform_required_version" +func (r *TerraformRequiredVersionRange) Name() string { + return "terraform_required_version_range" } // Enabled returns whether the rule is enabled by default. -func (r *TerraformRequiredVersion) Enabled() bool { +func (r *TerraformRequiredVersionRange) Enabled() bool { return false } // Severity returns the rule severity. -func (r *TerraformRequiredVersion) Severity() tflint.Severity { +func (r *TerraformRequiredVersionRange) Severity() tflint.Severity { return tflint.ERROR } // Link returns the rule reference link -func (r *TerraformRequiredVersion) Link() string { +func (r *TerraformRequiredVersionRange) Link() string { return "https://googlecloudplatform.github.io/samples-style-guide/#language-specific" } const ( - minimumTerraformRequiredVersion = "1.3" - maximumTerraformRequiredVersion = "1.5" + minimumTerraformRequiredVersionRange = "1.3" + maximumTerraformRequiredVersionRange = "1.5" ) // Checks if a module has a terraform required_version within valid range. -func (r *TerraformRequiredVersion) Check(runner tflint.Runner) error { - config := &TerraformRequiredVersionConfig{} +func (r *TerraformRequiredVersionRange) Check(runner tflint.Runner) error { + config := &TerraformRequiredVersionRangeConfig{} if err := runner.DecodeRuleConfig(r.Name(), config); err != nil { return err } - minVersion := minimumTerraformRequiredVersion + minVersion := minimumTerraformRequiredVersionRange if config.MinVersion != "" { if _, err := version.NewSemver(config.MinVersion); err != nil { return err @@ -68,7 +68,7 @@ func (r *TerraformRequiredVersion) Check(runner tflint.Runner) error { minVersion = config.MinVersion } - maxVersion := maximumTerraformRequiredVersion + maxVersion := maximumTerraformRequiredVersionRange if config.MaxVersion != "" { if _, err := version.NewSemver(config.MaxVersion); err != nil { return err diff --git a/tflint-ruleset-blueprint/rules/terraform_required_version_range_test.go b/tflint-ruleset-blueprint/rules/terraform_required_version_range_test.go new file mode 100644 index 00000000000..120896387f6 --- /dev/null +++ b/tflint-ruleset-blueprint/rules/terraform_required_version_range_test.go @@ -0,0 +1,38 @@ +package rules + +import ( + "path" + "testing" +) + +const ( + TerraformRequiredVersionRangeTestDir = "terraform_required_version_range" +) + +func TestTerraformMinimumRequiredVersionRange(t *testing.T) { + tests := []ruleTC{ + { + dir: path.Join(TerraformRequiredVersionRangeTestDir, "multiple-valid"), + }, + { + dir: path.Join(TerraformRequiredVersionRangeTestDir, "multiple-invalid"), + }, + { + dir: path.Join(TerraformRequiredVersionRangeTestDir, "multiple-valid-config"), + }, + { + dir: path.Join(TerraformRequiredVersionRangeTestDir, "multiple-invalid-config"), + }, + { + dir: path.Join(TerraformRequiredVersionRangeTestDir, "multiple-valid-config-single"), + }, + } + + rule := NewTerraformRequiredVersionRange() + + for _, tc := range tests { + t.Run(tc.dir, func(t *testing.T) { + ruleTest(t, rule, tc) + }) + } +} diff --git a/tflint-ruleset-blueprint/rules/terraform_required_version_test.go b/tflint-ruleset-blueprint/rules/terraform_required_version_test.go deleted file mode 100644 index f218ee2d2c8..00000000000 --- a/tflint-ruleset-blueprint/rules/terraform_required_version_test.go +++ /dev/null @@ -1,38 +0,0 @@ -package rules - -import ( - "path" - "testing" -) - -const ( - terraformRequiredVersionTestDir = "terraform_required_version" -) - -func TestTerraformMinimumRequiredVersion(t *testing.T) { - tests := []ruleTC{ - { - dir: path.Join(terraformRequiredVersionTestDir, "multiple-valid"), - }, - { - dir: path.Join(terraformRequiredVersionTestDir, "multiple-invalid"), - }, - { - dir: path.Join(terraformRequiredVersionTestDir, "multiple-valid-config"), - }, - { - dir: path.Join(terraformRequiredVersionTestDir, "multiple-invalid-config"), - }, - { - dir: path.Join(terraformRequiredVersionTestDir, "multiple-valid-config-single"), - }, - } - - rule := NewTerraformRequiredVersion() - - for _, tc := range tests { - t.Run(tc.dir, func(t *testing.T) { - ruleTest(t, rule, tc) - }) - } -} diff --git a/tflint-ruleset-blueprint/rules/testdata/terraform_required_version/multiple-invalid-config/.expected/issues.json b/tflint-ruleset-blueprint/rules/testdata/terraform_required_version_range/multiple-invalid-config/.expected/issues.json similarity index 100% rename from tflint-ruleset-blueprint/rules/testdata/terraform_required_version/multiple-invalid-config/.expected/issues.json rename to tflint-ruleset-blueprint/rules/testdata/terraform_required_version_range/multiple-invalid-config/.expected/issues.json diff --git a/tflint-ruleset-blueprint/rules/testdata/terraform_required_version/multiple-valid-config/.tflint.hcl b/tflint-ruleset-blueprint/rules/testdata/terraform_required_version_range/multiple-invalid-config/.tflint.hcl similarity index 61% rename from tflint-ruleset-blueprint/rules/testdata/terraform_required_version/multiple-valid-config/.tflint.hcl rename to tflint-ruleset-blueprint/rules/testdata/terraform_required_version_range/multiple-invalid-config/.tflint.hcl index e9e5ba835f5..5844e3c25ee 100644 --- a/tflint-ruleset-blueprint/rules/testdata/terraform_required_version/multiple-valid-config/.tflint.hcl +++ b/tflint-ruleset-blueprint/rules/testdata/terraform_required_version_range/multiple-invalid-config/.tflint.hcl @@ -1,4 +1,4 @@ -rule "terraform_required_version" { +rule "terraform_required_version_range" { enabled = true min_version = "1.6" max_version = "1.9" diff --git a/tflint-ruleset-blueprint/rules/testdata/terraform_required_version/multiple-invalid-config/main.tf b/tflint-ruleset-blueprint/rules/testdata/terraform_required_version_range/multiple-invalid-config/main.tf similarity index 100% rename from tflint-ruleset-blueprint/rules/testdata/terraform_required_version/multiple-invalid-config/main.tf rename to tflint-ruleset-blueprint/rules/testdata/terraform_required_version_range/multiple-invalid-config/main.tf diff --git a/tflint-ruleset-blueprint/rules/testdata/terraform_required_version/multiple-invalid/.expected/issues.json b/tflint-ruleset-blueprint/rules/testdata/terraform_required_version_range/multiple-invalid/.expected/issues.json similarity index 100% rename from tflint-ruleset-blueprint/rules/testdata/terraform_required_version/multiple-invalid/.expected/issues.json rename to tflint-ruleset-blueprint/rules/testdata/terraform_required_version_range/multiple-invalid/.expected/issues.json diff --git a/tflint-ruleset-blueprint/rules/testdata/terraform_required_version/multiple-invalid/main.tf b/tflint-ruleset-blueprint/rules/testdata/terraform_required_version_range/multiple-invalid/main.tf similarity index 100% rename from tflint-ruleset-blueprint/rules/testdata/terraform_required_version/multiple-invalid/main.tf rename to tflint-ruleset-blueprint/rules/testdata/terraform_required_version_range/multiple-invalid/main.tf diff --git a/tflint-ruleset-blueprint/rules/testdata/terraform_required_version/multiple-valid-config-single/.expected/issues.json b/tflint-ruleset-blueprint/rules/testdata/terraform_required_version_range/multiple-valid-config-single/.expected/issues.json similarity index 100% rename from tflint-ruleset-blueprint/rules/testdata/terraform_required_version/multiple-valid-config-single/.expected/issues.json rename to tflint-ruleset-blueprint/rules/testdata/terraform_required_version_range/multiple-valid-config-single/.expected/issues.json diff --git a/tflint-ruleset-blueprint/rules/testdata/terraform_required_version/multiple-valid-config-single/.tflint.hcl b/tflint-ruleset-blueprint/rules/testdata/terraform_required_version_range/multiple-valid-config-single/.tflint.hcl similarity index 51% rename from tflint-ruleset-blueprint/rules/testdata/terraform_required_version/multiple-valid-config-single/.tflint.hcl rename to tflint-ruleset-blueprint/rules/testdata/terraform_required_version_range/multiple-valid-config-single/.tflint.hcl index 2af18905a66..2b138f4a409 100644 --- a/tflint-ruleset-blueprint/rules/testdata/terraform_required_version/multiple-valid-config-single/.tflint.hcl +++ b/tflint-ruleset-blueprint/rules/testdata/terraform_required_version_range/multiple-valid-config-single/.tflint.hcl @@ -1,4 +1,4 @@ -rule "terraform_required_version" { +rule "terraform_required_version_range" { enabled = true max_version = "1.6" } diff --git a/tflint-ruleset-blueprint/rules/testdata/terraform_required_version/multiple-valid-config-single/main.tf b/tflint-ruleset-blueprint/rules/testdata/terraform_required_version_range/multiple-valid-config-single/main.tf similarity index 100% rename from tflint-ruleset-blueprint/rules/testdata/terraform_required_version/multiple-valid-config-single/main.tf rename to tflint-ruleset-blueprint/rules/testdata/terraform_required_version_range/multiple-valid-config-single/main.tf diff --git a/tflint-ruleset-blueprint/rules/testdata/terraform_required_version/multiple-valid-config/.expected/issues.json b/tflint-ruleset-blueprint/rules/testdata/terraform_required_version_range/multiple-valid-config/.expected/issues.json similarity index 100% rename from tflint-ruleset-blueprint/rules/testdata/terraform_required_version/multiple-valid-config/.expected/issues.json rename to tflint-ruleset-blueprint/rules/testdata/terraform_required_version_range/multiple-valid-config/.expected/issues.json diff --git a/tflint-ruleset-blueprint/rules/testdata/terraform_required_version/multiple-invalid-config/.tflint.hcl b/tflint-ruleset-blueprint/rules/testdata/terraform_required_version_range/multiple-valid-config/.tflint.hcl similarity index 61% rename from tflint-ruleset-blueprint/rules/testdata/terraform_required_version/multiple-invalid-config/.tflint.hcl rename to tflint-ruleset-blueprint/rules/testdata/terraform_required_version_range/multiple-valid-config/.tflint.hcl index e9e5ba835f5..5844e3c25ee 100644 --- a/tflint-ruleset-blueprint/rules/testdata/terraform_required_version/multiple-invalid-config/.tflint.hcl +++ b/tflint-ruleset-blueprint/rules/testdata/terraform_required_version_range/multiple-valid-config/.tflint.hcl @@ -1,4 +1,4 @@ -rule "terraform_required_version" { +rule "terraform_required_version_range" { enabled = true min_version = "1.6" max_version = "1.9" diff --git a/tflint-ruleset-blueprint/rules/testdata/terraform_required_version/multiple-valid-config/main.tf b/tflint-ruleset-blueprint/rules/testdata/terraform_required_version_range/multiple-valid-config/main.tf similarity index 100% rename from tflint-ruleset-blueprint/rules/testdata/terraform_required_version/multiple-valid-config/main.tf rename to tflint-ruleset-blueprint/rules/testdata/terraform_required_version_range/multiple-valid-config/main.tf diff --git a/tflint-ruleset-blueprint/rules/testdata/terraform_required_version/multiple-valid/.expected/issues.json b/tflint-ruleset-blueprint/rules/testdata/terraform_required_version_range/multiple-valid/.expected/issues.json similarity index 100% rename from tflint-ruleset-blueprint/rules/testdata/terraform_required_version/multiple-valid/.expected/issues.json rename to tflint-ruleset-blueprint/rules/testdata/terraform_required_version_range/multiple-valid/.expected/issues.json diff --git a/tflint-ruleset-blueprint/rules/testdata/terraform_required_version/multiple-valid/main.tf b/tflint-ruleset-blueprint/rules/testdata/terraform_required_version_range/multiple-valid/main.tf similarity index 100% rename from tflint-ruleset-blueprint/rules/testdata/terraform_required_version/multiple-valid/main.tf rename to tflint-ruleset-blueprint/rules/testdata/terraform_required_version_range/multiple-valid/main.tf