diff --git a/command/refresh_test.go b/command/refresh_test.go index aec83d334..68c1fb748 100644 --- a/command/refresh_test.go +++ b/command/refresh_test.go @@ -275,7 +275,8 @@ func TestRefresh_defaultState(t *testing.T) { expected := &states.ResourceInstanceObjectSrc{ Status: states.ObjectReady, AttrsJSON: []byte("{\n \"ami\": null,\n \"id\": \"yes\"\n }"), - Dependencies: []addrs.Referenceable{}, + Dependencies: []addrs.AbsResource{}, + DependsOn: []addrs.Referenceable{}, } if !reflect.DeepEqual(actual, expected) { t.Fatalf("wrong new object\ngot: %swant: %s", spew.Sdump(actual), spew.Sdump(expected)) @@ -339,7 +340,8 @@ func TestRefresh_outPath(t *testing.T) { expected := &states.ResourceInstanceObjectSrc{ Status: states.ObjectReady, AttrsJSON: []byte("{\n \"ami\": null,\n \"id\": \"yes\"\n }"), - Dependencies: []addrs.Referenceable{}, + Dependencies: []addrs.AbsResource{}, + DependsOn: []addrs.Referenceable{}, } if !reflect.DeepEqual(actual, expected) { t.Fatalf("wrong new object\ngot: %swant: %s", spew.Sdump(actual), spew.Sdump(expected)) @@ -568,7 +570,8 @@ func TestRefresh_backup(t *testing.T) { expected := &states.ResourceInstanceObjectSrc{ Status: states.ObjectReady, AttrsJSON: []byte("{\n \"ami\": null,\n \"id\": \"changed\"\n }"), - Dependencies: []addrs.Referenceable{}, + Dependencies: []addrs.AbsResource{}, + DependsOn: []addrs.Referenceable{}, } if !reflect.DeepEqual(actual, expected) { t.Fatalf("wrong new object\ngot: %swant: %s", spew.Sdump(actual), spew.Sdump(expected)) @@ -632,7 +635,8 @@ func TestRefresh_disableBackup(t *testing.T) { expected := &states.ResourceInstanceObjectSrc{ Status: states.ObjectReady, AttrsJSON: []byte("{\n \"ami\": null,\n \"id\": \"yes\"\n }"), - Dependencies: []addrs.Referenceable{}, + Dependencies: []addrs.AbsResource{}, + DependsOn: []addrs.Referenceable{}, } if !reflect.DeepEqual(actual, expected) { t.Fatalf("wrong new object\ngot: %swant: %s", spew.Sdump(actual), spew.Sdump(expected)) diff --git a/states/instance_object.go b/states/instance_object.go index 211b4c8b3..78e1dda93 100644 --- a/states/instance_object.go +++ b/states/instance_object.go @@ -29,12 +29,17 @@ type ResourceInstanceObject struct { // it was updated. Status ObjectStatus - // Dependencies is a set of other addresses in the same module which - // this instance depended on when the given attributes were evaluated. - // This is used to construct the dependency relationships for an object - // whose configuration is no longer available, such as if it has been - // removed from configuration altogether, or is now deposed. - Dependencies []addrs.Referenceable + // Dependencies is a set of absolute address to other resources this + // instance dependeded on when it was applied. This is used to construct + // the dependency relationships for an object whose configuration is no + // longer available, such as if it has been removed from configuration + // altogether, or is now deposed. + Dependencies []addrs.AbsResource + + // DependsOn corresponds to the deprecated `depends_on` field in the state. + // This field contained the configuration `depends_on` values, and some of + // the references from within a single module. + DependsOn []addrs.Referenceable } // ObjectStatus represents the status of a RemoteObject. diff --git a/states/instance_object_src.go b/states/instance_object_src.go index 62907ab76..4bb333057 100644 --- a/states/instance_object_src.go +++ b/states/instance_object_src.go @@ -53,7 +53,9 @@ type ResourceInstanceObjectSrc struct { // ResourceInstanceObject. Private []byte Status ObjectStatus - Dependencies []addrs.Referenceable + Dependencies []addrs.AbsResource + // deprecated + DependsOn []addrs.Referenceable } // Decode unmarshals the raw representation of the object attributes. Pass the diff --git a/states/state_deepcopy.go b/states/state_deepcopy.go index 8664f3bea..dfa1fbc05 100644 --- a/states/state_deepcopy.go +++ b/states/state_deepcopy.go @@ -153,8 +153,17 @@ func (obj *ResourceInstanceObjectSrc) DeepCopy() *ResourceInstanceObjectSrc { // Some addrs.Referencable implementations are technically mutable, but // we treat them as immutable by convention and so we don't deep-copy here. - dependencies := make([]addrs.Referenceable, len(obj.Dependencies)) - copy(dependencies, obj.Dependencies) + var dependencies []addrs.AbsResource + if obj.Dependencies != nil { + dependencies = make([]addrs.AbsResource, len(obj.Dependencies)) + copy(dependencies, obj.Dependencies) + } + + var dependsOn []addrs.Referenceable + if obj.DependsOn != nil { + dependsOn = make([]addrs.Referenceable, len(obj.DependsOn)) + copy(dependsOn, obj.DependsOn) + } return &ResourceInstanceObjectSrc{ Status: obj.Status, @@ -187,9 +196,9 @@ func (obj *ResourceInstanceObject) DeepCopy() *ResourceInstanceObject { // Some addrs.Referenceable implementations are technically mutable, but // we treat them as immutable by convention and so we don't deep-copy here. - var dependencies []addrs.Referenceable + var dependencies []addrs.AbsResource if obj.Dependencies != nil { - dependencies = make([]addrs.Referenceable, len(obj.Dependencies)) + dependencies = make([]addrs.AbsResource, len(obj.Dependencies)) copy(dependencies, obj.Dependencies) } diff --git a/states/state_test.go b/states/state_test.go index 618cfaafb..22a43859f 100644 --- a/states/state_test.go +++ b/states/state_test.go @@ -138,7 +138,7 @@ func TestStateDeepCopy(t *testing.T) { SchemaVersion: 1, AttrsJSON: []byte(`{"woozles":"confuzles"}`), Private: []byte("private data"), - Dependencies: []addrs.Referenceable{}, + Dependencies: []addrs.AbsResource{}, }, addrs.ProviderConfig{ Type: "test", @@ -155,11 +155,16 @@ func TestStateDeepCopy(t *testing.T) { SchemaVersion: 1, AttrsJSON: []byte(`{"woozles":"confuzles"}`), Private: []byte("private data"), - Dependencies: []addrs.Referenceable{addrs.Resource{ - Mode: addrs.ManagedResourceMode, - Type: "test_thing", - Name: "baz", - }}, + Dependencies: []addrs.AbsResource{ + { + Module: addrs.RootModuleInstance, + Resource: addrs.Resource{ + Mode: addrs.ManagedResourceMode, + Type: "test_thing", + Name: "baz", + }, + }, + }, }, addrs.ProviderConfig{ Type: "test", diff --git a/terraform/context_apply_test.go b/terraform/context_apply_test.go index 902e0dd5a..4e64109bb 100644 --- a/terraform/context_apply_test.go +++ b/terraform/context_apply_test.go @@ -2885,8 +2885,9 @@ func TestContext2Apply_orphanResource(t *testing.T) { s.SetResourceMeta(zeroAddr, states.EachList, providerAddr) s.SetResourceMeta(oneAddr, states.EachList, providerAddr) s.SetResourceInstanceCurrent(oneAddr.Instance(addrs.IntKey(0)), &states.ResourceInstanceObjectSrc{ - Status: states.ObjectReady, - AttrsJSON: []byte(`{}`), + Status: states.ObjectReady, + AttrsJSON: []byte(`{}`), + Dependencies: []addrs.AbsResource{}, }, providerAddr) }) if !cmp.Equal(state, want) {