Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Complicate our RequiresReplace(If) logic.
Fixes #187, supercedes #203. This changes the logic on our RequiresReplace function in the following ways: * if the attribute being modified has not changed, RequiresReplace isn't changed. This prevents the resource from being destroyed and recreated when _any_ attribute changes, limiting it only to the attribute with RequiresReplace set on it. * if the attribute being modified is computed and is null in the config, RequiresReplace isn't changed. This prevents the resource from being destroyed and recreated when the provider returns an unknown value in the plan, or even a new, provider-controlled value, because it's unlikely the practitioners expect their resource to be destroyed and recreated when an attribute out of their control changes. This has the unfortunate side-effect that practitioners removing an Optional+Computed field from their config will not prompt the default RequiresReplace behavior, but providers can specify their own, special plan modifier that has a better understanding of practitioner intent in that case. * if the resource is being created or destroyed, RequiresReplace isn't changed. This prevents the resource from being marked for destruction and recreation when it's just now being created or destroyed, which would be nonsensical. RequiresReplaceIf gets all these changes and an additional change that it will only set RequiresReplace to true, never to false, as its Modify method's GoDoc indicated. This means that RequiresReplaceIf functions can be chained, and that RequiresReplaceIf won't overwrite previous plan modifiers' determinations on whether or not the resource should be destroyed and recreated. Tests were added for RequiresReplace and RequiresReplaceIf to test these invariants.
- Loading branch information