From 2a19afd1ad20d78802c39e8129eeaa7ade94b6bf Mon Sep 17 00:00:00 2001 From: Kazuma Watanabe Date: Mon, 18 Jul 2022 13:28:29 +0000 Subject: [PATCH] Add AsNative helper --- hclext/structure.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/hclext/structure.go b/hclext/structure.go index 08a1416..caee114 100644 --- a/hclext/structure.go +++ b/hclext/structure.go @@ -158,6 +158,25 @@ func PartialContent(body hcl.Body, schema *BodySchema) (*BodyContent, hcl.Diagno return ret, diags } +// AsNative returns self as hcl.Attributes +func (as Attributes) AsNative() hcl.Attributes { + ret := hcl.Attributes{} + for name, attr := range as { + ret[name] = attr.AsNative() + } + return ret +} + +// AsNative returns self as hcl.Attribute +func (a *Attribute) AsNative() *hcl.Attribute { + return &hcl.Attribute{ + Name: a.Name, + Expr: a.Expr, + Range: a.Range, + NameRange: a.NameRange, + } +} + // OfType filters the receiving block sequence by block type name, // returning a new block sequence including only the blocks of the // requested type.