@@ -81,34 +81,14 @@ func (api *API) templateVersionDynamicParameters(rw http.ResponseWriter, r *http
81
81
}
82
82
defer api .FileCache .Release (fileID )
83
83
84
- staticDiagnostics := hcl.Diagnostics {}
85
- missingMetaData := hcl.Diagnostic {
86
- Severity : hcl .DiagWarning ,
87
- Summary : "This template version is missing required metadata to support dynamic parameters. Go back to the classic creation flow." ,
88
- Detail : "To restore full functionality, please re-import the terraform as a new template version." ,
89
- }
90
-
91
84
// Having the Terraform plan available for the evaluation engine is helpful
92
85
// for populating values from data blocks, but isn't strictly required. If
93
86
// we don't have a cached plan available, we just use an empty one instead.
94
87
plan := json .RawMessage ("{}" )
95
88
tf , err := api .Database .GetTemplateVersionTerraformValues (ctx , templateVersion .ID )
96
- if xerrors .Is (err , sql .ErrNoRows ) {
97
- staticDiagnostics = staticDiagnostics .Append (& missingMetaData )
98
- }
99
89
if err == nil {
100
90
plan = tf .CachedPlan
101
91
102
- major , minor , err := apiversion .Parse (tf .ProvisionerdVersion )
103
- if err != nil || tf .ProvisionerdVersion == "" {
104
- staticDiagnostics = staticDiagnostics .Append (& missingMetaData )
105
- } else if major < 1 || (major == 1 && minor < 5 ) {
106
- missingMetaData .Detail = "This template version requires provisioner v1.5 or newer to support dynamic parameters. " +
107
- "Some options may be missing or incorrect. " +
108
- "Please contact an administrator to update the provisioner and re-import the template version."
109
- staticDiagnostics = staticDiagnostics .Append (& missingMetaData )
110
- }
111
-
112
92
if tf .CachedModuleFiles .Valid {
113
93
moduleFilesFS , err := api .FileCache .Acquire (fileCtx , tf .CachedModuleFiles .UUID )
114
94
if err != nil {
@@ -136,6 +116,10 @@ func (api *API) templateVersionDynamicParameters(rw http.ResponseWriter, r *http
136
116
return
137
117
}
138
118
119
+ var staticDiagnostics hcl.Diagnostics
120
+ // If the err is sql.ErrNoRows, an empty terraform values struct is correct.
121
+ staticDiagnostics = staticDiagnostics .Extend (parameterProvisionerVersionDiagnostic (tf ))
122
+
139
123
owner , err := api .getWorkspaceOwnerData (ctx , user , templateVersion .OrganizationID )
140
124
if err != nil {
141
125
httpapi .Write (ctx , rw , http .StatusInternalServerError , codersdk.Response {
@@ -291,3 +275,31 @@ func (api *API) getWorkspaceOwnerData(
291
275
Groups : groupNames ,
292
276
}, nil
293
277
}
278
+
279
+ // parameterProvisionerVersionDiagnostic checks the version of the provisioner
280
+ // used to create the template version. If the version is less than 1.5, it
281
+ // returns a warning diagnostic. Only versions 1.5+ return the module & plan data
282
+ // required.
283
+ func parameterProvisionerVersionDiagnostic (tf database.TemplateVersionTerraformValue ) hcl.Diagnostics {
284
+ missingMetaData := hcl.Diagnostic {
285
+ Severity : hcl .DiagWarning ,
286
+ Summary : "This template version is missing required metadata to support dynamic parameters. Go back to the classic creation flow." ,
287
+ Detail : "To restore full functionality, please re-import the terraform as a new template version." ,
288
+ }
289
+
290
+ if tf .ProvisionerdVersion == "" {
291
+ return hcl.Diagnostics {& missingMetaData }
292
+ }
293
+
294
+ major , minor , err := apiversion .Parse (tf .ProvisionerdVersion )
295
+ if err != nil || tf .ProvisionerdVersion == "" {
296
+ return hcl.Diagnostics {& missingMetaData }
297
+ } else if major < 1 || (major == 1 && minor < 5 ) {
298
+ missingMetaData .Detail = "This template version requires provisioner v1.5 or newer to support dynamic parameters. " +
299
+ "Some options may be missing or incorrect. " +
300
+ "Please contact an administrator to update the provisioner and re-import the template version."
301
+ return hcl.Diagnostics {& missingMetaData }
302
+ }
303
+
304
+ return nil
305
+ }
0 commit comments