Terraform – Mount EBS volume as part of user_data on an linux EC2 machine

by Sanjeev on February 19, 2017

Assumptions : You have an EC2 machine running with an attached EBS volume.
Goal : To learn how to manually/automatically mount the volume

Below is the terraform excerpt to add an ebs volume


  • Manual: Login to EC2 machine and mount the EBS Volume

  • Automatic: Mount the disk as part of user data



{ 5 comments… read them below or add one }

Sheifali July 17, 2017 at 9:45 AM

Really helpful


John Markston July 23, 2017 at 4:45 PM

Good work Sanjay, this really saved me a bunch of time after I ran into an Ansible bug that prevented me from doing this.


imrickysingh November 3, 2017 at 2:00 PM

How do you know that the attached volume name would be xvdg
It could be anything and that depends on AMI in aws.


Leon Wong November 23, 2017 at 7:54 AM

He has already defines it on the ebs_block_device under device_name as ../sdg which also translates to xvdg on some linux AMI


Anthony Cleaves December 8, 2017 at 9:49 AM

I ran into problems using this, as the volume wasn’t created (it’s 1500gb) and it silently failed.


Leave a Comment

Previous post:

Next post: