Downgrade missing map elem errors to warn and continue evaluation
e.g. non existing header keys
@@ -16,8 +16,8 @@ var validKey = regexp.MustCompile("[a-zA-Z_][a-zA-Z0-9_-]*")
func ExpToMap(ctx *hcl.EvalContext, exp hcl.Expression) (map[string]interface{}, hcl.Diagnostics) {
val, diags := exp.Value(ctx)
- if diags.HasErrors() {
- return nil, diags
+ if d := setSeverityLevel(diags); d.HasErrors() {
+ return nil, d
}
result := make(map[string]interface{})
if val.IsNull() {
@@ -40,7 +40,8 @@ func ExpToMap(ctx *hcl.EvalContext, exp hcl.Expression) (map[string]interface{},
result[k] = toStringSlice(v)
continue
}
- result[k] = v
+ // unknown types results in empty string which gets removed later on
+ result[k] = ""
}
}
return result, nil
@@ -154,3 +155,13 @@ func ToString(s interface{}) string {
func isTuple(v cty.Value) bool {
return v.Type().FriendlyNameForConstraint() == "tuple"
}
+
+func setSeverityLevel(diags hcl.Diagnostics) hcl.Diagnostics {
+ for i, d := range diags {
+ if d.Summary == "Missing map element" {
+ d.Severity = hcl.DiagWarning
+ return setSeverityLevel(diags[i+1:])
+ }
+ }
+ return diags
+}
