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:
parent
2a47b32374
commit
0e6e206465
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue