How to read the volume ID of the EC2 instance using Terraform

0 votes

Hi Team,

I have one EC2 instance in AWS. I have attached one volume to the instance. Can anyone tell me how to read the volume ID of the EC2 instance using Terraform?

Dec 4, 2020 in Terraform by akhtar
• 38,230 points
1,774 views

1 answer to this question.

0 votes

Hi@akhtar,

You won't be able to extract EBS details from aws_instance since it's the AWS side that provides an EBS volume to the resource. But you can define an EBS data source with some filter.

data "aws_ebs_volume" "ebs_volume" {
  most_recent = true
  filter {
    name   = "attachment.instance-id"
    values = ["${aws_instance.DCOS-master3.id}"]
  }
}
output "ebs_volume_id" {
  value = "${data.aws_ebs_volume.ebs_volume.id}"
}
answered Dec 4, 2020 by MD
• 95,440 points

Related Questions In Terraform

0 votes
1 answer

How to launch EC2 windows instance with powershell script using terraform?

Hi, In your Terraform code, you have written ...READ MORE

answered Jul 21, 2020 in Terraform by MD
• 95,440 points
3,633 views
0 votes
1 answer

How to attach Elastic IP in EC2 instance using Terraform code?

Hi@akhtar, You can use aws_eip resource in your ...READ MORE

answered Jul 22, 2020 in Terraform by MD
• 95,440 points
8,152 views
0 votes
1 answer

How to read input from CSV file or any file instead of using tfvars file in Terraform?

Hi, You can use the file function in Terraform. ...READ MORE

answered Jul 27, 2020 in Terraform by MD
• 95,440 points
5,044 views
+2 votes
1 answer

How to attach an elastic load balancer with ec2 instance using Terraform?

Hi@akhtar, You can use aws_elb_attachment resource in Terraform. ...READ MORE

answered Aug 17, 2020 in Terraform by MD
• 95,440 points
2,586 views
0 votes
1 answer

Create Snapshot of EBS and attach to EC2 using Terraform

You can also create a snapshot using ...READ MORE

answered Oct 29, 2018 in AWS by Priyaj
• 58,090 points
1,898 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

How to attach an EBS volume to EC2 instance using terraform?

Hi@akhtar, You can use aws_volume_attachment resource to attach ...READ MORE

answered Jun 12, 2020 in Terraform by MD
• 95,440 points
8,440 views
0 votes
1 answer

How to do ssh in EC2 instance using Terraform?

Hi@akhtar, To ssh in your EC2 instance, you ...READ MORE

answered Jun 15, 2020 in Terraform by MD
• 95,440 points
6,730 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP