list := &hcl.ObjectList{} // ... populate list ... // get all objects of type "example" objs := list.Filter("example", func(o *hcl.Object) bool { return o.Type() == "example" })
list := &hcl.ObjectList{} // ... populate list ... // get all objects where "name" attribute is "example" objs := list.Filter("example", func(o *hcl.Object) bool { nameAttr := o.Attributes["name"] return nameAttr != nil && nameAttr.Expr().LiteralValue() == "example" })In both examples, we are using the ObjectList Filter to retrieve objects from a list based on a specific type or attribute value. This functionality is part of the github.com.hashicorp/hcl/hclparse package.