Skip to content

Commit

Permalink
fix(tflint): rename plugin (#2516)
Browse files Browse the repository at this point in the history
  • Loading branch information
apeabody authored Aug 13, 2024
1 parent 7125f5e commit 0cc19e2
Show file tree
Hide file tree
Showing 16 changed files with 59 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,63 +12,63 @@ 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
}
minVersion = config.MinVersion
}

maxVersion := maximumTerraformRequiredVersion
maxVersion := maximumTerraformRequiredVersionRange
if config.MaxVersion != "" {
if _, err := version.NewSemver(config.MaxVersion); err != nil {
return err
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
})
}
}
38 changes: 0 additions & 38 deletions tflint-ruleset-blueprint/rules/terraform_required_version_test.go

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
rule "terraform_required_version" {
rule "terraform_required_version_range" {
enabled = true
min_version = "1.6"
max_version = "1.9"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
rule "terraform_required_version" {
rule "terraform_required_version_range" {
enabled = true
max_version = "1.6"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
rule "terraform_required_version" {
rule "terraform_required_version_range" {
enabled = true
min_version = "1.6"
max_version = "1.9"
Expand Down

0 comments on commit 0cc19e2

Please sign in to comment.