diff --git a/helper/resource/state_shim.go b/helper/resource/state_shim.go index ceb4c6ac33..13802dbc7b 100644 --- a/helper/resource/state_shim.go +++ b/helper/resource/state_shim.go @@ -88,6 +88,11 @@ func shimNewState(newState *states.State, schemas *terraform.Schemas) (*terrafor Tainted: i.Current.Status == states.ObjectTainted, }, } + if i.Current.SchemaVersion != 0 { + resState.Primary.Meta = map[string]interface{}{ + "schema_version": i.Current.SchemaVersion, + } + } for _, dep := range i.Current.Dependencies { resState.Dependencies = append(resState.Dependencies, dep.String()) @@ -119,6 +124,11 @@ func shimNewState(newState *states.State, schemas *terraform.Schemas) (*terrafor Attributes: flatmap, Tainted: dep.Status == states.ObjectTainted, } + if dep.SchemaVersion != 0 { + deposed.Meta = map[string]interface{}{ + "schema_version": dep.SchemaVersion, + } + } resState.Deposed = append(resState.Deposed, deposed) } diff --git a/helper/resource/state_shim_test.go b/helper/resource/state_shim_test.go index 0f01747579..22f5b02fe7 100644 --- a/helper/resource/state_shim_test.go +++ b/helper/resource/state_shim_test.go @@ -3,9 +3,8 @@ package resource import ( "testing" - "github.com/hashicorp/terraform/configs/configschema" - "github.com/hashicorp/terraform/addrs" + "github.com/hashicorp/terraform/configs/configschema" "github.com/hashicorp/terraform/states" "github.com/hashicorp/terraform/terraform" "github.com/zclconf/go-cty/cty" @@ -29,8 +28,9 @@ func TestStateShim(t *testing.T) { Name: "foo", }.Instance(addrs.NoKey), &states.ResourceInstanceObjectSrc{ - Status: states.ObjectReady, - AttrsFlat: map[string]string{"id": "foo", "bazzle": "dazzle"}, + Status: states.ObjectReady, + AttrsFlat: map[string]string{"id": "foo", "bazzle": "dazzle"}, + SchemaVersion: 7, Dependencies: []addrs.Referenceable{ addrs.ResourceInstance{ Resource: addrs.Resource{ @@ -209,6 +209,9 @@ func TestStateShim(t *testing.T) { "id": "foo", "bazzle": "dazzle", }, + Meta: map[string]interface{}{ + "schema_version": 7, + }, }, Dependencies: []string{"test_thing.baz"}, },