Skip to content

plugin: Drop support for plugin SDK v0.12/v0.13 #1749

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

Merged
merged 1 commit into from
May 2, 2023
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
16 changes: 6 additions & 10 deletions cmd/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,6 @@ func (cli *CLI) inspectModule(opts Options, dir string, filterFiles []string) (t
if err != nil {
return tflint.Issues{}, fmt.Errorf("Failed to load TFLint config; %w", err)
}
// tflint-plugin-sdk v0.13+ doesn't need to disable rules config when enabling the only option.
// This is for the backward compatibility.
if len(opts.Only) > 0 {
for _, rule := range cli.config.Rules {
rule.Enabled = false
}
}
cli.config.Merge(opts.toConfig())

// Setup loader
Expand Down Expand Up @@ -193,11 +186,14 @@ func (cli *CLI) inspectModule(opts Options, dir string, filterFiles []string) (t
if err != nil {
if st, ok := status.FromError(err); ok && st.Code() == codes.Unimplemented {
// SDKVersion endpoint is available in tflint-plugin-sdk v0.14+.
// Use nil if not available.
return tflint.Issues{}, fmt.Errorf(`Plugin "%s" SDK version is incompatible. Compatible versions: %s`, name, plugin.SDKVersionConstraints)
} else {
return tflint.Issues{}, fmt.Errorf("Failed to get TFLint version constraints to `%s` plugin; %w", name, err)
return tflint.Issues{}, fmt.Errorf(`Failed to get plugin "%s" SDK version; %w`, name, err)
}
}
if !plugin.SDKVersionConstraints.Check(sdkVersion) {
return tflint.Issues{}, fmt.Errorf(`Plugin "%s" SDK version (%s) is incompatible. Compatible versions: %s`, name, sdkVersion, plugin.SDKVersionConstraints)
}

for _, runner := range runners {
err = ruleset.Check(plugin.NewGRPCServer(runner, rootRunner, cli.loader.Files(), sdkVersion))
Expand Down Expand Up @@ -280,7 +276,7 @@ func launchPlugins(config *tflint.Config) (*plugin.Plugin, error) {
if err != nil {
if st, ok := status.FromError(err); ok && st.Code() == codes.Unimplemented {
// VersionConstraints endpoint is available in tflint-plugin-sdk v0.14+.
// Skip verification if not available.
return rulesetPlugin, fmt.Errorf(`Plugin "%s" SDK version is incompatible. Compatible versions: %s`, name, plugin.SDKVersionConstraints)
} else {
return rulesetPlugin, fmt.Errorf("Failed to get TFLint version constraints to `%s` plugin; %w", name, err)
}
Expand Down
34 changes: 11 additions & 23 deletions cmd/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,30 +83,18 @@ func (opts *Options) toConfig() *tflint.Config {
}

rules := map[string]*tflint.RuleConfig{}
if len(opts.Only) > 0 {
// tflint-plugin-sdk v0.13+ doesn't need rules config when enabling the only option.
// This is for the backward compatibility.
for _, rule := range opts.Only {
rules[rule] = &tflint.RuleConfig{
Name: rule,
Enabled: true,
Body: nil,
}
}
} else {
for _, rule := range opts.EnableRules {
rules[rule] = &tflint.RuleConfig{
Name: rule,
Enabled: true,
Body: nil,
}
for _, rule := range append(opts.Only, opts.EnableRules...) {
rules[rule] = &tflint.RuleConfig{
Name: rule,
Enabled: true,
Body: nil,
}
for _, rule := range opts.DisableRules {
rules[rule] = &tflint.RuleConfig{
Name: rule,
Enabled: false,
Body: nil,
}
}
for _, rule := range opts.DisableRules {
rules[rule] = &tflint.RuleConfig{
Name: rule,
Enabled: false,
Body: nil,
}
}

Expand Down
15 changes: 5 additions & 10 deletions docs/developer-guide/api_compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,19 @@
This is an internal documentation summarizing the currently supported SDK and TFLint versions and any compatibility caveats.

Protocol version: 11
SDK version: v0.12.0+
SDK version: v0.14.0+
TFLint version: v0.40.0+

- `Only` option is only supported by SDK v0.13.0+.
- https://github.com/terraform-linters/tflint/pull/1516
- https://github.com/terraform-linters/tflint-plugin-sdk/pull/198
- Schema mode is only supported by SDK v0.14.0+ and TFLint v0.42.0+. v0.41 ignores this mode.
- Schema mode is only supported by TFLint v0.42.0+. v0.41 ignores this mode.
- https://github.com/terraform-linters/tflint/pull/1530
- https://github.com/terraform-linters/tflint-plugin-sdk/pull/201
- `VersionConstraint` is only supported by SDK v0.14.0+ and TFLint v0.42.0+. v0.41 ignores this constraint.
- `VersionConstraint` is only supported by TFLint v0.42.0+. v0.41 ignores this constraint.
- https://github.com/terraform-linters/tflint/pull/1535
- https://github.com/terraform-linters/tflint-plugin-sdk/pull/202
- `SDKVersion` is only supported by SDK v0.14.0+. v0.13 does not return a version.
- https://github.com/terraform-linters/tflint-plugin-sdk/pull/203
- `each.*` and `count.*` are only supported by SDK v0.14.0+ and TFLint v0.42.0+.
- `each.*` and `count.*` are only supported by TFLint v0.42.0+. v0.41 treats as unknown value.
- https://github.com/terraform-linters/tflint/pull/1537
- https://github.com/terraform-linters/tflint-plugin-sdk/pull/205
- Expand mode is only supported by SDK v0.14.0+ and TFLint v0.42.0+.
- Expand mode is only supported by TFLint v0.42.0+. v0.41 ignores this option.
- https://github.com/terraform-linters/tflint/pull/1537
- https://github.com/terraform-linters/tflint-plugin-sdk/pull/208
- Client-side value handling is introduced in SDK v0.16.0 and TFLint v0.46.0. TFLint v0.45.0 returns an error instead of a value.
Expand Down
9 changes: 6 additions & 3 deletions langserver/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func NewHandler(configPath string, cliConfig *tflint.Config) (jsonrpc2.Handler,
if err != nil {
if st, ok := status.FromError(err); ok && st.Code() == codes.Unimplemented {
// VersionConstraints endpoint is available in tflint-plugin-sdk v0.14+.
// Skip verification if not available.
return nil, nil, fmt.Errorf(`Plugin "%s" SDK version is incompatible. Compatible versions: %s`, name, plugin.SDKVersionConstraints)
} else {
return nil, nil, fmt.Errorf("Failed to get TFLint version constraints to `%s` plugin; %w", name, err)
}
Expand All @@ -63,11 +63,14 @@ func NewHandler(configPath string, cliConfig *tflint.Config) (jsonrpc2.Handler,
if err != nil {
if st, ok := status.FromError(err); ok && st.Code() == codes.Unimplemented {
// SDKVersion endpoint is available in tflint-plugin-sdk v0.14+.
// Use nil if not available.
return nil, nil, fmt.Errorf(`Plugin "%s" SDK version is incompatible. Compatible versions: %s`, name, plugin.SDKVersionConstraints)
} else {
return nil, nil, fmt.Errorf("Failed to get SDK version of `%s` plugin; %w", name, err)
return nil, nil, fmt.Errorf(`Failed to get plugin "%s" SDK version; %w`, name, err)
}
}
if !plugin.SDKVersionConstraints.Check(clientSDKVersions[name]) {
return nil, nil, fmt.Errorf(`Plugin "%s" SDK version (%s) is incompatible. Compatible versions: %s`, name, clientSDKVersions[name], plugin.SDKVersionConstraints)
}

rulesets = append(rulesets, ruleset)
}
Expand Down
4 changes: 4 additions & 0 deletions plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package plugin

import (
plugin "github.com/hashicorp/go-plugin"
"github.com/hashicorp/go-version"
"github.com/terraform-linters/tflint-plugin-sdk/plugin/host2plugin"
)

Expand All @@ -12,6 +13,9 @@ var (
localPluginRoot = "./.tflint.d/plugins"
)

// SDKVersionConstraints is the version constraint of the supported SDK version.
var SDKVersionConstraints = version.MustConstraints(version.NewConstraint(">= 0.14.0"))

// Plugin is an object handling plugins
// Basically, it is a wrapper for go-plugin and provides an API to handle them collectively.
type Plugin struct {
Expand Down