diff --git a/terraform/context_apply_test.go b/terraform/context_apply_test.go index fe5f404676..91961e6ec4 100644 --- a/terraform/context_apply_test.go +++ b/terraform/context_apply_test.go @@ -1008,8 +1008,9 @@ func TestContext2Apply_createBeforeDestroy_hook(t *testing.T) { var actualLock sync.Mutex h.PostApplyFn = func(n *InstanceInfo, s *InstanceState, e error) (HookAction, error) { actualLock.Lock() + defer actualLock.Unlock() - actual = append(actual, n.Id) + actual = append(actual, s.String()) return HookActionContinue, nil } @@ -1034,7 +1035,11 @@ func TestContext2Apply_createBeforeDestroy_hook(t *testing.T) { t.Fatalf("apply errors: %s", diags.Err()) } - expected := []string{"aws_instance.bar", "aws_instance.bar (deposed #0)"} + expected := []string{ + "ID = foo\nrequire_new = xyz\ntype = aws_instance\nTainted = false\n", + "", + } + if !reflect.DeepEqual(actual, expected) { t.Fatalf("bad: %#v", actual) } diff --git a/terraform/state.go b/terraform/state.go index 0d303b0fef..bdc2538d98 100644 --- a/terraform/state.go +++ b/terraform/state.go @@ -1770,13 +1770,19 @@ func (s *InstanceState) MergeDiff(d *InstanceDiff) *InstanceState { } func (s *InstanceState) String() string { + notCreated := "" + + if s == nil { + return notCreated + } + s.Lock() defer s.Unlock() var buf bytes.Buffer - if s == nil || s.ID == "" { - return "" + if s.ID == "" { + return notCreated } buf.WriteString(fmt.Sprintf("ID = %s\n", s.ID))