// 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)
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
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.