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{})
| 20 | // etc are all important to the parsing process. This should be replaced with |
| 21 | // preview and have all inputs. |
| 22 | func (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 |
nothing calls this directly
no test coverage detected