Sequential Groupings
Community note
[!TIP] Hi there, OpenTofu community! The OpenTofu team prioritizes issues based on upvotes. Please make sure to upvote this issue and describe how it affects you in detail in the comments to show your support.
OpenTofu Version
$ tofu version
OpenTofu v1.12.6
on linux_amd64The problem in your OpenTofu project
Unable to control the recreation of resources/modules such that one instance of an active/standby cluster is completely recreated before the other ensuring that at least one instance remains online throughout the process.
Attempted Solutions
The closest it appears you can get today is the use of depends_on. However, during the above scenario, both will be destroyed in reverse order of dependency and then recreated in order of dependency. You have a time when both machines are gone.
Proposal
Propose that a lifecycle option called sequential_group or similar be added that will cause resources or modules that are members of the same group to be applied completely sequentially and cause a failure if one fails without proceeding on with other members in the group.
The use case for this is instances where you have, for example, an active/standby pair of machines deployed from a common image. A new image becomes available and both must be recreated. You want one to be completely recreated before the other.
This should also be applicable to modules, whereby all operations for resources within a module are completed before another module of the same group. For simplicity, it may be that a sequential_group can only contain modules OR resources. Resources within modules may be parallelized in the usual way.
Workarounds and Alternatives
Tried multiple incarnations of depends_on. The only way I can see that doesnt involve -target is to maintain an active stack and standby stack.
References
No response
Source: opentofu/opentofu