MCPcopy Index your code
hub / github.com/coder/coder / runTemplateDryRun

Method runTemplateDryRun

provisionerd/runner/runner.go:760–828  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

758}
759
760func (r *Runner) runTemplateDryRun(ctx context.Context) (*proto.CompletedJob, *proto.FailedJob) {
761 ctx, span := r.startTrace(ctx, tracing.FuncName())
762 defer span.End()
763
764 // Ensure all metadata fields are set as they are all optional for dry-run.
765 metadata := r.job.GetTemplateDryRun().GetMetadata()
766 metadata.WorkspaceTransition = sdkproto.WorkspaceTransition_START
767 if metadata.CoderUrl == "" {
768 metadata.CoderUrl = "http://localhost:3000"
769 }
770 if metadata.WorkspaceName == "" {
771 metadata.WorkspaceName = "dryrun"
772 }
773 metadata.WorkspaceOwner = r.job.UserName
774 if metadata.WorkspaceOwner == "" {
775 metadata.WorkspaceOwner = "dryrunner"
776 }
777 if metadata.WorkspaceId == "" {
778 id, err := uuid.NewRandom()
779 if err != nil {
780 return nil, r.failedJobf("generate random ID: %s", err)
781 }
782 metadata.WorkspaceId = id.String()
783 }
784 if metadata.WorkspaceOwnerId == "" {
785 id, err := uuid.NewRandom()
786 if err != nil {
787 return nil, r.failedJobf("generate random ID: %s", err)
788 }
789 metadata.WorkspaceOwnerId = id.String()
790 }
791
792 failedJob := r.configure(&sdkproto.Config{})
793 if failedJob != nil {
794 return nil, failedJob
795 }
796
797 // Initialize the Terraform working directory
798 initResp, failedJob := r.init(ctx, false, r.job.GetTemplateSourceArchive(), nil)
799 if failedJob != nil {
800 return nil, failedJob
801 }
802 if initResp == nil {
803 return nil, r.failedJobf("template dry-run init returned nil response")
804 }
805 if initResp.Error != "" {
806 return nil, r.failedJobf("template dry-run init error: %s", initResp.Error)
807 }
808
809 // Run the template import provision task since it's already a dry run.
810 provision, err := r.runTemplateImportProvisionWithRichParameters(ctx,
811 r.job.GetTemplateDryRun().GetVariableValues(),
812 r.job.GetTemplateDryRun().GetRichParameterValues(),
813 metadata,
814 )
815 if err != nil {
816 return nil, r.failedJobf("run dry-run provision job: %s", err)
817 }

Callers 1

doMethod · 0.95

Calls 12

startTraceMethod · 0.95
failedJobfMethod · 0.95
configureMethod · 0.95
initMethod · 0.95
FuncNameFunction · 0.92
GetMetadataMethod · 0.45
GetTemplateDryRunMethod · 0.45
StringMethod · 0.45
GetVariableValuesMethod · 0.45

Tested by

no test coverage detected