|
8 | 8 | "time"
|
9 | 9 |
|
10 | 10 | "github.com/google/uuid"
|
| 11 | +"github.com/hashicorp/hcl/v2" |
11 | 12 | "golang.org/x/sync/errgroup"
|
12 | 13 | "golang.org/x/xerrors"
|
13 | 14 |
|
@@ -79,11 +80,21 @@ func (api *API) templateVersionDynamicParameters(rw http.ResponseWriter, r *http
|
79 | 80 | }
|
80 | 81 | deferapi.FileCache.Release(fileID)
|
81 | 82 |
|
| 83 | +staticDiagnostics:= hcl.Diagnostics{} |
| 84 | + |
82 | 85 | // Having the Terraform plan available for the evaluation engine is helpful
|
83 | 86 | // for populating values from data blocks, but isn't strictly required. If
|
84 | 87 | // we don't have a cached plan available, we just use an empty one instead.
|
85 | 88 | plan:=json.RawMessage("{}")
|
86 | 89 | tf,err:=api.Database.GetTemplateVersionTerraformValues(ctx,templateVersion.ID)
|
| 90 | +ifxerrors.Is(err,sql.ErrNoRows) { |
| 91 | +staticDiagnostics.Append(&hcl.Diagnostic{ |
| 92 | +Severity:hcl.DiagWarning, |
| 93 | +Summary:"This template version is missing required metadata to support dynamic parameters.", |
| 94 | +Detail:"To restore full functionality, please re-import the terraform as a new template version.", |
| 95 | +}) |
| 96 | +} |
| 97 | + |
87 | 98 | iferr==nil {
|
88 | 99 | plan=tf.CachedPlan
|
89 | 100 |
|
@@ -148,7 +159,7 @@ func (api *API) templateVersionDynamicParameters(rw http.ResponseWriter, r *http
|
148 | 159 | result,diagnostics:=preview.Preview(ctx,input,templateFS)
|
149 | 160 | response:= codersdk.DynamicParametersResponse{
|
150 | 161 | ID:-1,
|
151 |
| -Diagnostics:previewtypes.Diagnostics(diagnostics), |
| 162 | +Diagnostics:previewtypes.Diagnostics(diagnostics.Extend(staticDiagnostics)), |
152 | 163 | }
|
153 | 164 | ifresult!=nil {
|
154 | 165 | response.Parameters=result.Parameters
|
@@ -176,7 +187,7 @@ func (api *API) templateVersionDynamicParameters(rw http.ResponseWriter, r *http
|
176 | 187 | result,diagnostics:=preview.Preview(ctx,input,templateFS)
|
177 | 188 | response:= codersdk.DynamicParametersResponse{
|
178 | 189 | ID:update.ID,
|
179 |
| -Diagnostics:previewtypes.Diagnostics(diagnostics), |
| 190 | +Diagnostics:previewtypes.Diagnostics(diagnostics.Extend(staticDiagnostics)), |
180 | 191 | }
|
181 | 192 | ifresult!=nil {
|
182 | 193 | response.Parameters=result.Parameters
|
|