( ctx, killCtx context.Context, env []string, logr logSink, )
| 514 | } |
| 515 | |
| 516 | func (e *executor) apply( |
| 517 | ctx, killCtx context.Context, |
| 518 | env []string, |
| 519 | logr logSink, |
| 520 | ) (*proto.ApplyComplete, error) { |
| 521 | ctx, span := e.server.startTrace(ctx, tracing.FuncName()) |
| 522 | defer span.End() |
| 523 | |
| 524 | e.mut.Lock() |
| 525 | defer e.mut.Unlock() |
| 526 | |
| 527 | args := []string{ |
| 528 | "apply", |
| 529 | "-no-color", |
| 530 | "-auto-approve", |
| 531 | "-input=false", |
| 532 | "-json", |
| 533 | e.files.PlanFilePath(), |
| 534 | } |
| 535 | |
| 536 | outWriter, doneOut := e.provisionLogWriter(logr) |
| 537 | errWriter, doneErr := logWriter(logr, proto.LogLevel_ERROR) |
| 538 | defer func() { |
| 539 | _ = outWriter.Close() |
| 540 | _ = errWriter.Close() |
| 541 | <-doneOut |
| 542 | <-doneErr |
| 543 | }() |
| 544 | |
| 545 | // `terraform apply` |
| 546 | err := e.execWriteOutput(ctx, killCtx, args, env, outWriter, errWriter) |
| 547 | if err != nil { |
| 548 | return nil, xerrors.Errorf("terraform apply: %w", err) |
| 549 | } |
| 550 | |
| 551 | statefilePath := e.files.StateFilePath() |
| 552 | stateContent, err := os.ReadFile(statefilePath) |
| 553 | if err != nil { |
| 554 | return nil, xerrors.Errorf("read statefile %q: %w", statefilePath, err) |
| 555 | } |
| 556 | |
| 557 | return &proto.ApplyComplete{ |
| 558 | State: stateContent, |
| 559 | }, nil |
| 560 | } |
| 561 | |
| 562 | // state must only be called while the lock is held. |
| 563 | func (e *executor) state(ctx, killCtx context.Context) (*tfjson.State, error) { |
no test coverage detected