helper/schema: Resource.Data should set latest schema version
This commit is contained in:
parent
84fa3e5c9e
commit
b728e55861
|
@ -295,6 +295,11 @@ func (r *Resource) Data(s *terraform.InstanceState) *ResourceData {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set the schema version to latest by default
|
||||||
|
result.meta = map[string]string{
|
||||||
|
"schema_version": strconv.Itoa(r.SchemaVersion),
|
||||||
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@ type ResourceData struct {
|
||||||
config *terraform.ResourceConfig
|
config *terraform.ResourceConfig
|
||||||
state *terraform.InstanceState
|
state *terraform.InstanceState
|
||||||
diff *terraform.InstanceDiff
|
diff *terraform.InstanceDiff
|
||||||
|
meta map[string]string
|
||||||
|
|
||||||
// Don't set
|
// Don't set
|
||||||
multiReader *MultiLevelFieldReader
|
multiReader *MultiLevelFieldReader
|
||||||
|
@ -233,6 +234,7 @@ func (d *ResourceData) SetType(t string) {
|
||||||
func (d *ResourceData) State() *terraform.InstanceState {
|
func (d *ResourceData) State() *terraform.InstanceState {
|
||||||
var result terraform.InstanceState
|
var result terraform.InstanceState
|
||||||
result.ID = d.Id()
|
result.ID = d.Id()
|
||||||
|
result.Meta = d.meta
|
||||||
|
|
||||||
// If we have no ID, then this resource doesn't exist and we just
|
// If we have no ID, then this resource doesn't exist and we just
|
||||||
// return nil.
|
// return nil.
|
||||||
|
|
|
@ -873,6 +873,16 @@ func TestResourceData(t *testing.T) {
|
||||||
if v := data.Get("foo"); v != 42 {
|
if v := data.Get("foo"); v != 42 {
|
||||||
t.Fatalf("bad: %#v", v)
|
t.Fatalf("bad: %#v", v)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set expectations
|
||||||
|
state.Meta = map[string]string{
|
||||||
|
"schema_version": "2",
|
||||||
|
}
|
||||||
|
|
||||||
|
result := data.State()
|
||||||
|
if !reflect.DeepEqual(result, state) {
|
||||||
|
t.Fatalf("bad: %#v", result)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestResourceData_blank(t *testing.T) {
|
func TestResourceData_blank(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue