diff options
author | Nathan Dench <ndenc2@gmail.com> | 2019-05-24 15:16:44 +1000 |
---|---|---|
committer | Nathan Dench <ndenc2@gmail.com> | 2019-05-24 15:16:44 +1000 |
commit | 107c1cdb09c575aa2f61d97f48d8587eb6bada4c (patch) | |
tree | ca7d008643efc555c388baeaf1d986e0b6b3e28c /vendor/github.com/hashicorp/terraform/configs/backend.go | |
parent | 844b5a68d8af4791755b8f0ad293cc99f5959183 (diff) | |
download | terraform-provider-statuscake-107c1cdb09c575aa2f61d97f48d8587eb6bada4c.tar.gz terraform-provider-statuscake-107c1cdb09c575aa2f61d97f48d8587eb6bada4c.tar.zst terraform-provider-statuscake-107c1cdb09c575aa2f61d97f48d8587eb6bada4c.zip |
Upgrade to 0.12
Diffstat (limited to 'vendor/github.com/hashicorp/terraform/configs/backend.go')
-rw-r--r-- | vendor/github.com/hashicorp/terraform/configs/backend.go | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/terraform/configs/backend.go b/vendor/github.com/hashicorp/terraform/configs/backend.go new file mode 100644 index 0000000..6df7ddd --- /dev/null +++ b/vendor/github.com/hashicorp/terraform/configs/backend.go | |||
@@ -0,0 +1,55 @@ | |||
1 | package configs | ||
2 | |||
3 | import ( | ||
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" | ||
8 | ) | ||
9 | |||
10 | // Backend represents a "backend" block inside a "terraform" block in a module | ||
11 | // or file. | ||
12 | type Backend struct { | ||
13 | Type string | ||
14 | Config hcl.Body | ||
15 | |||
16 | TypeRange hcl.Range | ||
17 | DeclRange hcl.Range | ||
18 | } | ||
19 | |||
20 | func decodeBackendBlock(block *hcl.Block) (*Backend, hcl.Diagnostics) { | ||
21 | return &Backend{ | ||
22 | Type: block.Labels[0], | ||
23 | TypeRange: block.LabelRanges[0], | ||
24 | Config: block.Body, | ||
25 | DeclRange: block.DefRange, | ||
26 | }, nil | ||
27 | } | ||
28 | |||
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. | ||
31 | // | ||
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. | ||
34 | // | ||
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 | ||
38 | // case. | ||
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()) | ||
47 | } | ||
48 | |||
49 | toHash := cty.TupleVal([]cty.Value{ | ||
50 | cty.StringVal(b.Type), | ||
51 | val, | ||
52 | }) | ||
53 | |||
54 | return toHash.Hash() | ||
55 | } | ||