How to rollback a release if we've used the tf "moved" block?

Usually to rollback a release, we run the deploy job from the previous release/hotfix branch.

If we use the “moved” block in terraform, how does that impact the rollback? i.e. if we’ve moved an EBS volume from one server to another, how do we move it back? Can we just flip the moved from/to values or is it more complex?

Terraform handles moved blocks by checking if there’s an object tracked in the state whose address matches the from address, and if so it rebinds that object to the to address before doing any other work. A moved block is effectively inert if there is no object currently bound to the from address.

Therefore you can swap the from and to addresses if you want to rebind the already-moved address back to where it started again.

If you are using the same module in multiple workspaces or multiple times in the same workspace then this might require more care. In effect, you are removing a moved block by making this change – modifying either from or to makes this effectively an entirely different moved block as far as Terraform is concerned – and so the same concerns would apply as described in the documentation about removing moved blocks. If this module is used only once throughout your infrastructure and therefore there is only one possible state it could be used with, these concerns don’t apply.

If you’d rather not mess with the configuration for rollback, a potential alternative is to manually run terraform state mv to perform the same operation imperatively from the command line, and then you’ll still have the moved block ready to move the object back to the new address again once you’ve fixed whatever prompted you to roll back.

In general I’d recommend a “roll forward with fixes” strategy for dealing with Terraform changes, due to its stateful nature. This is similar to how not all database schema migrations can be safely rolled back when dealing with a database-driven application. But as long as you keep the state in mind when you do it, and carefully read Terraform’s plan output to make sure it’s not proposing to do something other than what you intended, you can use a rollback strategy if you wish.