graph must only be called while the lock is held.
(ctx, killCtx context.Context)
| 469 | |
| 470 | // graph must only be called while the lock is held. |
| 471 | func (e *executor) graph(ctx, killCtx context.Context) (string, error) { |
| 472 | ctx, span := e.server.startTrace(ctx, tracing.FuncName()) |
| 473 | defer span.End() |
| 474 | |
| 475 | if ctx.Err() != nil { |
| 476 | return "", ctx.Err() |
| 477 | } |
| 478 | |
| 479 | ver, err := e.version(ctx) |
| 480 | if err != nil { |
| 481 | return "", err |
| 482 | } |
| 483 | args := []string{ |
| 484 | "graph", |
| 485 | // TODO: When the plan is present, we should probably use it? |
| 486 | // "-plan=" + e.files.PlanFilePath(), |
| 487 | } |
| 488 | |
| 489 | if ver.GreaterThanOrEqual(version170) { |
| 490 | args = append(args, "-type=plan") |
| 491 | } |
| 492 | |
| 493 | var out strings.Builder |
| 494 | cmd := exec.CommandContext(killCtx, e.binaryPath, args...) // #nosec |
| 495 | cmd.Stdout = &out |
| 496 | cmd.Dir = e.files.WorkDirectory() |
| 497 | cmd.Env = e.basicEnv() |
| 498 | |
| 499 | e.server.logger.Debug(ctx, "executing terraform command graph", |
| 500 | slog.F("binary_path", e.binaryPath), |
| 501 | slog.F("args", "graph"), |
| 502 | ) |
| 503 | err = cmd.Start() |
| 504 | if err != nil { |
| 505 | return "", err |
| 506 | } |
| 507 | interruptCommandOnCancel(ctx, killCtx, e.logger, cmd) |
| 508 | |
| 509 | err = cmd.Wait() |
| 510 | if err != nil { |
| 511 | return "", xerrors.Errorf("graph: %w", err) |
| 512 | } |
| 513 | return out.String(), nil |
| 514 | } |
| 515 | |
| 516 | func (e *executor) apply( |
| 517 | ctx, killCtx context.Context, |
no test coverage detected