github.com/jameswoolfenden/terraform@v0.11.12-beta1/configs/util.go (about) 1 package configs 2 3 import ( 4 "github.com/hashicorp/hcl2/hcl" 5 "github.com/hashicorp/hcl2/hcl/hclsyntax" 6 ) 7 8 // exprIsNativeQuotedString determines whether the given expression looks like 9 // it's a quoted string in the HCL native syntax. 10 // 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) 17 return ok 18 } 19 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. 22 // 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. 25 // 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. 29 // 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, 37 } 38 39 for i, attrS := range schema.Attributes { 40 ret.Attributes[i] = attrS 41 ret.Attributes[i].Required = false 42 } 43 44 return ret 45 }