Skip to content

Commit be882d0

Browse files
authored
Remove unused net/rpc based plugin implementations (#147)
1 parent a74d3f5 commit be882d0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+163
-2803
lines changed

README.md

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

1111
## Requirements
1212

13-
- TFLint v0.30+
13+
- TFLint v0.35+
1414
- Go v1.18
1515

1616
## Usage
@@ -23,6 +23,8 @@ For more details on the API, see [tflint](https://pkg.go.dev/github.com/terrafor
2323

2424
![architecture](architecture.png)
2525

26-
This plugin system uses [go-plugin](https://github.com/hashicorp/go-plugin). TFLint launches the plugin as a sub-process and communicates with the plugin over RPC. The plugin acts as a server, while TFLint acts as a client that sends inspection requests to the plugin.
26+
This plugin system uses [go-plugin](https://github.com/hashicorp/go-plugin). TFLint launches the plugin as a sub-process and communicates with the plugin over gRPC. The plugin acts as a server, while TFLint acts as a client that sends inspection requests to the plugin.
2727

2828
On the other hand, the plugin sends various requests to a server (TFLint) to get detailed runtime contexts (e.g. variables and expressions). This means that TFLint and plugins can act as both a server and a client.
29+
30+
These implementations are included in the [plugin/host2plugin](https://pkg.go.dev/github.com/terraform-linters/tflint-plugin-sdk/plugin/host2plugin) and [plugin/plugin2host]((https://pkg.go.dev/github.com/terraform-linters/tflint-plugin-sdk/plugin/plugin2host)) packages.

go.mod

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ require (
66
github.com/google/go-cmp v0.5.7
77
github.com/hashicorp/go-hclog v1.2.0
88
github.com/hashicorp/go-plugin v1.4.3
9-
github.com/hashicorp/go-version v1.4.0
109
github.com/hashicorp/hcl/v2 v2.11.1
11-
github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734
1210
github.com/zclconf/go-cty v1.10.0
1311
google.golang.org/grpc v1.45.0
1412
google.golang.org/protobuf v1.27.1

go.sum

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,13 @@ github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=
6060
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
6161
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
6262
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
63-
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
6463
github.com/hashicorp/go-hclog v0.14.1/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ=
6564
github.com/hashicorp/go-hclog v1.2.0 h1:La19f8d7WIlm4ogzNHB0JGqs5AUDAZ2UfCY4sJXcJdM=
6665
github.com/hashicorp/go-hclog v1.2.0/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ=
6766
github.com/hashicorp/go-plugin v1.4.3 h1:DXmvivbWD5qdiBts9TpBC7BYL1Aia5sxbRgQB+v6UZM=
6867
github.com/hashicorp/go-plugin v1.4.3/go.mod h1:5fGEH17QVwTTcR0zV7yhDPLLmFX9YSZ38b18Udy6vYQ=
69-
github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
70-
github.com/hashicorp/go-version v1.4.0 h1:aAQzgqIrRKRa7w75CKpbBxYsmUoPjzVm1W59ca1L0J4=
71-
github.com/hashicorp/go-version v1.4.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
7268
github.com/hashicorp/hcl/v2 v2.11.1 h1:yTyWcXcm9XB0TEkyU/JCRU6rYy4K+mgLtzn2wlrJbcc=
7369
github.com/hashicorp/hcl/v2 v2.11.1/go.mod h1:FwWsfWEjyV/CMj8s/gqAuiviY72rJ1/oayI9WftqcKg=
74-
github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734 h1:HKLsbzeOsfXmKNpr3GiT18XAblV0BjCbzL8KQAMZGa0=
75-
github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734/go.mod h1:kNDNcF7sN4DocDLBkQYz73HGKwN1ANB1blq4lIYLYvg=
7670
github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb h1:b5rjCoWHc7eqmAS4/qyk21ZsHyb6Mxv/jykxvNTkU4M=
7771
github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
7872
github.com/jhump/protoreflect v1.6.0 h1:h5jfMVslIg6l29nsMs0D8Wj17RDVdNYti0vDN/PZZoE=
@@ -113,7 +107,6 @@ github.com/vmihailenco/msgpack/v4 v4.3.12 h1:07s4sz9IReOgdikxLTKNbBdqDMLsjPKXwvC
113107
github.com/vmihailenco/msgpack/v4 v4.3.12/go.mod h1:gborTTJjAo/GWTqqRjrLCn9pgNN+NXzzngzBKDPIqw4=
114108
github.com/vmihailenco/tagparser v0.1.1 h1:quXMXlA39OCbd2wAdTsGDlK9RkOk6Wuw+x37wVyIuWY=
115109
github.com/vmihailenco/tagparser v0.1.1/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI=
116-
github.com/zclconf/go-cty v1.1.0/go.mod h1:xnAOWiHeOqg2nWS62VtQ7pbOu17FtxJNW8RLEih+O3s=
117110
github.com/zclconf/go-cty v1.2.0/go.mod h1:hOPWgoHbaTUnI5k4D2ld+GRpFJSCe6bCM7m1q/N4PQ8=
118111
github.com/zclconf/go-cty v1.8.0/go.mod h1:vVKLxnk3puL4qRAv72AO+W99LUD4da90g3uUAzyuvAk=
119112
github.com/zclconf/go-cty v1.10.0 h1:mp9ZXQeIcN8kAwuqorjH+Q+njbJKjLrvB2yIh4q7U+0=
@@ -136,12 +129,10 @@ golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73r
136129
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
137130
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
138131
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
139-
golang.org/x/net v0.0.0-20191009170851-d66e71096ffb/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
140132
golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
141133
golang.org/x/net v0.0.0-20200822124328-c89045814202 h1:VvcQYSHwXgi7W+TpUR6A9g6Up98WAHf3f/ulnJ62IyA=
142134
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
143135
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
144-
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
145136
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
146137
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
147138
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=

helper/doc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Package helper contains implementations for plugin testing.
22
//
33
// You can test the implemented rules using the mock Runner that is not
4-
// an RPC client. It is similar to TFLint's Runner, but is implemented
4+
// an gRPC client. It is similar to TFLint's Runner, but is implemented
55
// from scratch to avoid Terraform dependencies.
66
//
77
// Some implementations of the mock Runner have been simplified. As a result,

helper/runner.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66

77
"github.com/hashicorp/hcl/v2"
88
"github.com/terraform-linters/tflint-plugin-sdk/hclext"
9-
"github.com/terraform-linters/tflint-plugin-sdk/terraform/configs"
109
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
1110
"github.com/zclconf/go-cty/cty"
1211
"github.com/zclconf/go-cty/cty/convert"
@@ -15,11 +14,18 @@ import (
1514

1615
// Runner is a mock that satisfies the Runner interface for plugin testing.
1716
type Runner struct {
18-
files map[string]*hcl.File
1917
Issues Issues
2018

21-
tfconfig *configs.Config
22-
config Config
19+
files map[string]*hcl.File
20+
config Config
21+
variables map[string]*Variable
22+
}
23+
24+
// Variable is an implementation of variables in Terraform language
25+
type Variable struct {
26+
Name string
27+
Default cty.Value
28+
DeclRange hcl.Range
2329
}
2430

2531
// Config is a pseudo TFLint config file object for testing from plugins.
@@ -141,7 +147,7 @@ func (r *Runner) EvaluateExpr(expr hcl.Expression, ret interface{}, opts *tflint
141147
}
142148

143149
variables := map[string]cty.Value{}
144-
for _, variable := range r.tfconfig.Module.Variables {
150+
for _, variable := range r.variables {
145151
variables[variable.Name] = variable.Default
146152
}
147153
workspace, success := os.LookupEnv("TF_WORKSPACE")
@@ -203,12 +209,6 @@ func (r *Runner) AddLocalFile(name string, file *hcl.File) bool {
203209
}
204210

205211
func (r *Runner) initFromFiles() error {
206-
r.tfconfig = &configs.Config{
207-
Module: &configs.Module{
208-
Variables: map[string]*configs.Variable{},
209-
},
210-
}
211-
212212
for _, file := range r.files {
213213
content, _, diags := file.Body.PartialContent(configFileSchema)
214214
if diags.HasErrors() {
@@ -218,11 +218,11 @@ func (r *Runner) initFromFiles() error {
218218
for _, block := range content.Blocks {
219219
switch block.Type {
220220
case "variable":
221-
variable, diags := simpleDecodeVariableBlock(block)
221+
variable, diags := decodeVariableBlock(block)
222222
if diags.HasErrors() {
223223
return diags
224224
}
225-
r.tfconfig.Module.Variables[variable.Name] = variable
225+
r.variables[variable.Name] = variable
226226
default:
227227
continue
228228
}
@@ -232,8 +232,8 @@ func (r *Runner) initFromFiles() error {
232232
return nil
233233
}
234234

235-
func simpleDecodeVariableBlock(block *hcl.Block) (*configs.Variable, hcl.Diagnostics) {
236-
v := &configs.Variable{
235+
func decodeVariableBlock(block *hcl.Block) (*Variable, hcl.Diagnostics) {
236+
v := &Variable{
237237
Name: block.Labels[0],
238238
DeclRange: block.DefRange,
239239
}

helper/runner_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ func (r *dummyRule) Enabled() bool { return true }
283283
func (r *dummyRule) Severity() tflint.Severity { return tflint.ERROR }
284284
func (r *dummyRule) Check(tflint.Runner) error { return nil }
285285

286-
func Test_EmitIssueOnExpr(t *testing.T) {
286+
func Test_EmitIssue(t *testing.T) {
287287
src := `
288288
resource "aws_instance" "foo" {
289289
instance_type = "t2.micro"

plugin/client.go

Lines changed: 0 additions & 76 deletions
This file was deleted.

plugin/doc.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
// Package plugin contains the implementations needed to make
22
// the built binary act as a plugin.
33
//
4-
// A plugin is implemented as an RPC server and the host acts
4+
// A plugin is implemented as an gRPC server and the host acts
55
// as the client, sending analysis requests to the plugin.
6-
// Note that the server-client relationship here is the opposite of
7-
// the communication that takes place during the checking phase.
86
//
9-
// Implementation details are hidden in go-plugin. This package is
10-
// essentially a wrapper for go-plugin.
7+
// See host2plugin for implementation details.
118
package plugin

plugin/plugin.go

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,15 @@
11
package plugin
22

33
import (
4-
"encoding/gob"
5-
"net/rpc"
6-
7-
plugin "github.com/hashicorp/go-plugin"
8-
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
4+
"github.com/terraform-linters/tflint-plugin-sdk/plugin/host2plugin"
95

106
// Import this package to initialize the global logger
117
_ "github.com/terraform-linters/tflint-plugin-sdk/logger"
128
)
139

14-
// handShakeConfig is used for UX. ProcotolVersion will be updated by incompatible changes.
15-
var handshakeConfig = plugin.HandshakeConfig{
16-
ProtocolVersion: 9,
17-
MagicCookieKey: "TFLINT_RULESET_PLUGIN",
18-
MagicCookieValue: "5adSn1bX8nrDfgBqiAqqEkC6OE1h3iD8SqbMc5UUONx8x3xCF0KlPDsBRNDjoYDP",
19-
}
20-
21-
// RuleSetPlugin is a wrapper to satisfy the interface of go-plugin.
22-
type RuleSetPlugin struct {
23-
impl tflint.RPCRuleSet
24-
}
25-
26-
// Server returns an RPC server acting as a plugin.
27-
func (p *RuleSetPlugin) Server(b *plugin.MuxBroker) (interface{}, error) {
28-
return &Server{impl: p.impl, broker: b}, nil
29-
}
30-
31-
// Client returns an RPC client for the host.
32-
func (RuleSetPlugin) Client(b *plugin.MuxBroker, c *rpc.Client) (interface{}, error) {
33-
return &Client{rpcClient: c, broker: b}, nil
34-
}
10+
// ServeOpts is an option for serving a plugin.
11+
// Each plugin can pass a RuleSet that represents its own functionality.
12+
type ServeOpts = host2plugin.ServeOpts
3513

36-
func init() {
37-
gob.Register(tflint.Error{})
38-
}
14+
// Serve is a wrapper of plugin.Serve. This is entrypoint of all plugins.
15+
var Serve = host2plugin.Serve

plugin/server.go

Lines changed: 0 additions & 59 deletions
This file was deleted.

0 commit comments

Comments
 (0)