core: InstanceDiff.ApplyToValue correctly handle creates
We previously tried to take a shortcut for an empty diff, just returning the given value directly. This is incorrect in the weird case where we're creating a new instance but it has no attributes (and thus an empty diff) because in that case we'd return the given null value, turning the result into a no-op or destroy change. To fix this, we just always do the work to construct a new value, even if we might end up doing all this just to reconstruct the same value we started with in some cases.
This commit is contained in:
parent
27745af0ea
commit
e488ff126e
|
@ -415,10 +415,10 @@ func (d *InstanceDiff) Unlock() { d.mu.Unlock() }
|
|||
// This method is intended for shimming old subsystems that still use this
|
||||
// legacy diff type to work with the new-style types.
|
||||
func (d *InstanceDiff) ApplyToValue(base cty.Value, schema *configschema.Block) (cty.Value, error) {
|
||||
// No diff means the state is unchanged.
|
||||
if d.Empty() {
|
||||
return base, nil
|
||||
}
|
||||
// We always build a new value here, even if the given diff is "empty",
|
||||
// because we might be planning to create a new instance that happens
|
||||
// to have no attributes set, and so we want to produce an empty object
|
||||
// rather than just echoing back the null old value.
|
||||
|
||||
// Create an InstanceState attributes from our existing state.
|
||||
// We can use this to more easily apply the diff changes.
|
||||
|
|
Loading…
Reference in New Issue