(ctx context.Context)
| 520 | } |
| 521 | |
| 522 | func (r *Runner) runTemplateImport(ctx context.Context) (*proto.CompletedJob, *proto.FailedJob) { |
| 523 | ctx, span := r.startTrace(ctx, tracing.FuncName()) |
| 524 | defer span.End() |
| 525 | |
| 526 | failedJob := r.configure(&sdkproto.Config{ |
| 527 | TemplateId: strings2.EmptyToNil(r.job.GetTemplateImport().Metadata.TemplateId), |
| 528 | TemplateVersionId: strings2.EmptyToNil(r.job.GetTemplateImport().Metadata.TemplateVersionId), |
| 529 | }) |
| 530 | if failedJob != nil { |
| 531 | return nil, failedJob |
| 532 | } |
| 533 | |
| 534 | // Initialize the Terraform working directory |
| 535 | initResp, failedInit := r.init(ctx, false, r.job.GetTemplateSourceArchive(), nil) |
| 536 | if failedInit != nil { |
| 537 | return nil, failedInit |
| 538 | } |
| 539 | if initResp == nil { |
| 540 | return nil, r.failedJobf("template import init returned nil response") |
| 541 | } |
| 542 | if initResp.Error != "" { |
| 543 | return nil, r.failedJobf("template import init error: %s", initResp.Error) |
| 544 | } |
| 545 | |
| 546 | // Parse parameters and update the job with the parameter specs |
| 547 | r.queueLog(ctx, &proto.Log{ |
| 548 | Source: proto.LogSource_PROVISIONER_DAEMON, |
| 549 | Level: sdkproto.LogLevel_INFO, |
| 550 | Stage: "Parsing template parameters", |
| 551 | CreatedAt: time.Now().UnixMilli(), |
| 552 | }) |
| 553 | workspaceTags, templateVariables, readme, err := r.runTemplateImportParse(ctx) // TODO workspace_tags |
| 554 | if err != nil { |
| 555 | return nil, r.failedJobf("run parse: %s", err) |
| 556 | } |
| 557 | |
| 558 | // Once Terraform template variables are parsed, the runner can pass variables |
| 559 | // to store in database and filter valid ones. |
| 560 | updateResponse, err := r.update(ctx, &proto.UpdateJobRequest{ |
| 561 | JobId: r.job.JobId, |
| 562 | TemplateVariables: templateVariables, |
| 563 | UserVariableValues: r.job.GetTemplateImport().GetUserVariableValues(), |
| 564 | Readme: readme, |
| 565 | WorkspaceTags: workspaceTags, |
| 566 | }) |
| 567 | if err != nil { |
| 568 | return nil, r.failedJobf("update job: %s", err) |
| 569 | } |
| 570 | |
| 571 | // Determine persistent resources |
| 572 | r.queueLog(ctx, &proto.Log{ |
| 573 | Source: proto.LogSource_PROVISIONER_DAEMON, |
| 574 | Level: sdkproto.LogLevel_INFO, |
| 575 | Stage: "Detecting persistent resources", |
| 576 | CreatedAt: time.Now().UnixMilli(), |
| 577 | }) |
| 578 | startProvision, err := r.runTemplateImportProvision(ctx, updateResponse.VariableValues, &sdkproto.Metadata{ |
| 579 | CoderUrl: r.job.GetTemplateImport().Metadata.CoderUrl, |
no test coverage detected