Skip to content

Commit a9512b1

Browse files
authored
Drop support for TFLint v0.45 and earlier (#366)
1 parent f8dbc31 commit a9512b1

File tree

9 files changed

+126
-176
lines changed

9 files changed

+126
-176
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ NOTE: This plugin system is experimental. This means that API compatibility is f
1010

1111
## Requirements
1212

13-
- TFLint v0.42+
14-
- Go v1.23+
13+
- TFLint v0.46+
14+
- Go v1.24+
1515

1616
## Usage
1717

plugin/internal/fromproto/fromproto.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -343,12 +343,6 @@ func Error(err error) error {
343343
switch t := st.Details()[0].(type) {
344344
case *proto.ErrorDetail:
345345
switch t.Code {
346-
case proto.ErrorCode_ERROR_CODE_UNKNOWN_VALUE:
347-
return tflint.ErrUnknownValue
348-
case proto.ErrorCode_ERROR_CODE_NULL_VALUE:
349-
return tflint.ErrNullValue
350-
case proto.ErrorCode_ERROR_CODE_UNEVALUABLE:
351-
return fmt.Errorf("%s%w", st.Message(), tflint.ErrUnevaluable)
352346
case proto.ErrorCode_ERROR_CODE_SENSITIVE:
353347
return tflint.ErrSensitive
354348
}

plugin/internal/host2plugin/host2plugin_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,15 +245,15 @@ func TestVersionConstraints(t *testing.T) {
245245
ServerImpl: func() string {
246246
return ""
247247
},
248-
Want: "",
248+
Want: minTFLintVersionConstraint.String(),
249249
ErrCheck: neverHappend,
250250
},
251251
{
252252
Name: "valid constraint",
253253
ServerImpl: func() string {
254254
return ">= 1.0"
255255
},
256-
Want: ">= 1.0",
256+
Want: fmt.Sprintf(">= 1.0,%s", minTFLintVersionConstraint),
257257
ErrCheck: neverHappend,
258258
},
259259
{
@@ -444,7 +444,7 @@ func TestApplyGlobalConfig(t *testing.T) {
444444
},
445445
LegacyHost: true,
446446
ErrCheck: func(err error) bool {
447-
return err == nil || err.Error() != "failed to satisfy version constraints; tflint-ruleset-test_ruleset requires >= 0.42, but TFLint version is 0.40 or 0.41"
447+
return err == nil || err.Error() != fmt.Sprintf("failed to satisfy version constraints; tflint-ruleset-test_ruleset requires %s, but TFLint version is 0.40 or 0.41", minTFLintVersionConstraint)
448448
},
449449
},
450450
}

plugin/internal/host2plugin/plugin.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55

66
plugin "github.com/hashicorp/go-plugin"
7+
"github.com/hashicorp/go-version"
78
"github.com/terraform-linters/tflint-plugin-sdk/plugin/internal/proto"
89
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
910
"google.golang.org/grpc"
@@ -12,6 +13,9 @@ import (
1213
// SDKVersion is the SDK version.
1314
const SDKVersion = "0.22.0"
1415

16+
// minTFLintVersionConstraint presents the minimum version of TFLint that this SDK supports.
17+
var minTFLintVersionConstraint = version.MustConstraints(version.NewConstraint(">= 0.46"))
18+
1519
// handShakeConfig is used for UX. ProcotolVersion will be updated by incompatible changes.
1620
var handshakeConfig = plugin.HandshakeConfig{
1721
ProtocolVersion: 11,

plugin/internal/host2plugin/server.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66

77
"github.com/hashicorp/go-plugin"
8+
"github.com/hashicorp/go-version"
89
"github.com/terraform-linters/tflint-plugin-sdk/internal"
910
"github.com/terraform-linters/tflint-plugin-sdk/logger"
1011
"github.com/terraform-linters/tflint-plugin-sdk/plugin/internal/fromproto"
@@ -73,7 +74,18 @@ func (s *GRPCServer) GetRuleNames(ctx context.Context, req *proto.GetRuleNames_R
7374
// GetVersionConstraint returns a constraint of TFLint versions.
7475
func (s *GRPCServer) GetVersionConstraint(ctx context.Context, req *proto.GetVersionConstraint_Request) (*proto.GetVersionConstraint_Response, error) {
7576
s.constraintChecked = true
76-
return &proto.GetVersionConstraint_Response{Constraint: s.impl.VersionConstraint()}, nil
77+
constraints := version.Constraints{}
78+
var err error
79+
if s.impl.VersionConstraint() != "" {
80+
constraints, err = version.NewConstraint(s.impl.VersionConstraint())
81+
if err != nil {
82+
return nil, status.Error(codes.Internal, err.Error())
83+
}
84+
}
85+
// Append a minimum supported version constraint
86+
constraints = append(constraints, minTFLintVersionConstraint...)
87+
88+
return &proto.GetVersionConstraint_Response{Constraint: constraints.String()}, nil
7789
}
7890

7991
// GetSDKVersion returns the SDK version.
@@ -90,7 +102,7 @@ func (s *GRPCServer) GetConfigSchema(ctx context.Context, req *proto.GetConfigSc
90102
func (s *GRPCServer) ApplyGlobalConfig(ctx context.Context, req *proto.ApplyGlobalConfig_Request) (*proto.ApplyGlobalConfig_Response, error) {
91103
// TFLint v0.41 and earlier does not check version constraints.
92104
if !s.constraintChecked {
93-
return nil, status.Error(codes.FailedPrecondition, fmt.Sprintf("failed to satisfy version constraints; tflint-ruleset-%s requires >= 0.42, but TFLint version is 0.40 or 0.41", s.impl.RuleSetName()))
105+
return nil, status.Error(codes.FailedPrecondition, fmt.Sprintf("failed to satisfy version constraints; tflint-ruleset-%s requires %s, but TFLint version is 0.40 or 0.41", s.impl.RuleSetName(), minTFLintVersionConstraint))
94106
}
95107

96108
if req.Config == nil {

plugin/internal/plugin2host/plugin2host_test.go

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1761,45 +1761,6 @@ func TestEvaluateExpr(t *testing.T) {
17611761
return err == nil || err.Error() != "unexpected error"
17621762
},
17631763
},
1764-
{
1765-
Name: "server returns an unknown error",
1766-
Expr: hclExpr(`1`),
1767-
TargetType: reflect.TypeOf(0),
1768-
ServerImpl: func(hcl.Expression, tflint.EvaluateExprOption) (cty.Value, error) {
1769-
return cty.Value{}, fmt.Errorf("unknown%w", tflint.ErrUnknownValue)
1770-
},
1771-
Want: 0,
1772-
GetFileImpl: fileExists,
1773-
ErrCheck: func(err error) bool {
1774-
return !errors.Is(err, tflint.ErrUnknownValue)
1775-
},
1776-
},
1777-
{
1778-
Name: "server returns a null value error",
1779-
Expr: hclExpr(`1`),
1780-
TargetType: reflect.TypeOf(0),
1781-
ServerImpl: func(hcl.Expression, tflint.EvaluateExprOption) (cty.Value, error) {
1782-
return cty.Value{}, fmt.Errorf("null value%w", tflint.ErrNullValue)
1783-
},
1784-
Want: 0,
1785-
GetFileImpl: fileExists,
1786-
ErrCheck: func(err error) bool {
1787-
return !errors.Is(err, tflint.ErrNullValue)
1788-
},
1789-
},
1790-
{
1791-
Name: "server returns a unevaluable error",
1792-
Expr: hclExpr(`1`),
1793-
TargetType: reflect.TypeOf(0),
1794-
ServerImpl: func(hcl.Expression, tflint.EvaluateExprOption) (cty.Value, error) {
1795-
return cty.Value{}, fmt.Errorf("unevaluable%w", tflint.ErrUnevaluable)
1796-
},
1797-
Want: 0,
1798-
GetFileImpl: fileExists,
1799-
ErrCheck: func(err error) bool {
1800-
return !errors.Is(err, tflint.ErrUnevaluable)
1801-
},
1802-
},
18031764
{
18041765
Name: "server returns a sensitive error",
18051766
Expr: hclExpr(`1`),

0 commit comments

Comments
 (0)