bake: merge vars from multiple JSON files

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax
2022-04-06 00:55:56 +02:00
parent c317ca1e95
commit cad7ed68be
2 changed files with 58 additions and 3 deletions

View File

@ -302,7 +302,7 @@ func Parse(b hcl.Body, opt Opt, val interface{}) hcl.Diagnostics {
attrs, diags := b.JustAttributes()
if diags.HasErrors() {
if d := removeAttributesDiags(diags, reserved); len(d) > 0 {
if d := removeAttributesDiags(diags, reserved, p.vars); len(d) > 0 {
return d
}
}
@ -513,7 +513,7 @@ func setLabel(v reflect.Value, lbl string) int {
return -1
}
func removeAttributesDiags(diags hcl.Diagnostics, reserved map[string]struct{}) hcl.Diagnostics {
func removeAttributesDiags(diags hcl.Diagnostics, reserved map[string]struct{}, vars map[string]*variable) hcl.Diagnostics {
var fdiags hcl.Diagnostics
for _, d := range diags {
if fout := func(d *hcl.Diagnostic) bool {
@ -529,6 +529,12 @@ func removeAttributesDiags(diags hcl.Diagnostics, reserved map[string]struct{})
return true
}
}
for v := range vars {
// Do the same for global variables
if strings.HasPrefix(d.Detail, fmt.Sprintf(`Argument "%s" was already set at `, v)) {
return true
}
}
return false
}(d); !fout {
fdiags = append(fdiags, d)