SetId should set the attribute as well
The update protocol shims will also check for this this, but eventually "id" will only be a normal attribute, and we shouldn't have to special case this.
This commit is contained in:
parent
befa81c74f
commit
3112b707be
|
@ -219,10 +219,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 +252,10 @@ 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.
|
||||
d.setWriter.unsafeWriteField("id", v)
|
||||
}
|
||||
|
||||
// SetConnInfo sets the connection info for a resource.
|
||||
|
|
|
@ -3440,7 +3440,10 @@ func TestResourceDataSetId(t *testing.T) {
|
|||
d.SetId("foo")
|
||||
|
||||
actual := d.State()
|
||||
if actual.ID != "foo" {
|
||||
|
||||
// SetId should set both the ID field as well as the attribute, to aid in
|
||||
// transitioning to the new type system.
|
||||
if actual.ID != "foo" && actual.Attributes["id"] != "foo" {
|
||||
t.Fatalf("bad: %#v", actual)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue