Skip to content

Commit ee6dcd7

Browse files
authored
Internalize unnecessarily published plugin packages (#273)
1 parent 54455dd commit ee6dcd7

28 files changed

+86
-53
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ prepare:
55
@echo 'export PATH="$${AQUA_ROOT_DIR:-$${XDG_DATA_HOME:-$$HOME/.local/share}/aquaproj-aqua}/bin:$$PATH"'
66

77
proto:
8-
cd plugin/proto; \
8+
cd plugin/internal/proto; \
99
protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative tflint.proto

README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ NOTE: This plugin system is experimental. This means that API compatibility is f
1717

1818
Please refer to [tflint-ruleset-template](https://github.com/terraform-linters/tflint-ruleset-template) for an example plugin implementation using this SDK.
1919

20-
For more details on the API, see [tflint](https://pkg.go.dev/github.com/terraform-linters/tflint-plugin-sdk/tflint) and [helper](https://pkg.go.dev/github.com/terraform-linters/tflint-plugin-sdk/helper) packages on pkg.go.dev.
20+
For more details on the API, see https://pkg.go.dev/github.com/terraform-linters/tflint-plugin-sdk.
2121

2222
## Developing
2323

@@ -41,10 +41,8 @@ $ make proto
4141

4242
## Architecture
4343

44-
![architecture](architecture.png)
45-
46-
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.
44+
This plugin system uses [go-plugin](https://github.com/hashicorp/go-plugin). TFLint launch plugins as sub-processes and communicates with plugins over gRPC. A plugin acts as a server, while TFLint acts as a client that sends inspection requests to the plugin.
4745

4846
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.
4947

50-
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.
48+
This SDK provides client, server and Protocol Buffers for these bi-directional communications. See [Architecture](https://github.com/terraform-linters/tflint/blob/master/docs/developer-guide/architecture.md) for more details.

architecture.png

-33.3 KB
Binary file not shown.

plugin/doc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
// A plugin is implemented as an gRPC server and the host acts
55
// as the client, sending analysis requests to the plugin.
66
//
7-
// See host2plugin for implementation details.
7+
// See internal/host2plugin for implementation details.
88
package plugin

plugin/host2plugin/doc.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
// Package host2plugin contains a gRPC server (plugin) and client (host).
1+
// Package host2plugin exposes a gRPC client for use on a host (TFLint).
22
//
3-
// In the plugin system, this communication is the first thing that happens,
4-
// and a plugin must use this package to provide a gRPC server.
5-
// However, the detailed implementation is hidden in the tflint.RuleSet interface,
6-
// and plugin developers usually don't need to be aware of gRPC server behavior.
7-
//
8-
// When the host initializes a gRPC client, go-plugin starts a gRPC server
9-
// on the plugin side as another process. This package acts as a wrapper for go-plugin.
10-
// Separately, the Check function initializes a new gRPC client for plugin-to-host
11-
// communication. See the plugin2host package for details.
3+
// The implementation details are hidden in internal/host2plugin and
4+
// the exposed ones are minimal. They are not intended to be used by plugins.
5+
// For that reason, this package is subject to breaking changes without notice,
6+
// and the changes do not follow the SDK versioning policy.
127
package host2plugin

plugin/host2plugin/host2plugin.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package host2plugin
2+
3+
import "github.com/terraform-linters/tflint-plugin-sdk/plugin/internal/host2plugin"
4+
5+
// Client is a host-side implementation. Host can send requests through the client to plugin's gRPC server.
6+
type Client = host2plugin.GRPCClient
7+
8+
// ClientOpts is an option for initializing a Client.
9+
type ClientOpts = host2plugin.ClientOpts
10+
11+
// NewClient returns a new gRPC client for host-to-plugin communication.
12+
var NewClient = host2plugin.NewClient
File renamed without changes.

plugin/fromproto/fromproto.go renamed to plugin/internal/fromproto/fromproto.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ 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/plugin/proto"
9+
"github.com/terraform-linters/tflint-plugin-sdk/plugin/internal/proto"
1010
"github.com/terraform-linters/tflint-plugin-sdk/terraform/lang/marks"
1111
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
1212
"github.com/zclconf/go-cty/cty"

plugin/host2plugin/client.go renamed to plugin/internal/host2plugin/client.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import (
88
"github.com/hashicorp/go-version"
99
"github.com/terraform-linters/tflint-plugin-sdk/hclext"
1010
"github.com/terraform-linters/tflint-plugin-sdk/logger"
11-
"github.com/terraform-linters/tflint-plugin-sdk/plugin/fromproto"
12-
"github.com/terraform-linters/tflint-plugin-sdk/plugin/interceptor"
13-
"github.com/terraform-linters/tflint-plugin-sdk/plugin/plugin2host"
14-
"github.com/terraform-linters/tflint-plugin-sdk/plugin/proto"
15-
"github.com/terraform-linters/tflint-plugin-sdk/plugin/toproto"
11+
"github.com/terraform-linters/tflint-plugin-sdk/plugin/internal/fromproto"
12+
"github.com/terraform-linters/tflint-plugin-sdk/plugin/internal/interceptor"
13+
"github.com/terraform-linters/tflint-plugin-sdk/plugin/internal/plugin2host"
14+
"github.com/terraform-linters/tflint-plugin-sdk/plugin/internal/proto"
15+
"github.com/terraform-linters/tflint-plugin-sdk/plugin/internal/toproto"
1616
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
1717
"google.golang.org/grpc"
1818
)

plugin/internal/host2plugin/doc.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Package host2plugin contains a gRPC server (plugin) and client (host).
2+
//
3+
// In the plugin system, this communication is the first thing that happens,
4+
// and a plugin must use this package to provide a gRPC server.
5+
// However, the detailed implementation is hidden in the tflint.RuleSet interface,
6+
// and plugin developers usually don't need to be aware of gRPC server behavior.
7+
//
8+
// When the host initializes a gRPC client, go-plugin starts a gRPC server
9+
// on the plugin side as another process. This package acts as a wrapper for go-plugin.
10+
// Separately, the Check function initializes a new gRPC client for plugin-to-host
11+
// communication. See the plugin2host package for details.
12+
package host2plugin

0 commit comments

Comments
 (0)