|
|
|
@ -613,7 +613,7 @@ func Parse(b hcl.Body, opt Opt, val interface{}) (map[string]map[string][]string
|
|
|
|
|
|
|
|
|
|
attrs, diags := b.JustAttributes()
|
|
|
|
|
if diags.HasErrors() {
|
|
|
|
|
if d := removeAttributesDiags(diags, reserved, p.vars); len(d) > 0 {
|
|
|
|
|
if d := removeAttributesDiags(diags, reserved, p.vars, attrs); len(d) > 0 {
|
|
|
|
|
return nil, d
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -854,27 +854,50 @@ func getNameIndex(v reflect.Value) (int, bool) {
|
|
|
|
|
return 0, false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func removeAttributesDiags(diags hcl.Diagnostics, reserved map[string]struct{}, vars map[string]*variable) hcl.Diagnostics {
|
|
|
|
|
func removeAttributesDiags(diags hcl.Diagnostics, reserved map[string]struct{}, vars map[string]*variable, attrs hcl.Attributes) hcl.Diagnostics {
|
|
|
|
|
var fdiags hcl.Diagnostics
|
|
|
|
|
|
|
|
|
|
alreadySetArg := func(detail string, keys []string) bool {
|
|
|
|
|
for _, k := range keys {
|
|
|
|
|
if strings.HasPrefix(detail, fmt.Sprintf(`Argument %q was already set at `, k)) {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var reservedKeys []string
|
|
|
|
|
for k := range reserved {
|
|
|
|
|
reservedKeys = append(reservedKeys, k)
|
|
|
|
|
}
|
|
|
|
|
var varsKeys []string
|
|
|
|
|
for k := range vars {
|
|
|
|
|
varsKeys = append(varsKeys, k)
|
|
|
|
|
}
|
|
|
|
|
var attrsKeys []string
|
|
|
|
|
for k := range attrs {
|
|
|
|
|
attrsKeys = append(attrsKeys, k)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, d := range diags {
|
|
|
|
|
if fout := func(d *hcl.Diagnostic) bool {
|
|
|
|
|
// https://github.com/docker/buildx/pull/541
|
|
|
|
|
if d.Detail == "Blocks are not allowed here." {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
for r := range reserved {
|
|
|
|
|
// JSON body objects don't handle repeated blocks like HCL but
|
|
|
|
|
// reserved name attributes should be allowed when multi bodies are merged.
|
|
|
|
|
// https://github.com/hashicorp/hcl/blob/main/json/spec.md#blocks
|
|
|
|
|
if strings.HasPrefix(d.Detail, fmt.Sprintf(`Argument "%s" was already set at `, r)) {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
// JSON body objects don't handle repeated blocks like HCL but
|
|
|
|
|
// reserved name attributes should be allowed when multi bodies are merged.
|
|
|
|
|
// https://github.com/hashicorp/hcl/blob/main/json/spec.md#blocks
|
|
|
|
|
if alreadySetArg(d.Detail, reservedKeys) {
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
// Do the same for global variables
|
|
|
|
|
if alreadySetArg(d.Detail, varsKeys) {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
// Do the same for attributes
|
|
|
|
|
if alreadySetArg(d.Detail, attrsKeys) {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
}(d); !fout {
|
|
|
|
|