diff --git a/hclext/structure.go b/hclext/structure.go index ab0e49d..08a1416 100644 --- a/hclext/structure.go +++ b/hclext/structure.go @@ -158,6 +158,19 @@ func PartialContent(body hcl.Body, schema *BodySchema) (*BodyContent, hcl.Diagno return ret, diags } +// OfType filters the receiving block sequence by block type name, +// returning a new block sequence including only the blocks of the +// requested type. +func (els Blocks) OfType(typeName string) Blocks { + ret := make(Blocks, 0) + for _, el := range els { + if el.Type == typeName { + ret = append(ret, el) + } + } + return ret +} + // ByType transforms the receiving block sequence into a map from type // name to block sequences of only that type. func (els Blocks) ByType() map[string]Blocks {