diff options
author | appilon <apilon@hashicorp.com> | 2019-02-27 16:43:31 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-27 16:43:31 -0500 |
commit | 844b5a68d8af4791755b8f0ad293cc99f5959183 (patch) | |
tree | 255c250a5c9d4801c74092d33b7337d8c14438ff /vendor/github.com/hashicorp/terraform/helper/schema/field_reader_diff.go | |
parent | 303b299eeb6b06e939e35905e4b34cb410dd9dc3 (diff) | |
parent | 15c0b25d011f37e7c20aeca9eaf461f78285b8d9 (diff) | |
download | terraform-provider-statuscake-844b5a68d8af4791755b8f0ad293cc99f5959183.tar.gz terraform-provider-statuscake-844b5a68d8af4791755b8f0ad293cc99f5959183.tar.zst terraform-provider-statuscake-844b5a68d8af4791755b8f0ad293cc99f5959183.zip |
Merge pull request #27 from terraform-providers/go-modules-2019-02-22
[MODULES] Switch to Go Modules
Diffstat (limited to 'vendor/github.com/hashicorp/terraform/helper/schema/field_reader_diff.go')
-rw-r--r-- | vendor/github.com/hashicorp/terraform/helper/schema/field_reader_diff.go | 43 |
1 files changed, 37 insertions, 6 deletions
diff --git a/vendor/github.com/hashicorp/terraform/helper/schema/field_reader_diff.go b/vendor/github.com/hashicorp/terraform/helper/schema/field_reader_diff.go index 16bbae2..d558a5b 100644 --- a/vendor/github.com/hashicorp/terraform/helper/schema/field_reader_diff.go +++ b/vendor/github.com/hashicorp/terraform/helper/schema/field_reader_diff.go | |||
@@ -29,29 +29,59 @@ type DiffFieldReader struct { | |||
29 | Diff *terraform.InstanceDiff | 29 | Diff *terraform.InstanceDiff |
30 | Source FieldReader | 30 | Source FieldReader |
31 | Schema map[string]*Schema | 31 | Schema map[string]*Schema |
32 | |||
33 | // cache for memoizing ReadField calls. | ||
34 | cache map[string]cachedFieldReadResult | ||
35 | } | ||
36 | |||
37 | type cachedFieldReadResult struct { | ||
38 | val FieldReadResult | ||
39 | err error | ||
32 | } | 40 | } |
33 | 41 | ||
34 | func (r *DiffFieldReader) ReadField(address []string) (FieldReadResult, error) { | 42 | func (r *DiffFieldReader) ReadField(address []string) (FieldReadResult, error) { |
43 | if r.cache == nil { | ||
44 | r.cache = make(map[string]cachedFieldReadResult) | ||
45 | } | ||
46 | |||
47 | // Create the cache key by joining around a value that isn't a valid part | ||
48 | // of an address. This assumes that the Source and Schema are not changed | ||
49 | // for the life of this DiffFieldReader. | ||
50 | cacheKey := strings.Join(address, "|") | ||
51 | if cached, ok := r.cache[cacheKey]; ok { | ||
52 | return cached.val, cached.err | ||
53 | } | ||
54 | |||
35 | schemaList := addrToSchema(address, r.Schema) | 55 | schemaList := addrToSchema(address, r.Schema) |
36 | if len(schemaList) == 0 { | 56 | if len(schemaList) == 0 { |
57 | r.cache[cacheKey] = cachedFieldReadResult{} | ||
37 | return FieldReadResult{}, nil | 58 | return FieldReadResult{}, nil |
38 | } | 59 | } |
39 | 60 | ||
61 | var res FieldReadResult | ||
62 | var err error | ||
63 | |||
40 | schema := schemaList[len(schemaList)-1] | 64 | schema := schemaList[len(schemaList)-1] |
41 | switch schema.Type { | 65 | switch schema.Type { |
42 | case TypeBool, TypeInt, TypeFloat, TypeString: | 66 | case TypeBool, TypeInt, TypeFloat, TypeString: |
43 | return r.readPrimitive(address, schema) | 67 | res, err = r.readPrimitive(address, schema) |
44 | case TypeList: | 68 | case TypeList: |
45 | return readListField(r, address, schema) | 69 | res, err = readListField(r, address, schema) |
46 | case TypeMap: | 70 | case TypeMap: |
47 | return r.readMap(address, schema) | 71 | res, err = r.readMap(address, schema) |
48 | case TypeSet: | 72 | case TypeSet: |
49 | return r.readSet(address, schema) | 73 | res, err = r.readSet(address, schema) |
50 | case typeObject: | 74 | case typeObject: |
51 | return readObjectField(r, address, schema.Elem.(map[string]*Schema)) | 75 | res, err = readObjectField(r, address, schema.Elem.(map[string]*Schema)) |
52 | default: | 76 | default: |
53 | panic(fmt.Sprintf("Unknown type: %#v", schema.Type)) | 77 | panic(fmt.Sprintf("Unknown type: %#v", schema.Type)) |
54 | } | 78 | } |
79 | |||
80 | r.cache[cacheKey] = cachedFieldReadResult{ | ||
81 | val: res, | ||
82 | err: err, | ||
83 | } | ||
84 | return res, err | ||
55 | } | 85 | } |
56 | 86 | ||
57 | func (r *DiffFieldReader) readMap( | 87 | func (r *DiffFieldReader) readMap( |
@@ -92,7 +122,8 @@ func (r *DiffFieldReader) readMap( | |||
92 | result[k] = v.New | 122 | result[k] = v.New |
93 | } | 123 | } |
94 | 124 | ||
95 | err = mapValuesToPrimitive(result, schema) | 125 | key := address[len(address)-1] |
126 | err = mapValuesToPrimitive(key, result, schema) | ||
96 | if err != nil { | 127 | if err != nil { |
97 | return FieldReadResult{}, nil | 128 | return FieldReadResult{}, nil |
98 | } | 129 | } |