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.
This commit is contained in:
James Bardin 2016-08-24 15:48:47 -04:00
parent 2a47b32374
commit 0e6e206465
2 changed files with 16 additions and 1 deletions

View File

@ -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 {

View File

@ -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
}