From 3fb4ed0d9260f5c187470d0d879c7b598d5899d1 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Wed, 27 Mar 2019 15:38:17 -0700 Subject: [PATCH] ext/dynblock: Allow WalkVariablesChild callers to get the body In normal situations the block type name alone is enough to determine the appropriate schema for a child, but when callers are otherwise doing unusual pre-processing of bodies to dynamically generate schemas during decoding they are likely to need to take similar steps while analyzing for variables, to ensure that all of the references can be located in spite of the not-yet-applied pre-processing. --- ext/dynblock/variables.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ext/dynblock/variables.go b/ext/dynblock/variables.go index 90b4820..ad838f3 100644 --- a/ext/dynblock/variables.go +++ b/ext/dynblock/variables.go @@ -47,6 +47,18 @@ type WalkVariablesChild struct { Node WalkVariablesNode } +// Body returns the HCL Body associated with the child node, in case the caller +// wants to do some sort of inspection of it in order to decide what schema +// to pass to Visit. +// +// Most implementations should just fetch a fixed schema based on the +// BlockTypeName field and not access this. Deciding on a schema dynamically +// based on the body is a strange thing to do and generally necessary only if +// your caller is already doing other bizarre things with HCL bodies. +func (c WalkVariablesChild) Body() hcl.Body { + return c.Node.body +} + // Visit returns the variable traversals required for any "dynamic" blocks // directly in the body associated with this node, and also returns any child // nodes that must be visited in order to continue the walk.