Skip to content

Commit 9b802b1

Browse files
authored
Drop support for plugin SDK v0.12/v0.13 (#1749)
1 parent a53636d commit 9b802b1

File tree

5 files changed

+32
-46
lines changed

5 files changed

+32
-46
lines changed

cmd/inspect.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,6 @@ func (cli *CLI) inspectModule(opts Options, dir string, filterFiles []string) (t
152152
if err != nil {
153153
return tflint.Issues{}, fmt.Errorf("Failed to load TFLint config; %w", err)
154154
}
155-
// tflint-plugin-sdk v0.13+ doesn't need to disable rules config when enabling the only option.
156-
// This is for the backward compatibility.
157-
if len(opts.Only) > 0 {
158-
for _, rule := range cli.config.Rules {
159-
rule.Enabled = false
160-
}
161-
}
162155
cli.config.Merge(opts.toConfig())
163156

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

202198
for _, runner := range runners {
203199
err = ruleset.Check(plugin.NewGRPCServer(runner, rootRunner, cli.loader.Files(), sdkVersion))
@@ -280,7 +276,7 @@ func launchPlugins(config *tflint.Config) (*plugin.Plugin, error) {
280276
if err != nil {
281277
if st, ok := status.FromError(err); ok && st.Code() == codes.Unimplemented {
282278
// VersionConstraints endpoint is available in tflint-plugin-sdk v0.14+.
283-
// Skip verification if not available.
279+
return rulesetPlugin, fmt.Errorf(`Plugin "%s" SDK version is incompatible. Compatible versions: %s`, name, plugin.SDKVersionConstraints)
284280
} else {
285281
return rulesetPlugin, fmt.Errorf("Failed to get TFLint version constraints to `%s` plugin; %w", name, err)
286282
}

cmd/option.go

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -83,30 +83,18 @@ func (opts *Options) toConfig() *tflint.Config {
8383
}
8484

8585
rules := map[string]*tflint.RuleConfig{}
86-
if len(opts.Only) > 0 {
87-
// tflint-plugin-sdk v0.13+ doesn't need rules config when enabling the only option.
88-
// This is for the backward compatibility.
89-
for _, rule := range opts.Only {
90-
rules[rule] = &tflint.RuleConfig{
91-
Name: rule,
92-
Enabled: true,
93-
Body: nil,
94-
}
95-
}
96-
} else {
97-
for _, rule := range opts.EnableRules {
98-
rules[rule] = &tflint.RuleConfig{
99-
Name: rule,
100-
Enabled: true,
101-
Body: nil,
102-
}
86+
for _, rule := range append(opts.Only, opts.EnableRules...) {
87+
rules[rule] = &tflint.RuleConfig{
88+
Name: rule,
89+
Enabled: true,
90+
Body: nil,
10391
}
104-
for _, rule := range opts.DisableRules {
105-
rules[rule] = &tflint.RuleConfig{
106-
Name: rule,
107-
Enabled: false,
108-
Body: nil,
109-
}
92+
}
93+
for _, rule := range opts.DisableRules {
94+
rules[rule] = &tflint.RuleConfig{
95+
Name: rule,
96+
Enabled: false,
97+
Body: nil,
11098
}
11199
}
112100

docs/developer-guide/api_compatibility.md

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,19 @@
33
This is an internal documentation summarizing the currently supported SDK and TFLint versions and any compatibility caveats.
44

55
Protocol version: 11
6-
SDK version: v0.12.0+
6+
SDK version: v0.14.0+
77
TFLint version: v0.40.0+
88

9-
- `Only` option is only supported by SDK v0.13.0+.
10-
- https://github.com/terraform-linters/tflint/pull/1516
11-
- https://github.com/terraform-linters/tflint-plugin-sdk/pull/198
12-
- Schema mode is only supported by SDK v0.14.0+ and TFLint v0.42.0+. v0.41 ignores this mode.
9+
- Schema mode is only supported by TFLint v0.42.0+. v0.41 ignores this mode.
1310
- https://github.com/terraform-linters/tflint/pull/1530
1411
- https://github.com/terraform-linters/tflint-plugin-sdk/pull/201
15-
- `VersionConstraint` is only supported by SDK v0.14.0+ and TFLint v0.42.0+. v0.41 ignores this constraint.
12+
- `VersionConstraint` is only supported by TFLint v0.42.0+. v0.41 ignores this constraint.
1613
- https://github.com/terraform-linters/tflint/pull/1535
1714
- https://github.com/terraform-linters/tflint-plugin-sdk/pull/202
18-
- `SDKVersion` is only supported by SDK v0.14.0+. v0.13 does not return a version.
19-
- https://github.com/terraform-linters/tflint-plugin-sdk/pull/203
20-
- `each.*` and `count.*` are only supported by SDK v0.14.0+ and TFLint v0.42.0+.
15+
- `each.*` and `count.*` are only supported by TFLint v0.42.0+. v0.41 treats as unknown value.
2116
- https://github.com/terraform-linters/tflint/pull/1537
2217
- https://github.com/terraform-linters/tflint-plugin-sdk/pull/205
23-
- Expand mode is only supported by SDK v0.14.0+ and TFLint v0.42.0+.
18+
- Expand mode is only supported by TFLint v0.42.0+. v0.41 ignores this option.
2419
- https://github.com/terraform-linters/tflint/pull/1537
2520
- https://github.com/terraform-linters/tflint-plugin-sdk/pull/208
2621
- 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.

langserver/handler.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func NewHandler(configPath string, cliConfig *tflint.Config) (jsonrpc2.Handler,
5050
if err != nil {
5151
if st, ok := status.FromError(err); ok && st.Code() == codes.Unimplemented {
5252
// VersionConstraints endpoint is available in tflint-plugin-sdk v0.14+.
53-
// Skip verification if not available.
53+
return nil, nil, fmt.Errorf(`Plugin "%s" SDK version is incompatible. Compatible versions: %s`, name, plugin.SDKVersionConstraints)
5454
} else {
5555
return nil, nil, fmt.Errorf("Failed to get TFLint version constraints to `%s` plugin; %w", name, err)
5656
}
@@ -63,11 +63,14 @@ func NewHandler(configPath string, cliConfig *tflint.Config) (jsonrpc2.Handler,
6363
if err != nil {
6464
if st, ok := status.FromError(err); ok && st.Code() == codes.Unimplemented {
6565
// SDKVersion endpoint is available in tflint-plugin-sdk v0.14+.
66-
// Use nil if not available.
66+
return nil, nil, fmt.Errorf(`Plugin "%s" SDK version is incompatible. Compatible versions: %s`, name, plugin.SDKVersionConstraints)
6767
} else {
68-
return nil, nil, fmt.Errorf("Failed to get SDK version of `%s` plugin; %w", name, err)
68+
return nil, nil, fmt.Errorf(`Failed to get plugin "%s" SDK version; %w`, name, err)
6969
}
7070
}
71+
if !plugin.SDKVersionConstraints.Check(clientSDKVersions[name]) {
72+
return nil, nil, fmt.Errorf(`Plugin "%s" SDK version (%s) is incompatible. Compatible versions: %s`, name, clientSDKVersions[name], plugin.SDKVersionConstraints)
73+
}
7174

7275
rulesets = append(rulesets, ruleset)
7376
}

plugin/plugin.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package plugin
22

33
import (
44
plugin "github.com/hashicorp/go-plugin"
5+
"github.com/hashicorp/go-version"
56
"github.com/terraform-linters/tflint-plugin-sdk/plugin/host2plugin"
67
)
78

@@ -12,6 +13,9 @@ var (
1213
localPluginRoot = "./.tflint.d/plugins"
1314
)
1415

16+
// SDKVersionConstraints is the version constraint of the supported SDK version.
17+
var SDKVersionConstraints = version.MustConstraints(version.NewConstraint(">= 0.14.0"))
18+
1519
// Plugin is an object handling plugins
1620
// Basically, it is a wrapper for go-plugin and provides an API to handle them collectively.
1721
type Plugin struct {

0 commit comments

Comments
 (0)