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

fix(tflint): rename plugin #2516

Merged
merged 1 commit into from
Aug 13, 2024
Merged
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
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
Loading