Skip to content

Commit

Permalink
Add an InstanceState.Set method to set all fields
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jbardin committed Aug 25, 2016
1 parent 2a47b32 commit 0e6e206
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions terraform/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion terraform/state_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 0e6e206

Please sign in to comment.