4 "github.com/hashicorp/hcl2/hcl"
5 "github.com/hashicorp/hcl2/hcl/hclsyntax"
8 // exprIsNativeQuotedString determines whether the given expression looks like
9 // it's a quoted string in the HCL native syntax.
11 // This should be used sparingly only for situations where our legacy HCL
12 // decoding would've expected a keyword or reference in quotes but our new
13 // decoding expects the keyword or reference to be provided directly as
14 // an identifier-based expression.
15 func exprIsNativeQuotedString(expr hcl.Expression) bool {
16 _, ok := expr.(*hclsyntax.TemplateExpr)
20 // schemaForOverrides takes a *hcl.BodySchema and produces a new one that is
21 // equivalent except that any required attributes are forced to not be required.
23 // This is useful for dealing with "override" config files, which are allowed
24 // to omit things that they don't wish to override from the main configuration.
26 // The returned schema may have some pointers in common with the given schema,
27 // so neither the given schema nor the returned schema should be modified after
28 // using this function in order to avoid confusion.
30 // Overrides are rarely used, so it's recommended to just create the override
31 // schema on the fly only when it's needed, rather than storing it in a global
32 // variable as we tend to do for a primary schema.
33 func schemaForOverrides(schema *hcl.BodySchema) *hcl.BodySchema {
34 ret := &hcl.BodySchema{
35 Attributes: make([]hcl.AttributeSchema, len(schema.Attributes)),
36 Blocks: schema.Blocks,
39 for i, attrS := range schema.Attributes {
40 ret.Attributes[i] = attrS
41 ret.Attributes[i].Required = false
47 // schemaWithDynamic takes a *hcl.BodySchema and produces a new one that
48 // is equivalent except that it accepts an additional block type "dynamic" with
49 // a single label, used to recognize usage of the HCL dynamic block extension.
50 func schemaWithDynamic(schema *hcl.BodySchema) *hcl.BodySchema {
51 ret := &hcl.BodySchema{
52 Attributes: schema.Attributes,
53 Blocks: make([]hcl.BlockHeaderSchema, len(schema.Blocks), len(schema.Blocks)+1),
56 copy(ret.Blocks, schema.Blocks)
57 ret.Blocks = append(ret.Blocks, hcl.BlockHeaderSchema{
59 LabelNames: []string{"type"},