in hcl/parse.go [203:264]
func ParseAzapiResource(f hcl.File) (*[]AzapiResource, []error) {
content, _, diags := f.Body.PartialContent(&ResourceBlockSchema)
if diags.HasErrors() {
logrus.Error(diags)
}
results := make([]AzapiResource, 0)
for _, block := range content.Blocks {
if block.Type == "resource" && len(block.Labels) > 1 && block.Labels[0] == "azapi_resource" {
attrs, diags := block.Body.JustAttributes()
if diags.HasErrors() {
diags := skipJustAttributesDiags(diags)
if diags.HasErrors() {
return nil, diags.Errs()
}
}
resourceTypeRaw, ok := attrs["type"]
if !ok {
return nil, []error{fmt.Errorf("resource type is not specified for azapi_resource.%s", block.Labels[1])}
}
resourceType, errs := mockExpression(resourceTypeRaw.Expr)
if errs != nil {
return nil, errs
}
r := AzapiResource{
Name: block.Labels[1],
Type: resourceType.AsString(),
FileName: block.DefRange.Filename,
LineNumber: block.DefRange.Start.Line,
}
if p := attrs["body"]; p != nil {
body, errs := mockExpression(p.Expr)
if errs != nil {
return nil, errs
}
if body.Type() == cty.String {
r.Body = body.AsString()
} else {
logrus.Debugf("jsonencode for azapi_resource %s with dynamic schema body: %+v", r.Name, body)
// azapi dynamic schema is used
v, err := stdlib.JSONEncode(*body)
if err != nil {
errs = append(errs, fmt.Errorf("jsonencode for azapi dynamic schema: %+v", err))
return nil, errs
}
r.Body = v.AsString()
}
}
results = append(results, r)
}
}
return &results, nil
}