mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-09-07 09:36:44 +00:00
37 lines
922 B
Go
37 lines
922 B
Go
package hcldec
|
|
|
|
import (
|
|
"github.com/hashicorp/hcl2/hcl"
|
|
)
|
|
|
|
// ImpliedSchema returns the *hcl.BodySchema implied by the given specification.
|
|
// This is the schema that the Decode function will use internally to
|
|
// access the content of a given body.
|
|
func ImpliedSchema(spec Spec) *hcl.BodySchema {
|
|
var attrs []hcl.AttributeSchema
|
|
var blocks []hcl.BlockHeaderSchema
|
|
|
|
// visitSameBodyChildren walks through the spec structure, calling
|
|
// the given callback for each descendent spec encountered. We are
|
|
// interested in the specs that reference attributes and blocks.
|
|
var visit visitFunc
|
|
visit = func(s Spec) {
|
|
if as, ok := s.(attrSpec); ok {
|
|
attrs = append(attrs, as.attrSchemata()...)
|
|
}
|
|
|
|
if bs, ok := s.(blockSpec); ok {
|
|
blocks = append(blocks, bs.blockHeaderSchemata()...)
|
|
}
|
|
|
|
s.visitSameBodyChildren(visit)
|
|
}
|
|
|
|
visit(spec)
|
|
|
|
return &hcl.BodySchema{
|
|
Attributes: attrs,
|
|
Blocks: blocks,
|
|
}
|
|
}
|