diff options
Diffstat (limited to 'vendor/github.com/hashicorp/terraform/helper/schema/resource_data.go')
-rw-r--r-- | vendor/github.com/hashicorp/terraform/helper/schema/resource_data.go | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/terraform/helper/schema/resource_data.go b/vendor/github.com/hashicorp/terraform/helper/schema/resource_data.go index 6cc01ee..1c39070 100644 --- a/vendor/github.com/hashicorp/terraform/helper/schema/resource_data.go +++ b/vendor/github.com/hashicorp/terraform/helper/schema/resource_data.go | |||
@@ -52,6 +52,8 @@ type getResult struct { | |||
52 | // UnsafeSetFieldRaw allows setting arbitrary values in state to arbitrary | 52 | // UnsafeSetFieldRaw allows setting arbitrary values in state to arbitrary |
53 | // values, bypassing schema. This MUST NOT be used in normal circumstances - | 53 | // values, bypassing schema. This MUST NOT be used in normal circumstances - |
54 | // it exists only to support the remote_state data source. | 54 | // it exists only to support the remote_state data source. |
55 | // | ||
56 | // Deprecated: Fully define schema attributes and use Set() instead. | ||
55 | func (d *ResourceData) UnsafeSetFieldRaw(key string, value string) { | 57 | func (d *ResourceData) UnsafeSetFieldRaw(key string, value string) { |
56 | d.once.Do(d.init) | 58 | d.once.Do(d.init) |
57 | 59 | ||
@@ -219,10 +221,16 @@ func (d *ResourceData) Id() string { | |||
219 | 221 | ||
220 | if d.state != nil { | 222 | if d.state != nil { |
221 | result = d.state.ID | 223 | result = d.state.ID |
224 | if result == "" { | ||
225 | result = d.state.Attributes["id"] | ||
226 | } | ||
222 | } | 227 | } |
223 | 228 | ||
224 | if d.newState != nil { | 229 | if d.newState != nil { |
225 | result = d.newState.ID | 230 | result = d.newState.ID |
231 | if result == "" { | ||
232 | result = d.newState.Attributes["id"] | ||
233 | } | ||
226 | } | 234 | } |
227 | 235 | ||
228 | return result | 236 | return result |
@@ -246,6 +254,18 @@ func (d *ResourceData) ConnInfo() map[string]string { | |||
246 | func (d *ResourceData) SetId(v string) { | 254 | func (d *ResourceData) SetId(v string) { |
247 | d.once.Do(d.init) | 255 | d.once.Do(d.init) |
248 | d.newState.ID = v | 256 | d.newState.ID = v |
257 | |||
258 | // once we transition away from the legacy state types, "id" will no longer | ||
259 | // be a special field, and will become a normal attribute. | ||
260 | // set the attribute normally | ||
261 | d.setWriter.unsafeWriteField("id", v) | ||
262 | |||
263 | // Make sure the newState is also set, otherwise the old value | ||
264 | // may get precedence. | ||
265 | if d.newState.Attributes == nil { | ||
266 | d.newState.Attributes = map[string]string{} | ||
267 | } | ||
268 | d.newState.Attributes["id"] = v | ||
249 | } | 269 | } |
250 | 270 | ||
251 | // SetConnInfo sets the connection info for a resource. | 271 | // SetConnInfo sets the connection info for a resource. |