Add support for gRPC server for the new plugin system #1292
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
See also terraform-linters/tflint-plugin-sdk#135
This PR adds support for gRPC server for the new plugin system. See terraform-linters/tflint-plugin-sdk#135 for motivation and purpose for this transition. The gRPC server implements:
GetModuleContent
Attributes()
,Blocks()
,Resources()
,ModuleCalls()
,Backend()
,Config()
, andRootProvider()
methods. Returns a module content based on the passed schema. The interface is inspired by the hcl package. Also, by taking a module context, you can now access the root module in the same way.GetFile
File()
method.GetFiles
Files()
method. Newly, this method takes a module context and can return a list of files in the root module.GetRuleConfigContent
RuleConfig()
method. This method takes a schema as an argument, and now you can get attributes more flexibly.EvaluateExpr
EvalExpr()
,EvalExprOnRootCtx()
, andIsNullExpr()
methods. Supports evaluation of the root module by taking a module context as an argument. We also addedcty.DynamicPseudoType
as a valid type, which allows decoding tocty.Value
. Therefore,IsNullExpr
has been removed (you can decode tocty.Value
from expr, and check the return value ofcty.Value.IsNull()
).EmitIssue
EmitIssue()
. Unlike before, it does not request the expr that caused the issue. Instead, the range of the issue determines if it is occurring on the expr.The biggest change is support for
GetModuleContent
. Previously, we used Terraform's internal packages to get attributes and blocks fromconfigs.Config
, but this should be avoided for the purposes of this transition. To achieve this,GetModuleContent
gets the attributes and blocks based on the schema from thehcl.File
parsed in the standard way.Some Terraform language semantics need to be reproduced to eliminate the dependency on Terraform internal packages. Here, the following is reimplemented:
count
/for_each
meta-argumentsUnlike in a previous way, these are not decoded in advance but are decoded and resolved at the time of getting contents. In particular, dynamic blocks need to be resolved recursively, so performance degradation is expected. However, performance issues are left here as future improvements.
These implementations exist in
Runner
, but this is obviously not a good idea. Perhaps it should be implemented in another layer likeLoader
. However, here I dare to implement it this way to minimize changes. Refactoring, including removing the net/rpc-based implementation, will be done later.Also, in the new SDK, the
tflint.Error
has been removed and standard error wrapping (fmt.Errorf("%w", err)
) has been adopted. Along with that, custom errors have been removed from TFLint as well. Others include following breaking changes in the SDK, such as changing the rule severity from a string to an enum.