Skip to content

Commit

Permalink
Add support for gRPC server for the new plugin system
Browse files Browse the repository at this point in the history
  • Loading branch information
wata727 committed Jan 10, 2022
1 parent 607a47b commit 5cecedd
Show file tree
Hide file tree
Showing 16 changed files with 340 additions and 48 deletions.
24 changes: 22 additions & 2 deletions cmd/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,31 @@ func (cli *CLI) inspect(opts Options, dir string, filterFiles []string) int {

rulesets := []tflint.RuleSet{&rules.RuleSet{}}
for name, ruleset := range plugin.RuleSets {
err = ruleset.ApplyConfig(cfg.ToPluginConfig(name))
config, err := cfg.ToPluginConfig(name).Unmarshal()
if err != nil {
cli.formatter.Print(tflint.Issues{}, tflint.NewContextError("Failed to fetch config schema from plugins", err), cli.loader.Sources())
return ExitCodeError
}
if err := ruleset.ApplyGlobalConfig(config); err != nil {
cli.formatter.Print(tflint.Issues{}, tflint.NewContextError("Failed to fetch config schema from plugins", err), cli.loader.Sources())
return ExitCodeError
}
configSchema, err := ruleset.ConfigSchema()
if err != nil {
cli.formatter.Print(tflint.Issues{}, tflint.NewContextError("Failed to fetch config schema from plugins", err), cli.loader.Sources())
return ExitCodeError
}
content, diags := cfg.PluginContent(name, configSchema)
if diags.HasErrors() {
cli.formatter.Print(tflint.Issues{}, tflint.NewContextError("Failed to parse plugin config schema", diags), cli.loader.Sources())
return ExitCodeError
}
err = ruleset.ApplyConfig(content, cfg.Sources())
if err != nil {
cli.formatter.Print(tflint.Issues{}, tflint.NewContextError("Failed to apply config to plugins", err), cli.loader.Sources())
return ExitCodeError
}

rulesets = append(rulesets, ruleset)
}
if err := cfg.ValidateRules(rulesets...); err != nil {
Expand All @@ -95,7 +115,7 @@ func (cli *CLI) inspect(opts Options, dir string, filterFiles []string) int {

for _, ruleset := range plugin.RuleSets {
for _, runner := range runners {
err = ruleset.Check(tfplugin.NewServer(runner, rootRunner, cli.loader.Sources()))
err = ruleset.Check(tfplugin.NewGRPCServer(runner, rootRunner, cli.loader.Sources()))
if err != nil {
cli.formatter.Print(tflint.Issues{}, tflint.NewContextError("Failed to check ruleset", err), cli.loader.Sources())
return ExitCodeError
Expand Down
2 changes: 0 additions & 2 deletions cmd/internal_aws_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/terraform-linters/tflint-ruleset-aws/aws"
"github.com/terraform-linters/tflint-ruleset-aws/project"
"github.com/terraform-linters/tflint-ruleset-aws/rules"
"github.com/terraform-linters/tflint-ruleset-aws/rules/api"
)

func (cli *CLI) actAsAwsPlugin() int {
Expand All @@ -19,7 +18,6 @@ func (cli *CLI) actAsAwsPlugin() int {
Version: fmt.Sprintf("%s-bundled", project.Version),
Rules: rules.Rules,
},
APIRules: api.Rules,
},
})

Expand Down
1 change: 1 addition & 0 deletions cmd/option_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ func Test_toConfig(t *testing.T) {
eqlopts := []cmp.Option{
cmpopts.IgnoreUnexported(tflint.RuleConfig{}),
cmpopts.IgnoreUnexported(tflint.PluginConfig{}),
cmpopts.IgnoreUnexported(tflint.Config{}),
}
if !cmp.Equal(tc.Expected, ret, eqlopts...) {
t.Fatalf("Failed `%s` test: diff=%s", tc.Name, cmp.Diff(tc.Expected, ret, eqlopts...))
Expand Down
14 changes: 7 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ require (
github.com/sourcegraph/jsonrpc2 v0.1.0
github.com/spf13/afero v1.7.0
github.com/stretchr/testify v1.7.0
github.com/terraform-linters/tflint-plugin-sdk v0.9.1
github.com/terraform-linters/tflint-ruleset-aws v0.10.1
github.com/terraform-linters/tflint-plugin-sdk v0.9.2-0.20220110085511-23d9a44a772d
github.com/terraform-linters/tflint-ruleset-aws v0.11.1-0.20220110095527-2965dc3212ef
github.com/xeipuuv/gojsonschema v1.2.0
github.com/zclconf/go-cty v1.10.0
github.com/zclconf/go-cty-yaml v1.0.2
golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616
golang.org/x/net v0.0.0-20210903162142-ad29c8ab022f
golang.org/x/net v0.0.0-20211216030914-fe4d6282115f
golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f
golang.org/x/text v0.3.7
)
Expand All @@ -47,11 +47,11 @@ require (
cloud.google.com/go v0.75.0 // indirect
cloud.google.com/go/storage v1.14.0 // indirect
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
github.com/aws/aws-sdk-go v1.42.19 // indirect
github.com/aws/aws-sdk-go v1.42.30 // indirect
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
github.com/golang/protobuf v1.4.3 // indirect
github.com/golang/protobuf v1.5.0 // indirect
github.com/google/go-querystring v1.0.0 // indirect
github.com/googleapis/gax-go/v2 v2.0.5 // indirect
github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8 // indirect
Expand Down Expand Up @@ -80,7 +80,7 @@ require (
google.golang.org/api v0.40.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20210226172003-ab064af71705 // indirect
google.golang.org/grpc v1.35.0 // indirect
google.golang.org/protobuf v1.25.0 // indirect
google.golang.org/grpc v1.41.0 // indirect
google.golang.org/protobuf v1.27.1 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
)
Loading

0 comments on commit 5cecedd

Please sign in to comment.