job parsing: fix panic when variable validation is missing condition (#16018)

This commit is contained in:
Tim Gross 2023-02-01 16:41:03 -05:00 committed by GitHub
parent 5440965260
commit 0abf0b948b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

3
.changelog/16018.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:bug
parser: Fixed a panic in the job spec parser when a variable validation block was missing its condition
```

View File

@ -95,6 +95,17 @@ func (v *Variable) validateValue(val VariableAssignment) (diags hcl.Diagnostics)
for _, validation := range v.Validations {
const errInvalidCondition = "Invalid variable validation result"
if validation.Condition == nil {
diags = append(diags, &hcl.Diagnostic{
Severity: hcl.DiagError,
Summary: "Invalid variable validation specification",
Detail: "validation requires a condition.",
Subject: validation.DeclRange.Ptr(),
EvalContext: hclCtx,
})
continue
}
result, moreDiags := validation.Condition.Value(hclCtx)
diags = append(diags, moreDiags...)
if !result.IsKnown() {