Prevent data disks from being detached before VM is shut down

We’re operating on an immutable infrastructure basis, so we redeploy our servers whenever we have configuration changes to apply. Due to the azurerm_linux_virtual_machine resource not having support for attaching data disks we’re using azurerm_virtual_machine_data_disk_attachment to attach them after the machine has been created.

The problem we have is that when terraform goes to replace a VM it first deletes the disk attachment, which pulls the disk from the VM while the service (in this case PostgreSQL) is still running and potentially still writing, which easily leads to disk corruption.

Is there currently any way to prevent the data disks from being detached before the VM has been shut down? Or is there another workaround that we could apply here to prevent disk corruption?