mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-25 08:21:07 -06:00
change state dependencies to AbsResource addrs
We need to be able to reference all possible dependencies for ordering when the configuration is no longer present, which means that absolute addresses must be used. Since this is only to recreate the proper ordering for instance destruction, only resources addresses need to be listed rather than individual instance addresses.
This commit is contained in:
parent
744b835e17
commit
2c3c011f20
@ -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))
|
||||
|
@ -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.
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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",
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user