From bac4e0a3dec440511b92b306506a6e5f9b966e5e Mon Sep 17 00:00:00 2001 From: James Bardin Date: Thu, 25 Mar 2021 12:57:21 -0400 Subject: [PATCH] fix ResourceInstanceObject.DeepCopy missing CreateBeforeDestroy --- states/state_deepcopy.go | 9 +++++---- states/state_test.go | 38 +++++++++++++++++++++++++++++++++----- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/states/state_deepcopy.go b/states/state_deepcopy.go index ad3610a720..74f21de03c 100644 --- a/states/state_deepcopy.go +++ b/states/state_deepcopy.go @@ -204,10 +204,11 @@ func (o *ResourceInstanceObject) DeepCopy() *ResourceInstanceObject { } return &ResourceInstanceObject{ - Value: o.Value, - Status: o.Status, - Private: private, - Dependencies: dependencies, + Value: o.Value, + Status: o.Status, + Private: private, + Dependencies: dependencies, + CreateBeforeDestroy: o.CreateBeforeDestroy, } } diff --git a/states/state_test.go b/states/state_test.go index 6b3eb815e3..b430ef78e2 100644 --- a/states/state_test.go +++ b/states/state_test.go @@ -1,6 +1,7 @@ package states import ( + "reflect" "testing" "github.com/go-test/deep" @@ -191,6 +192,32 @@ func TestState(t *testing.T) { } } +func TestStateDeepCopyObject(t *testing.T) { + obj := &ResourceInstanceObject{ + Value: cty.ObjectVal(map[string]cty.Value{ + "id": cty.StringVal("id"), + }), + Private: []byte("private"), + Status: ObjectReady, + Dependencies: []addrs.ConfigResource{ + { + Module: addrs.RootModule, + Resource: addrs.Resource{ + Mode: addrs.ManagedResourceMode, + Type: "test_instance", + Name: "bar", + }, + }, + }, + CreateBeforeDestroy: true, + } + + objCopy := obj.DeepCopy() + if !reflect.DeepEqual(obj, objCopy) { + t.Fatalf("not equal\n%#v\n%#v", obj, objCopy) + } +} + func TestStateDeepCopy(t *testing.T) { state := NewState() @@ -209,11 +236,12 @@ func TestStateDeepCopy(t *testing.T) { Name: "baz", }.Instance(addrs.IntKey(0)), &ResourceInstanceObjectSrc{ - Status: ObjectReady, - SchemaVersion: 1, - AttrsJSON: []byte(`{"woozles":"confuzles"}`), - Private: []byte("private data"), - Dependencies: []addrs.ConfigResource{}, + Status: ObjectReady, + SchemaVersion: 1, + AttrsJSON: []byte(`{"woozles":"confuzles"}`), + Private: []byte("private data"), + Dependencies: []addrs.ConfigResource{}, + CreateBeforeDestroy: true, }, addrs.AbsProviderConfig{ Provider: addrs.NewDefaultProvider("test"),