0
votes

I have attached two EBS Volumes to a EC2 instance. Using terraform, I want to output the ID's of the attached volumes. 1. I used the Data Source "aws_instance" but it only shows One attached volume. 2. Also tried using Data Source "aws_ebs_volume", but still get only one volume.

Please advice.

Code:

*data "aws_instance" "foo" {
  instance_id = "i-kljo......b0e"
}*

*output "ebs_block_device" {
  value = "${data.aws_instance.foo.ebs_block_device}"
}*
-------------------------------------------------------
*data "aws_ebs_volume" "ebs_volume" {
  most_recent = true
  filter {
    name   = "tag:Name"
    values = ["Test_001"]
  }
}*

*output "ebs_all_volumnes" {
  value = ["${data.aws_ebs_volume.ebs_volume.id}"]
}*
1

1 Answers

0
votes

A datasource can only output one datasource, so only one EBS volume/datasource.

According to the Terraform Documentation

most_recent - (Optional) If more than one result is returned, use the most recent Volume.

filter - (Optional) One or more name/value pairs to filter off of. There are several valid keys, for a full reference, check out describe-volumes in the AWS CLI reference.

You'll have to remove the most_recent and work with filter instead. Supplying two datasources