( ctx context.Context, db database.Store, prebuildID uuid.UUID, template database.Template, presetID uuid.UUID, transition database.WorkspaceTransition, workspace database.Workspace, mode DeprovisionMode, )
| 1079 | } |
| 1080 | |
| 1081 | func (c *StoreReconciler) provision( |
| 1082 | ctx context.Context, |
| 1083 | db database.Store, |
| 1084 | prebuildID uuid.UUID, |
| 1085 | template database.Template, |
| 1086 | presetID uuid.UUID, |
| 1087 | transition database.WorkspaceTransition, |
| 1088 | workspace database.Workspace, |
| 1089 | mode DeprovisionMode, |
| 1090 | ) (*database.ProvisionerJob, error) { |
| 1091 | ctx, span := c.tracer.Start(ctx, "prebuilds.provision", trace.WithAttributes( |
| 1092 | attribute.String("prebuild_id", prebuildID.String()), |
| 1093 | attribute.String("template_id", template.ID.String()), |
| 1094 | attribute.String("preset_id", presetID.String()), |
| 1095 | attribute.String("transition", string(transition)), |
| 1096 | attribute.String("workspace_id", workspace.ID.String()), |
| 1097 | attribute.String("mode", mode.String()), |
| 1098 | )) |
| 1099 | defer span.End() |
| 1100 | |
| 1101 | tvp, err := db.GetPresetParametersByTemplateVersionID(ctx, template.ActiveVersionID) |
| 1102 | if err != nil { |
| 1103 | return nil, xerrors.Errorf("fetch preset details: %w", err) |
| 1104 | } |
| 1105 | |
| 1106 | var params []codersdk.WorkspaceBuildParameter |
| 1107 | for _, param := range tvp { |
| 1108 | // TODO: don't fetch in the first place. |
| 1109 | if param.TemplateVersionPresetID != presetID { |
| 1110 | continue |
| 1111 | } |
| 1112 | |
| 1113 | params = append(params, codersdk.WorkspaceBuildParameter{ |
| 1114 | Name: param.Name, |
| 1115 | Value: param.Value, |
| 1116 | }) |
| 1117 | } |
| 1118 | |
| 1119 | builder := wsbuilder.New(workspace, transition, *c.buildUsageChecker.Load()). |
| 1120 | Reason(database.BuildReasonInitiator). |
| 1121 | Initiator(database.PrebuildsSystemUserID). |
| 1122 | MarkPrebuild(). |
| 1123 | BuildMetrics(c.workspaceBuilderMetrics) |
| 1124 | |
| 1125 | if transition != database.WorkspaceTransitionDelete { |
| 1126 | // We don't specify the version for a delete transition, |
| 1127 | // because the prebuilt workspace may have been created using an older template version. |
| 1128 | // If the version isn't explicitly set, the builder will automatically use the version |
| 1129 | // from the last workspace build — which is the desired behavior. |
| 1130 | builder = builder.VersionID(template.ActiveVersionID) |
| 1131 | |
| 1132 | // We only inject the required params when the prebuild is being created. |
| 1133 | // This mirrors the behavior of regular workspace deletion (see cli/delete.go). |
| 1134 | builder = builder.TemplateVersionPresetID(presetID) |
| 1135 | builder = builder.RichParameterValues(params) |
| 1136 | } |
| 1137 | |
| 1138 | // Use orphan mode for deletes when no Terraform resources exist |
no test coverage detected