Skip to content

Commit

Permalink
Merge pull request #11165 from hashicorp/b-gh-11149
Browse files Browse the repository at this point in the history
jobspec2: ensure consistent error handling between var-file & var.
  • Loading branch information
jrasell committed Nov 4, 2021
2 parents 9b5cadf + e8efbd8 commit 166b0cf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .changelog/11165.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
jobspec: ensure consistent error handling between var-file & cli vars
```
1 change: 1 addition & 0 deletions command/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ func (j *JobGetter) ApiJobWithArgs(jpath string, vars []string, varfiles []strin
AllowFS: true,
VarFiles: varfiles,
Envs: os.Environ(),
Strict: true,
})

if err != nil {
Expand Down
14 changes: 8 additions & 6 deletions jobspec2/types.variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,12 @@ func (c *jobConfig) collectInputVariableValues(env []string, files []*hcl.File,
})
}

// Define the severity of variable passed that are undefined.
undefSev := hcl.DiagWarning
if c.ParseConfig.Strict {
undefSev = hcl.DiagError
}

// files will contain files found in the folder then files passed as
// arguments.
for _, file := range files {
Expand Down Expand Up @@ -583,12 +589,8 @@ func (c *jobConfig) collectInputVariableValues(env []string, files []*hcl.File,
for name, attr := range attrs {
variable, found := variables[name]
if !found {
sev := hcl.DiagWarning
if c.ParseConfig.Strict {
sev = hcl.DiagError
}
diags = append(diags, &hcl.Diagnostic{
Severity: sev,
Severity: undefSev,
Summary: "Undefined variable",
Detail: fmt.Sprintf("A %q variable was set but was "+
"not found in known variables. To declare "+
Expand Down Expand Up @@ -630,7 +632,7 @@ func (c *jobConfig) collectInputVariableValues(env []string, files []*hcl.File,
variable, found := variables[name]
if !found {
diags = append(diags, &hcl.Diagnostic{
Severity: hcl.DiagError,
Severity: undefSev,
Summary: "Undefined -var variable",
Detail: fmt.Sprintf("A %q variable was passed in the command "+
"line but was not found in known variables. "+
Expand Down

0 comments on commit 166b0cf

Please sign in to comment.