diff options
Diffstat (limited to 'vendor/github.com/hashicorp/terraform/helper/resource')
-rw-r--r-- | vendor/github.com/hashicorp/terraform/helper/resource/state_shim.go | 78 | ||||
-rw-r--r-- | vendor/github.com/hashicorp/terraform/helper/resource/testing_config.go | 3 |
2 files changed, 52 insertions, 29 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 @@ | |||
1 | package resource | 1 | package resource |
2 | 2 | ||
3 | import ( | 3 | import ( |
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{}{ |
diff --git a/vendor/github.com/hashicorp/terraform/helper/resource/testing_config.go b/vendor/github.com/hashicorp/terraform/helper/resource/testing_config.go index 311fdb6..f34e17a 100644 --- a/vendor/github.com/hashicorp/terraform/helper/resource/testing_config.go +++ b/vendor/github.com/hashicorp/terraform/helper/resource/testing_config.go | |||
@@ -10,7 +10,6 @@ import ( | |||
10 | "strings" | 10 | "strings" |
11 | 11 | ||
12 | "github.com/hashicorp/terraform/addrs" | 12 | "github.com/hashicorp/terraform/addrs" |
13 | "github.com/hashicorp/terraform/config" | ||
14 | "github.com/hashicorp/terraform/config/hcl2shim" | 13 | "github.com/hashicorp/terraform/config/hcl2shim" |
15 | "github.com/hashicorp/terraform/states" | 14 | "github.com/hashicorp/terraform/states" |
16 | 15 | ||
@@ -341,7 +340,7 @@ func legacyDiffComparisonString(changes *plans.Changes) string { | |||
341 | v := newAttrs[attrK] | 340 | v := newAttrs[attrK] |
342 | u := oldAttrs[attrK] | 341 | u := oldAttrs[attrK] |
343 | 342 | ||
344 | if v == config.UnknownVariableValue { | 343 | if v == hcl2shim.UnknownVariableValue { |
345 | v = "<computed>" | 344 | v = "<computed>" |
346 | } | 345 | } |
347 | // NOTE: we don't support <sensitive> here because we would | 346 | // NOTE: we don't support <sensitive> here because we would |