Skip to content

Commit

Permalink
Internalize unnecessarily published plugin packages (#273)
Browse files Browse the repository at this point in the history
  • Loading branch information
wata727 authored Jul 29, 2023
1 parent 54455dd commit ee6dcd7
Show file tree
Hide file tree
Showing 28 changed files with 86 additions and 53 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ prepare:
@echo 'export PATH="$${AQUA_ROOT_DIR:-$${XDG_DATA_HOME:-$$HOME/.local/share}/aquaproj-aqua}/bin:$$PATH"'

proto:
cd plugin/proto; \
cd plugin/internal/proto; \
protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative tflint.proto
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ NOTE: This plugin system is experimental. This means that API compatibility is f

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

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.
For more details on the API, see https://pkg.go.dev/github.com/terraform-linters/tflint-plugin-sdk.

## Developing

Expand All @@ -41,10 +41,8 @@ $ make proto

## Architecture

![architecture](architecture.png)

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

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.

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.
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.
Binary file removed architecture.png
Binary file not shown.
2 changes: 1 addition & 1 deletion plugin/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
// A plugin is implemented as an gRPC server and the host acts
// as the client, sending analysis requests to the plugin.
//
// See host2plugin for implementation details.
// See internal/host2plugin for implementation details.
package plugin
15 changes: 5 additions & 10 deletions plugin/host2plugin/doc.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
// Package host2plugin contains a gRPC server (plugin) and client (host).
// Package host2plugin exposes a gRPC client for use on a host (TFLint).
//
// In the plugin system, this communication is the first thing that happens,
// and a plugin must use this package to provide a gRPC server.
// However, the detailed implementation is hidden in the tflint.RuleSet interface,
// and plugin developers usually don't need to be aware of gRPC server behavior.
//
// When the host initializes a gRPC client, go-plugin starts a gRPC server
// on the plugin side as another process. This package acts as a wrapper for go-plugin.
// Separately, the Check function initializes a new gRPC client for plugin-to-host
// communication. See the plugin2host package for details.
// The implementation details are hidden in internal/host2plugin and
// the exposed ones are minimal. They are not intended to be used by plugins.
// For that reason, this package is subject to breaking changes without notice,
// and the changes do not follow the SDK versioning policy.
package host2plugin
12 changes: 12 additions & 0 deletions plugin/host2plugin/host2plugin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package host2plugin

import "github.com/terraform-linters/tflint-plugin-sdk/plugin/internal/host2plugin"

// Client is a host-side implementation. Host can send requests through the client to plugin's gRPC server.
type Client = host2plugin.GRPCClient

// ClientOpts is an option for initializing a Client.
type ClientOpts = host2plugin.ClientOpts

// NewClient returns a new gRPC client for host-to-plugin communication.
var NewClient = host2plugin.NewClient
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/hashicorp/hcl/v2"
"github.com/terraform-linters/tflint-plugin-sdk/hclext"
"github.com/terraform-linters/tflint-plugin-sdk/plugin/proto"
"github.com/terraform-linters/tflint-plugin-sdk/plugin/internal/proto"
"github.com/terraform-linters/tflint-plugin-sdk/terraform/lang/marks"
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
"github.com/zclconf/go-cty/cty"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import (
"github.com/hashicorp/go-version"
"github.com/terraform-linters/tflint-plugin-sdk/hclext"
"github.com/terraform-linters/tflint-plugin-sdk/logger"
"github.com/terraform-linters/tflint-plugin-sdk/plugin/fromproto"
"github.com/terraform-linters/tflint-plugin-sdk/plugin/interceptor"
"github.com/terraform-linters/tflint-plugin-sdk/plugin/plugin2host"
"github.com/terraform-linters/tflint-plugin-sdk/plugin/proto"
"github.com/terraform-linters/tflint-plugin-sdk/plugin/toproto"
"github.com/terraform-linters/tflint-plugin-sdk/plugin/internal/fromproto"
"github.com/terraform-linters/tflint-plugin-sdk/plugin/internal/interceptor"
"github.com/terraform-linters/tflint-plugin-sdk/plugin/internal/plugin2host"
"github.com/terraform-linters/tflint-plugin-sdk/plugin/internal/proto"
"github.com/terraform-linters/tflint-plugin-sdk/plugin/internal/toproto"
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
"google.golang.org/grpc"
)
Expand Down
12 changes: 12 additions & 0 deletions plugin/internal/host2plugin/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Package host2plugin contains a gRPC server (plugin) and client (host).
//
// In the plugin system, this communication is the first thing that happens,
// and a plugin must use this package to provide a gRPC server.
// However, the detailed implementation is hidden in the tflint.RuleSet interface,
// and plugin developers usually don't need to be aware of gRPC server behavior.
//
// When the host initializes a gRPC client, go-plugin starts a gRPC server
// on the plugin side as another process. This package acts as a wrapper for go-plugin.
// Separately, the Check function initializes a new gRPC client for plugin-to-host
// communication. See the plugin2host package for details.
package host2plugin
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/hashicorp/hcl/v2"
"github.com/hashicorp/hcl/v2/hclsyntax"
"github.com/terraform-linters/tflint-plugin-sdk/hclext"
"github.com/terraform-linters/tflint-plugin-sdk/plugin/plugin2host"
"github.com/terraform-linters/tflint-plugin-sdk/plugin/internal/plugin2host"
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
"github.com/zclconf/go-cty/cty"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"

plugin "github.com/hashicorp/go-plugin"
"github.com/terraform-linters/tflint-plugin-sdk/plugin/proto"
"github.com/terraform-linters/tflint-plugin-sdk/plugin/internal/proto"
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
"google.golang.org/grpc"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import (
"github.com/hashicorp/go-plugin"
"github.com/terraform-linters/tflint-plugin-sdk/internal"
"github.com/terraform-linters/tflint-plugin-sdk/logger"
"github.com/terraform-linters/tflint-plugin-sdk/plugin/fromproto"
"github.com/terraform-linters/tflint-plugin-sdk/plugin/interceptor"
"github.com/terraform-linters/tflint-plugin-sdk/plugin/plugin2host"
"github.com/terraform-linters/tflint-plugin-sdk/plugin/proto"
"github.com/terraform-linters/tflint-plugin-sdk/plugin/toproto"
"github.com/terraform-linters/tflint-plugin-sdk/plugin/internal/fromproto"
"github.com/terraform-linters/tflint-plugin-sdk/plugin/internal/interceptor"
"github.com/terraform-linters/tflint-plugin-sdk/plugin/internal/plugin2host"
"github.com/terraform-linters/tflint-plugin-sdk/plugin/internal/proto"
"github.com/terraform-linters/tflint-plugin-sdk/plugin/internal/toproto"
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import (
"github.com/terraform-linters/tflint-plugin-sdk/hclext"
"github.com/terraform-linters/tflint-plugin-sdk/internal"
"github.com/terraform-linters/tflint-plugin-sdk/logger"
"github.com/terraform-linters/tflint-plugin-sdk/plugin/fromproto"
"github.com/terraform-linters/tflint-plugin-sdk/plugin/proto"
"github.com/terraform-linters/tflint-plugin-sdk/plugin/toproto"
"github.com/terraform-linters/tflint-plugin-sdk/plugin/internal/fromproto"
"github.com/terraform-linters/tflint-plugin-sdk/plugin/internal/proto"
"github.com/terraform-linters/tflint-plugin-sdk/plugin/internal/toproto"
"github.com/terraform-linters/tflint-plugin-sdk/terraform/addrs"
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
"github.com/zclconf/go-cty/cty"
Expand Down
12 changes: 12 additions & 0 deletions plugin/internal/plugin2host/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Package plugin2host contains a gRPC server (host) and client (plugin).
//
// Communication from the plugin to the host is the second one that occurs.
// To understand what happens first, see the host2plugin package first.
// The gRPC client used by the plugin is implicitly initialized by the host2plugin
// package and hidden in the tflint.Runner interface. Normally, plugin developers
// do not need to be aware of the details of this client.
//
// The host starts a gRPC server as goroutine to respond from the plugin side
// when calling Check function in host2plugin. Please note that the gRPC server
// and client startup in plugin2host is not due to go-plugin.
package plugin2host
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/hashicorp/hcl/v2/json"
"github.com/terraform-linters/tflint-plugin-sdk/hclext"
"github.com/terraform-linters/tflint-plugin-sdk/internal"
"github.com/terraform-linters/tflint-plugin-sdk/plugin/proto"
"github.com/terraform-linters/tflint-plugin-sdk/plugin/internal/proto"
"github.com/terraform-linters/tflint-plugin-sdk/terraform/addrs"
"github.com/terraform-linters/tflint-plugin-sdk/terraform/lang/marks"
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (

"github.com/hashicorp/hcl/v2"
"github.com/terraform-linters/tflint-plugin-sdk/hclext"
"github.com/terraform-linters/tflint-plugin-sdk/plugin/fromproto"
"github.com/terraform-linters/tflint-plugin-sdk/plugin/proto"
"github.com/terraform-linters/tflint-plugin-sdk/plugin/toproto"
"github.com/terraform-linters/tflint-plugin-sdk/plugin/internal/fromproto"
"github.com/terraform-linters/tflint-plugin-sdk/plugin/internal/proto"
"github.com/terraform-linters/tflint-plugin-sdk/plugin/internal/toproto"
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
"github.com/zclconf/go-cty/cty"
"github.com/zclconf/go-cty/cty/json"
Expand Down
File renamed without changes.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
syntax = "proto3";
option go_package = "github.com/terraform-linters/tflint-plugin-sdk/plugin/proto";
option go_package = "github.com/terraform-linters/tflint-plugin-sdk/plugin/internal/proto";

package proto;

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/hashicorp/hcl/v2"
"github.com/terraform-linters/tflint-plugin-sdk/hclext"
"github.com/terraform-linters/tflint-plugin-sdk/plugin/proto"
"github.com/terraform-linters/tflint-plugin-sdk/plugin/internal/proto"
"github.com/terraform-linters/tflint-plugin-sdk/terraform/lang/marks"
"github.com/terraform-linters/tflint-plugin-sdk/tflint"
"github.com/zclconf/go-cty/cty"
Expand Down
5 changes: 4 additions & 1 deletion plugin/plugin.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package plugin

import (
"github.com/terraform-linters/tflint-plugin-sdk/plugin/host2plugin"
"github.com/terraform-linters/tflint-plugin-sdk/plugin/internal/host2plugin"

// Import this package to initialize the global logger
_ "github.com/terraform-linters/tflint-plugin-sdk/logger"
Expand All @@ -13,3 +13,6 @@ type ServeOpts = host2plugin.ServeOpts

// Serve is a wrapper of plugin.Serve. This is entrypoint of all plugins.
var Serve = host2plugin.Serve

// SDKVersion is the SDK version.
const SDKVersion = host2plugin.SDKVersion
15 changes: 5 additions & 10 deletions plugin/plugin2host/doc.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
// Package plugin2host contains a gRPC server (host) and client (plugin).
// Package plugin2host exposes a gRPC server for use on a host (TFLint).
//
// Communication from the plugin to the host is the second one that occurs.
// To understand what happens first, see the host2plugin package first.
// The gRPC client used by the plugin is implicitly initialized by the host2plugin
// package and hidden in the tflint.Runner interface. Normally, plugin developers
// do not need to be aware of the details of this client.
//
// The host starts a gRPC server as goroutine to respond from the plugin side
// when calling Check function in host2plugin. Please note that the gRPC server
// and client startup in plugin2host is not due to go-plugin.
// The implementation details are hidden in internal/plugin2host and
// the exposed ones are minimal. They are not intended to be used by plugins.
// For that reason, this package is subject to breaking changes without notice,
// and the changes do not follow the SDK versioning policy.
package plugin2host
6 changes: 6 additions & 0 deletions plugin/plugin2host/plugin2host.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package plugin2host

import "github.com/terraform-linters/tflint-plugin-sdk/plugin/internal/plugin2host"

// Server is the interface that the host should implement when a plugin communicates with the host.
type Server = plugin2host.Server

0 comments on commit ee6dcd7

Please sign in to comment.