mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-13 09:32:24 -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{
|
expected := &states.ResourceInstanceObjectSrc{
|
||||||
Status: states.ObjectReady,
|
Status: states.ObjectReady,
|
||||||
AttrsJSON: []byte("{\n \"ami\": null,\n \"id\": \"yes\"\n }"),
|
AttrsJSON: []byte("{\n \"ami\": null,\n \"id\": \"yes\"\n }"),
|
||||||
Dependencies: []addrs.Referenceable{},
|
Dependencies: []addrs.AbsResource{},
|
||||||
|
DependsOn: []addrs.Referenceable{},
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(actual, expected) {
|
if !reflect.DeepEqual(actual, expected) {
|
||||||
t.Fatalf("wrong new object\ngot: %swant: %s", spew.Sdump(actual), spew.Sdump(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{
|
expected := &states.ResourceInstanceObjectSrc{
|
||||||
Status: states.ObjectReady,
|
Status: states.ObjectReady,
|
||||||
AttrsJSON: []byte("{\n \"ami\": null,\n \"id\": \"yes\"\n }"),
|
AttrsJSON: []byte("{\n \"ami\": null,\n \"id\": \"yes\"\n }"),
|
||||||
Dependencies: []addrs.Referenceable{},
|
Dependencies: []addrs.AbsResource{},
|
||||||
|
DependsOn: []addrs.Referenceable{},
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(actual, expected) {
|
if !reflect.DeepEqual(actual, expected) {
|
||||||
t.Fatalf("wrong new object\ngot: %swant: %s", spew.Sdump(actual), spew.Sdump(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{
|
expected := &states.ResourceInstanceObjectSrc{
|
||||||
Status: states.ObjectReady,
|
Status: states.ObjectReady,
|
||||||
AttrsJSON: []byte("{\n \"ami\": null,\n \"id\": \"changed\"\n }"),
|
AttrsJSON: []byte("{\n \"ami\": null,\n \"id\": \"changed\"\n }"),
|
||||||
Dependencies: []addrs.Referenceable{},
|
Dependencies: []addrs.AbsResource{},
|
||||||
|
DependsOn: []addrs.Referenceable{},
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(actual, expected) {
|
if !reflect.DeepEqual(actual, expected) {
|
||||||
t.Fatalf("wrong new object\ngot: %swant: %s", spew.Sdump(actual), spew.Sdump(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{
|
expected := &states.ResourceInstanceObjectSrc{
|
||||||
Status: states.ObjectReady,
|
Status: states.ObjectReady,
|
||||||
AttrsJSON: []byte("{\n \"ami\": null,\n \"id\": \"yes\"\n }"),
|
AttrsJSON: []byte("{\n \"ami\": null,\n \"id\": \"yes\"\n }"),
|
||||||
Dependencies: []addrs.Referenceable{},
|
Dependencies: []addrs.AbsResource{},
|
||||||
|
DependsOn: []addrs.Referenceable{},
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(actual, expected) {
|
if !reflect.DeepEqual(actual, expected) {
|
||||||
t.Fatalf("wrong new object\ngot: %swant: %s", spew.Sdump(actual), spew.Sdump(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.
|
// it was updated.
|
||||||
Status ObjectStatus
|
Status ObjectStatus
|
||||||
|
|
||||||
// Dependencies is a set of other addresses in the same module which
|
// Dependencies is a set of absolute address to other resources this
|
||||||
// this instance depended on when the given attributes were evaluated.
|
// instance dependeded on when it was applied. This is used to construct
|
||||||
// This is used to construct the dependency relationships for an object
|
// the dependency relationships for an object whose configuration is no
|
||||||
// whose configuration is no longer available, such as if it has been
|
// longer available, such as if it has been removed from configuration
|
||||||
// removed from configuration altogether, or is now deposed.
|
// altogether, or is now deposed.
|
||||||
Dependencies []addrs.Referenceable
|
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.
|
// ObjectStatus represents the status of a RemoteObject.
|
||||||
|
@ -53,7 +53,9 @@ type ResourceInstanceObjectSrc struct {
|
|||||||
// ResourceInstanceObject.
|
// ResourceInstanceObject.
|
||||||
Private []byte
|
Private []byte
|
||||||
Status ObjectStatus
|
Status ObjectStatus
|
||||||
Dependencies []addrs.Referenceable
|
Dependencies []addrs.AbsResource
|
||||||
|
// deprecated
|
||||||
|
DependsOn []addrs.Referenceable
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decode unmarshals the raw representation of the object attributes. Pass the
|
// 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
|
// Some addrs.Referencable implementations are technically mutable, but
|
||||||
// we treat them as immutable by convention and so we don't deep-copy here.
|
// we treat them as immutable by convention and so we don't deep-copy here.
|
||||||
dependencies := make([]addrs.Referenceable, len(obj.Dependencies))
|
var dependencies []addrs.AbsResource
|
||||||
|
if obj.Dependencies != nil {
|
||||||
|
dependencies = make([]addrs.AbsResource, len(obj.Dependencies))
|
||||||
copy(dependencies, 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{
|
return &ResourceInstanceObjectSrc{
|
||||||
Status: obj.Status,
|
Status: obj.Status,
|
||||||
@ -187,9 +196,9 @@ func (obj *ResourceInstanceObject) DeepCopy() *ResourceInstanceObject {
|
|||||||
|
|
||||||
// Some addrs.Referenceable implementations are technically mutable, but
|
// Some addrs.Referenceable implementations are technically mutable, but
|
||||||
// we treat them as immutable by convention and so we don't deep-copy here.
|
// 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 {
|
if obj.Dependencies != nil {
|
||||||
dependencies = make([]addrs.Referenceable, len(obj.Dependencies))
|
dependencies = make([]addrs.AbsResource, len(obj.Dependencies))
|
||||||
copy(dependencies, obj.Dependencies)
|
copy(dependencies, obj.Dependencies)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ func TestStateDeepCopy(t *testing.T) {
|
|||||||
SchemaVersion: 1,
|
SchemaVersion: 1,
|
||||||
AttrsJSON: []byte(`{"woozles":"confuzles"}`),
|
AttrsJSON: []byte(`{"woozles":"confuzles"}`),
|
||||||
Private: []byte("private data"),
|
Private: []byte("private data"),
|
||||||
Dependencies: []addrs.Referenceable{},
|
Dependencies: []addrs.AbsResource{},
|
||||||
},
|
},
|
||||||
addrs.ProviderConfig{
|
addrs.ProviderConfig{
|
||||||
Type: "test",
|
Type: "test",
|
||||||
@ -155,11 +155,16 @@ func TestStateDeepCopy(t *testing.T) {
|
|||||||
SchemaVersion: 1,
|
SchemaVersion: 1,
|
||||||
AttrsJSON: []byte(`{"woozles":"confuzles"}`),
|
AttrsJSON: []byte(`{"woozles":"confuzles"}`),
|
||||||
Private: []byte("private data"),
|
Private: []byte("private data"),
|
||||||
Dependencies: []addrs.Referenceable{addrs.Resource{
|
Dependencies: []addrs.AbsResource{
|
||||||
|
{
|
||||||
|
Module: addrs.RootModuleInstance,
|
||||||
|
Resource: addrs.Resource{
|
||||||
Mode: addrs.ManagedResourceMode,
|
Mode: addrs.ManagedResourceMode,
|
||||||
Type: "test_thing",
|
Type: "test_thing",
|
||||||
Name: "baz",
|
Name: "baz",
|
||||||
}},
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
addrs.ProviderConfig{
|
addrs.ProviderConfig{
|
||||||
Type: "test",
|
Type: "test",
|
||||||
|
@ -2887,6 +2887,7 @@ func TestContext2Apply_orphanResource(t *testing.T) {
|
|||||||
s.SetResourceInstanceCurrent(oneAddr.Instance(addrs.IntKey(0)), &states.ResourceInstanceObjectSrc{
|
s.SetResourceInstanceCurrent(oneAddr.Instance(addrs.IntKey(0)), &states.ResourceInstanceObjectSrc{
|
||||||
Status: states.ObjectReady,
|
Status: states.ObjectReady,
|
||||||
AttrsJSON: []byte(`{}`),
|
AttrsJSON: []byte(`{}`),
|
||||||
|
Dependencies: []addrs.AbsResource{},
|
||||||
}, providerAddr)
|
}, providerAddr)
|
||||||
})
|
})
|
||||||
if !cmp.Equal(state, want) {
|
if !cmp.Equal(state, want) {
|
||||||
|
Loading…
Reference in New Issue
Block a user