]> git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/blobdiff - vendor/github.com/hashicorp/terraform/helper/schema/resource_data.go
Upgrade to 0.12
[github/fretlink/terraform-provider-statuscake.git] / vendor / github.com / hashicorp / terraform / helper / schema / resource_data.go
index 6cc01ee0bd4c9fa8629c91990060175be2068304..1c390709e86339db6c36c6638e84477b51af7871 100644 (file)
@@ -52,6 +52,8 @@ type getResult struct {
 // UnsafeSetFieldRaw allows setting arbitrary values in state to arbitrary
 // values, bypassing schema. This MUST NOT be used in normal circumstances -
 // it exists only to support the remote_state data source.
+//
+// Deprecated: Fully define schema attributes and use Set() instead.
 func (d *ResourceData) UnsafeSetFieldRaw(key string, value string) {
        d.once.Do(d.init)
 
@@ -219,10 +221,16 @@ func (d *ResourceData) Id() string {
 
        if d.state != nil {
                result = d.state.ID
+               if result == "" {
+                       result = d.state.Attributes["id"]
+               }
        }
 
        if d.newState != nil {
                result = d.newState.ID
+               if result == "" {
+                       result = d.newState.Attributes["id"]
+               }
        }
 
        return result
@@ -246,6 +254,18 @@ func (d *ResourceData) ConnInfo() map[string]string {
 func (d *ResourceData) SetId(v string) {
        d.once.Do(d.init)
        d.newState.ID = v
+
+       // once we transition away from the legacy state types, "id" will no longer
+       // be a special field, and will become a normal attribute.
+       // set the attribute normally
+       d.setWriter.unsafeWriteField("id", v)
+
+       // Make sure the newState is also set, otherwise the old value
+       // may get precedence.
+       if d.newState.Attributes == nil {
+               d.newState.Attributes = map[string]string{}
+       }
+       d.newState.Attributes["id"] = v
 }
 
 // SetConnInfo sets the connection info for a resource.