aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/hashicorp/terraform/helper/resource/state_shim.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/hashicorp/terraform/helper/resource/state_shim.go')
-rw-r--r--vendor/github.com/hashicorp/terraform/helper/resource/state_shim.go78
1 files changed, 51 insertions, 27 deletions
diff --git a/vendor/github.com/hashicorp/terraform/helper/resource/state_shim.go b/vendor/github.com/hashicorp/terraform/helper/resource/state_shim.go
index b2aff99..f488207 100644
--- a/vendor/github.com/hashicorp/terraform/helper/resource/state_shim.go
+++ b/vendor/github.com/hashicorp/terraform/helper/resource/state_shim.go
@@ -1,6 +1,7 @@
1package resource 1package resource
2 2
3import ( 3import (
4 "encoding/json"
4 "fmt" 5 "fmt"
5 6
6 "github.com/hashicorp/terraform/addrs" 7 "github.com/hashicorp/terraform/addrs"
@@ -52,43 +53,57 @@ func shimNewState(newState *states.State, providers map[string]terraform.Resourc
52 resource := getResource(providers, providerType, res.Addr) 53 resource := getResource(providers, providerType, res.Addr)
53 54
54 for key, i := range res.Instances { 55 for key, i := range res.Instances {
55 flatmap, err := shimmedAttributes(i.Current, resource) 56 resState := &terraform.ResourceState{
56 if err != nil { 57 Type: resType,
57 return nil, fmt.Errorf("error decoding state for %q: %s", resType, err) 58 Provider: res.ProviderConfig.String(),
58 } 59 }
59 60
60 resState := &terraform.ResourceState{ 61 // We should always have a Current instance here, but be safe about checking.
61 Type: resType, 62 if i.Current != nil {
62 Primary: &terraform.InstanceState{ 63 flatmap, err := shimmedAttributes(i.Current, resource)
64 if err != nil {
65 return nil, fmt.Errorf("error decoding state for %q: %s", resType, err)
66 }
67
68 var meta map[string]interface{}
69 if i.Current.Private != nil {
70 err := json.Unmarshal(i.Current.Private, &meta)
71 if err != nil {
72 return nil, err
73 }
74 }
75
76 resState.Primary = &terraform.InstanceState{
63 ID: flatmap["id"], 77 ID: flatmap["id"],
64 Attributes: flatmap, 78 Attributes: flatmap,
65 Tainted: i.Current.Status == states.ObjectTainted, 79 Tainted: i.Current.Status == states.ObjectTainted,
66 }, 80 Meta: meta,
67 Provider: res.ProviderConfig.String(),
68 }
69 if i.Current.SchemaVersion != 0 {
70 resState.Primary.Meta = map[string]interface{}{
71 "schema_version": i.Current.SchemaVersion,
72 } 81 }
73 }
74 82
75 for _, dep := range i.Current.Dependencies { 83 if i.Current.SchemaVersion != 0 {
76 resState.Dependencies = append(resState.Dependencies, dep.String()) 84 resState.Primary.Meta = map[string]interface{}{
77 } 85 "schema_version": i.Current.SchemaVersion,
86 }
87 }
78 88
79 // convert the indexes to the old style flapmap indexes 89 for _, dep := range i.Current.Dependencies {
80 idx := "" 90 resState.Dependencies = append(resState.Dependencies, dep.String())
81 switch key.(type) {
82 case addrs.IntKey:
83 // don't add numeric index values to resources with a count of 0
84 if len(res.Instances) > 1 {
85 idx = fmt.Sprintf(".%d", key)
86 } 91 }
87 case addrs.StringKey:
88 idx = "." + key.String()
89 }
90 92
91 mod.Resources[res.Addr.String()+idx] = resState 93 // convert the indexes to the old style flapmap indexes
94 idx := ""
95 switch key.(type) {
96 case addrs.IntKey:
97 // don't add numeric index values to resources with a count of 0
98 if len(res.Instances) > 1 {
99 idx = fmt.Sprintf(".%d", key)
100 }
101 case addrs.StringKey:
102 idx = "." + key.String()
103 }
104
105 mod.Resources[res.Addr.String()+idx] = resState
106 }
92 107
93 // add any deposed instances 108 // add any deposed instances
94 for _, dep := range i.Deposed { 109 for _, dep := range i.Deposed {
@@ -97,10 +112,19 @@ func shimNewState(newState *states.State, providers map[string]terraform.Resourc
97 return nil, fmt.Errorf("error decoding deposed state for %q: %s", resType, err) 112 return nil, fmt.Errorf("error decoding deposed state for %q: %s", resType, err)
98 } 113 }
99 114
115 var meta map[string]interface{}
116 if dep.Private != nil {
117 err := json.Unmarshal(dep.Private, &meta)
118 if err != nil {
119 return nil, err
120 }
121 }
122
100 deposed := &terraform.InstanceState{ 123 deposed := &terraform.InstanceState{
101 ID: flatmap["id"], 124 ID: flatmap["id"],
102 Attributes: flatmap, 125 Attributes: flatmap,
103 Tainted: dep.Status == states.ObjectTainted, 126 Tainted: dep.Status == states.ObjectTainted,
127 Meta: meta,
104 } 128 }
105 if dep.SchemaVersion != 0 { 129 if dep.SchemaVersion != 0 {
106 deposed.Meta = map[string]interface{}{ 130 deposed.Meta = map[string]interface{}{