MCPcopy Create free account
hub / github.com/coder/coder / Parse

Method Parse

provisioner/terraform/parse.go:22–47  ·  view source on GitHub ↗

Parse extracts Terraform variables from source-code. TODO: This Parse is incomplete. It uses tfparse instead of terraform. The inputs are incomplete, as values such as the user context, parameters, etc are all important to the parsing process. This should be replaced with preview and have all inputs

(sess *provisionersdk.Session, _ *proto.ParseRequest, _ <-chan struct{})

Source from the content-addressed store, hash-verified

20// etc are all important to the parsing process. This should be replaced with
21// preview and have all inputs.
22func (s *server) Parse(sess *provisionersdk.Session, _ *proto.ParseRequest, _ <-chan struct{}) *proto.ParseComplete {
23 ctx := sess.Context()
24 _, span := s.startTrace(ctx, tracing.FuncName())
25 defer span.End()
26
27 // Load the module and print any parse errors.
28 parser, diags := tfparse.New(sess.Files.WorkDirectory(), tfparse.WithLogger(s.logger.Named("tfparse")))
29 if diags.HasErrors() {
30 return provisionersdk.ParseErrorf("load module: %s", formatDiagnostics(sess.Files.WorkDirectory(), diags))
31 }
32
33 workspaceTags, _, err := parser.WorkspaceTags(ctx)
34 if err != nil {
35 return provisionersdk.ParseErrorf("can't load workspace tags: %v", err)
36 }
37
38 templateVariables, err := parser.TemplateVariables()
39 if err != nil {
40 return provisionersdk.ParseErrorf("can't load template variables: %v", err)
41 }
42
43 return &proto.ParseComplete{
44 TemplateVariables: templateVariables,
45 WorkspaceTags: workspaceTags,
46 }
47}
48
49// FormatDiagnostics returns a nicely formatted string containing all of the
50// error details within the tfconfig.Diagnostics. We need to use this because

Callers

nothing calls this directly

Calls 11

startTraceMethod · 0.95
FuncNameFunction · 0.92
NewFunction · 0.92
WithLoggerFunction · 0.92
ParseErrorfFunction · 0.92
formatDiagnosticsFunction · 0.85
WorkDirectoryMethod · 0.80
NamedMethod · 0.80
WorkspaceTagsMethod · 0.80
TemplateVariablesMethod · 0.80
ContextMethod · 0.65

Tested by

no test coverage detected