From 0e6e206465260723e2ca7fce6ed8eed5eda8495f Mon Sep 17 00:00:00 2001 From: James Bardin Date: Wed, 24 Aug 2016 15:48:47 -0400 Subject: [PATCH] Add an InstanceState.Set method to set all fields We con no longer copy an InstanceState via a simple dereference+assignment because of the mutex which can't be copied. This adds a set method to properly set all field from another InstanceState, and take the appropriate locks while doing so. --- terraform/state.go | 15 +++++++++++++++ terraform/state_add.go | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/terraform/state.go b/terraform/state.go index 5054ac3f3..f65176074 100644 --- a/terraform/state.go +++ b/terraform/state.go @@ -1332,6 +1332,21 @@ func (i *InstanceState) init() { i.Ephemeral.init() } +// Copy all the Fields from another InstanceState +func (i *InstanceState) Set(from *InstanceState) { + i.Lock() + defer i.Unlock() + + from.Lock() + defer from.Unlock() + + i.ID = from.ID + i.Attributes = from.Attributes + i.Ephemeral = from.Ephemeral + i.Meta = from.Meta + i.Tainted = from.Tainted +} + func (i *InstanceState) DeepCopy() *InstanceState { copy, err := copystructure.LockedCopy(i) if err != nil { diff --git a/terraform/state_add.go b/terraform/state_add.go index 8255a3eb4..688e05d70 100644 --- a/terraform/state_add.go +++ b/terraform/state_add.go @@ -219,7 +219,7 @@ func stateAddFunc_Instance_Instance(s *State, fromAddr, addr *ResourceAddress, r instance := instanceRaw.(*InstanceState) // Set it - *instance = *src + instance.Set(src) return nil }