I have been trying, to no avail, to Terraform the following setup in Azure:
A Linux VM from a Packer-created custom VM image with an additional persistent, managed and encrypted data disk attached to said VM, but lives externally in case I want to recreate the VM with a newer (more updated, secure) version of the custom image, without losing any of the data saved to the external disk (imagine a node in a database cluster). And went on to do the following:
- Initially, I tried using the
azurerm_managed_diskand aazurerm_virtual_machine_data_disk_attachmentwith the VM resource, but the issue is that if you just create a disk like this (withcreate_optionset toEmpty) the disk will be unformatted, unpartitioned, and unmounted. Basically unusable unless something script is ran on the VM. - My thinking went: ok, I'll just run a
cloud-initor provisioner block thingie to partition/mount the disk and that's it. But: if I do this, when I rotate the VM, the script will run again and re-format/partition the disk, hence deleting any data I might have saved. - I also tried creating a custom image with an additional data disk with Packer, and using
FromImagein theazurerm_managed_disk'screate_option, but it turns out it only works when referencing marketplace images and custom images are not supported
The only viable thing I can now think of is going back to approach 2 and make a smarter script that runs only if the attached disk is not partitioned.
Is there an alternative approach I'm not seeing? Can someone help me validate this thinking?
My additional concern is regarding encryption in said disks, as I don't know if this will be an issue when adopting either approach.