Skip to content

Commit

Permalink
fix(tflint): rename plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
apeabody committed Aug 13, 2024
1 parent c9570c3 commit eaf5b93
Show file tree
Hide file tree
Showing 16 changed files with 56 additions and 56 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 TestTerraformMinimumRequiredVersion(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.

0 comments on commit eaf5b93

Please sign in to comment.