Skip to content

Commit

Permalink
ext/dynblock: Allow WalkVariablesChild callers to get the body
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
apparentlymart committed Mar 27, 2019
1 parent f9f92da commit 3fb4ed0
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions ext/dynblock/variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 3fb4ed0

Please sign in to comment.