When activate=true
, always read and clone from the active version
#423
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR implements the proposed solution in #416, and fixes the bug reported in #419.
There are two key points in the service resource lifecycle where the service version is particularly important. The first is when reading the state, and the second is when cloning a version to make updates to the service. The same version must be used at both of these points to ensure that the plan, based on the diff between the state and the configuration, is applied to the same version that the plan assumed it would be. Violating this rule leads to bugs such as the one in #419.
Updates are always based off
cloned_version
, andcloned_version
is always the last version that Terraform made changes to. When the provider has finished making updates, it setscloned_version
to the new version it has just created, so this is always true.However, the version that the state is read from depends on whether
activate
istrue
. If so, then state is read from theactive_version
, and it was previously assumed that this would always be the same ascloned_version
as thecloned_version
was always activated after it was created. Ifactivate
wasfalse
, then the state would be read fromcloned_version
. The rationale behind this is laid out in the second paragraph of #416, and a snippet is given below:However, the assumption that
cloned_version
andactive_version
would always match was incorrect. It is valid whenactivate
isfalse
, but whenactivate
istrue
, it does not account for the fact that the version could be created and activated outside of Terraform. In this case, the version that state is read from, and the one the updates are applied to, can be different, and errors can occur. The following diagram illustrates this case:The green section shows the case where the assumption is valid (no changes outside of Terraform). The red section shows how the mismatch occurs when a new version is activated externally.
This commit changes the behaviour so that, when
activate
istrue
, the value ofcloned_version
is updated on every state read to match the currently active version. This ensures that the above assumption is valid, even when a version is cloned and activated outside of Terraform. The following diagram shows how the previous sequence is changed.With this fix in place, it should now always be true that the same version will be used for reading the state and making updates to. It should also mean that the behaviour is more in line with what users expect as, when
activate
istrue
, they can make changes to the active version and see them reflected in the next Terraform plan, as you would see with a resource that does not use versioning.There is also an acceptance test added to replicate the behaviour in #419, to validate that this has been fixed.