(body hcl.Body, impliedName string)
| 191 | } |
| 192 | |
| 193 | func decodeAttrSpec(body hcl.Body, impliedName string) (hcldec.Spec, hcl.Diagnostics) { |
| 194 | type content struct { |
| 195 | Name *string `hcl:"name"` |
| 196 | Type hcl.Expression `hcl:"type"` |
| 197 | Required *bool `hcl:"required"` |
| 198 | } |
| 199 | |
| 200 | var args content |
| 201 | diags := gohcl.DecodeBody(body, nil, &args) |
| 202 | if diags.HasErrors() { |
| 203 | return errSpec, diags |
| 204 | } |
| 205 | |
| 206 | spec := &hcldec.AttrSpec{ |
| 207 | Name: impliedName, |
| 208 | } |
| 209 | |
| 210 | if args.Required != nil { |
| 211 | spec.Required = *args.Required |
| 212 | } |
| 213 | if args.Name != nil { |
| 214 | spec.Name = *args.Name |
| 215 | } |
| 216 | |
| 217 | var typeDiags hcl.Diagnostics |
| 218 | spec.Type, typeDiags = evalTypeExpr(args.Type) |
| 219 | diags = append(diags, typeDiags...) |
| 220 | |
| 221 | if spec.Name == "" { |
| 222 | diags = append(diags, &hcl.Diagnostic{ |
| 223 | Severity: hcl.DiagError, |
| 224 | Summary: "Missing name in attribute spec", |
| 225 | Detail: "The name attribute is required, to specify the attribute name that is expected in an input HCL file.", |
| 226 | Subject: body.MissingItemRange().Ptr(), |
| 227 | }) |
| 228 | return errSpec, diags |
| 229 | } |
| 230 | |
| 231 | return spec, diags |
| 232 | } |
| 233 | |
| 234 | func decodeBlockSpec(body hcl.Body, impliedName string) (hcldec.Spec, hcl.Diagnostics) { |
| 235 | type content struct { |
no test coverage detected