Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions plugin/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"log"
"sync"

"github.com/hashicorp/go-version"
hcl "github.com/hashicorp/hcl/v2"
Expand All @@ -17,6 +18,7 @@ import (

// GRPCServer is a gRPC server for responding to requests from plugins.
type GRPCServer struct {
mu sync.Mutex
runner *tflint.Runner
rootRunner *tflint.Runner
files map[string]*hcl.File
Expand Down Expand Up @@ -50,6 +52,8 @@ func (s *GRPCServer) GetModuleContent(bodyS *hclext.BodySchema, opts sdk.GetModu
module = s.runner.TFConfig.Module
ctx = s.runner.Ctx
case sdk.RootModuleCtxType:
s.mu.Lock()
defer s.mu.Unlock()
module = s.rootRunner.TFConfig.Module
ctx = s.rootRunner.Ctx
default:
Expand Down Expand Up @@ -87,6 +91,8 @@ func (s *GRPCServer) GetFiles(ty sdk.ModuleCtxType) map[string][]byte {
case sdk.SelfModuleCtxType:
return s.runner.Sources()
case sdk.RootModuleCtxType:
// HINT: This is an operation on the root runner,
// but it works without locking since it is obviously readonly.
return s.rootRunner.Sources()
default:
panic(fmt.Sprintf("invalid ModuleCtxType: %s", ty))
Expand Down Expand Up @@ -127,6 +133,8 @@ func (s *GRPCServer) EvaluateExpr(expr hcl.Expression, opts sdk.EvaluateExprOpti
case sdk.SelfModuleCtxType:
runner = s.runner
case sdk.RootModuleCtxType:
s.mu.Lock()
defer s.mu.Unlock()
runner = s.rootRunner
}

Expand Down
Loading