4 "github.com/hashicorp/hcl2/hcl"
5 "github.com/hashicorp/hcl2/hcldec"
6 "github.com/hashicorp/terraform/configs/configschema"
7 "github.com/zclconf/go-cty/cty"
10 // Backend represents a "backend" block inside a "terraform" block in a module
20 func decodeBackendBlock(block *hcl.Block) (*Backend, hcl.Diagnostics) {
22 Type: block.Labels[0],
23 TypeRange: block.LabelRanges[0],
25 DeclRange: block.DefRange,
29 // Hash produces a hash value for the reciever that covers the type and the
30 // portions of the config that conform to the given schema.
32 // If the config does not conform to the schema then the result is not
33 // meaningful for comparison since it will be based on an incomplete result.
35 // As an exception, required attributes in the schema are treated as optional
36 // for the purpose of hashing, so that an incomplete configuration can still
37 // be hashed. Other errors, such as extraneous attributes, have no such special
39 func (b *Backend) Hash(schema *configschema.Block) int {
40 // Don't fail if required attributes are not set. Instead, we'll just
41 // hash them as nulls.
42 schema = schema.NoneRequired()
43 spec := schema.DecoderSpec()
44 val, _ := hcldec.Decode(b.Config, spec, nil)
45 if val == cty.NilVal {
46 val = cty.UnknownVal(schema.ImpliedType())
49 toHash := cty.TupleVal([]cty.Value{
50 cty.StringVal(b.Type),