Skip to content

Commit

Permalink
Drop support for TFLint v0.45 and earlier
Browse files Browse the repository at this point in the history
  • Loading branch information
wata727 committed Jan 12, 2025
1 parent 9efe827 commit a93e3f9
Show file tree
Hide file tree
Showing 9 changed files with 125 additions and 175 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ NOTE: This plugin system is experimental. This means that API compatibility is f

## Requirements

- TFLint v0.42+
- TFLint v0.46+
- Go v1.23

## Usage
Expand Down
6 changes: 0 additions & 6 deletions plugin/internal/fromproto/fromproto.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,12 +343,6 @@ func Error(err error) error {
switch t := st.Details()[0].(type) {
case *proto.ErrorDetail:
switch t.Code {
case proto.ErrorCode_ERROR_CODE_UNKNOWN_VALUE:
return tflint.ErrUnknownValue
case proto.ErrorCode_ERROR_CODE_NULL_VALUE:
return tflint.ErrNullValue
case proto.ErrorCode_ERROR_CODE_UNEVALUABLE:
return fmt.Errorf("%s%w", st.Message(), tflint.ErrUnevaluable)
case proto.ErrorCode_ERROR_CODE_SENSITIVE:
return tflint.ErrSensitive
}
Expand Down
6 changes: 3 additions & 3 deletions plugin/internal/host2plugin/host2plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,15 +245,15 @@ func TestVersionConstraints(t *testing.T) {
ServerImpl: func() string {
return ""
},
Want: "",
Want: minTFLintVersionConstraint.String(),
ErrCheck: neverHappend,
},
{
Name: "valid constraint",
ServerImpl: func() string {
return ">= 1.0"
},
Want: ">= 1.0",
Want: fmt.Sprintf(">= 1.0,%s", minTFLintVersionConstraint),
ErrCheck: neverHappend,
},
{
Expand Down Expand Up @@ -444,7 +444,7 @@ func TestApplyGlobalConfig(t *testing.T) {
},
LegacyHost: true,
ErrCheck: func(err error) bool {
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"
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)
},
},
}
Expand Down
4 changes: 4 additions & 0 deletions plugin/internal/host2plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"

plugin "github.com/hashicorp/go-plugin"
"github.com/hashicorp/go-version"
"github.com/terraform-linters/tflint-plugin-sdk/plugin/internal/proto"
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
"google.golang.org/grpc"
Expand All @@ -12,6 +13,9 @@ import (
// SDKVersion is the SDK version.
const SDKVersion = "0.22.0"

// minTFLintVersionConstraint presents the minimum version of TFLint that this SDK supports.
var minTFLintVersionConstraint = version.MustConstraints(version.NewConstraint(">= 0.46"))

// handShakeConfig is used for UX. ProcotolVersion will be updated by incompatible changes.
var handshakeConfig = plugin.HandshakeConfig{
ProtocolVersion: 11,
Expand Down
16 changes: 14 additions & 2 deletions plugin/internal/host2plugin/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"

"github.com/hashicorp/go-plugin"
"github.com/hashicorp/go-version"
"github.com/terraform-linters/tflint-plugin-sdk/internal"
"github.com/terraform-linters/tflint-plugin-sdk/logger"
"github.com/terraform-linters/tflint-plugin-sdk/plugin/internal/fromproto"
Expand Down Expand Up @@ -73,7 +74,18 @@ func (s *GRPCServer) GetRuleNames(ctx context.Context, req *proto.GetRuleNames_R
// GetVersionConstraint returns a constraint of TFLint versions.
func (s *GRPCServer) GetVersionConstraint(ctx context.Context, req *proto.GetVersionConstraint_Request) (*proto.GetVersionConstraint_Response, error) {
s.constraintChecked = true
return &proto.GetVersionConstraint_Response{Constraint: s.impl.VersionConstraint()}, nil
constraints := version.Constraints{}
var err error
if s.impl.VersionConstraint() != "" {
constraints, err = version.NewConstraint(s.impl.VersionConstraint())
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
}
// Append a minimum supported version constraint
constraints = append(constraints, minTFLintVersionConstraint...)

return &proto.GetVersionConstraint_Response{Constraint: constraints.String()}, nil
}

// GetSDKVersion returns the SDK version.
Expand All @@ -90,7 +102,7 @@ func (s *GRPCServer) GetConfigSchema(ctx context.Context, req *proto.GetConfigSc
func (s *GRPCServer) ApplyGlobalConfig(ctx context.Context, req *proto.ApplyGlobalConfig_Request) (*proto.ApplyGlobalConfig_Response, error) {
// TFLint v0.41 and earlier does not check version constraints.
if !s.constraintChecked {
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()))
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))
}

if req.Config == nil {
Expand Down
39 changes: 0 additions & 39 deletions plugin/internal/plugin2host/plugin2host_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1761,45 +1761,6 @@ func TestEvaluateExpr(t *testing.T) {
return err == nil || err.Error() != "unexpected error"
},
},
{
Name: "server returns an unknown error",
Expr: hclExpr(`1`),
TargetType: reflect.TypeOf(0),
ServerImpl: func(hcl.Expression, tflint.EvaluateExprOption) (cty.Value, error) {
return cty.Value{}, fmt.Errorf("unknown%w", tflint.ErrUnknownValue)
},
Want: 0,
GetFileImpl: fileExists,
ErrCheck: func(err error) bool {
return !errors.Is(err, tflint.ErrUnknownValue)
},
},
{
Name: "server returns a null value error",
Expr: hclExpr(`1`),
TargetType: reflect.TypeOf(0),
ServerImpl: func(hcl.Expression, tflint.EvaluateExprOption) (cty.Value, error) {
return cty.Value{}, fmt.Errorf("null value%w", tflint.ErrNullValue)
},
Want: 0,
GetFileImpl: fileExists,
ErrCheck: func(err error) bool {
return !errors.Is(err, tflint.ErrNullValue)
},
},
{
Name: "server returns a unevaluable error",
Expr: hclExpr(`1`),
TargetType: reflect.TypeOf(0),
ServerImpl: func(hcl.Expression, tflint.EvaluateExprOption) (cty.Value, error) {
return cty.Value{}, fmt.Errorf("unevaluable%w", tflint.ErrUnevaluable)
},
Want: 0,
GetFileImpl: fileExists,
ErrCheck: func(err error) bool {
return !errors.Is(err, tflint.ErrUnevaluable)
},
},
{
Name: "server returns a sensitive error",
Expr: hclExpr(`1`),
Expand Down
Loading

0 comments on commit a93e3f9

Please sign in to comment.