4

Here's my problem - I'm using Hashicorp terraform to programmatically set up an Amazon c5 EC2 instance that has a couple of attached EBS drives. The c5 instances use nvme and end up remapping the names I assign in terraform (e.g. /dev/sdf) to nvme names (e.g. /dev/nvme1n1). The problem is that the mapping doesn't appear to be consistent. Upon reboot the drives sometimes get mapped in a different order. This means that my /etc/fstab which specifies /dev/nvme1n1 gets one drive one time and a different drive the next.

One solution to this is to use the UUID in the /etc/fstab file. This works fine, and I can get the UUID using ls -al /dev/disk/by-uuid/, however htis is a very clumsy process to automate.

Is there a way to just get the UUID directly from terraform so that I can put that in the fstab directly rather than having to do it by hand after the fact (or write a special script to automate this)?

Dave DeCaprio
  • 2,051
  • 17
  • 31

1 Answers1

2

I experienced this problem today. I'm not using terraform. Also, I was unable to solve the problem using UUIDs. Instead, I solved it by setting a label on the file system. You can do this with e2label (for ext*) or xfs_admin (for xfs). Once you have the label set, you can update your fstab to use the device path /dev/disk/by-label/<label>.

If you're creating your volume from an AWS provided snapshot, you'll need to manually:

  1. Create a volume (from that snapshot)
  2. Attach it to an EC2 instance (launch one just for this purpose if you need to)
  3. Mount it
  4. Set the label
  5. Create a snapshot
  6. Use that snapshot ID to create future volumes
Kyle Gibson
  • 1,150
  • 1
  • 9
  • 12