Q:

Using Terraform to create multiple AWS EBS volumes from shared snapshot and tagging them with snapshot description

As title described, I'm trying to create multiple AWS EBS from shared snapshots.
I am using data "aws_ebs_snapshot_ids" to get the list of snapshots and then use for_each to create the EBS volumes. So something like this
data "aws_ebs_snapshot_ids" "shared_snapshot_ids" {
  filter {
   name   = "description"
    values = ["snap-test*"]
  }
}

resource "aws_ebs_volume" "shared_snapshot_volume" {
    for_each = toset(data.aws_ebs_snapshot_ids.shared_snapshot_ids.ids)
    snapshot_id = each.value
    availability_zone = "us-west-1b"

Now I want to tag these volumes with the snapshot description, but data "aws_ebs_snapshot_ids doesn't return description, just a list of IDs. So I have to use data "aws_ebs_snapshot" with the for_each loop to get the description, and it returns a map for the snapshots. 
data "aws_ebs_snapshot" "shared_snapshot" {
  for_each = toset(data.aws_ebs_snapshot_ids.shared_snapshot_ids.ids)
  snapshot_ids = ["${each.value}"]
}

output "shared_snapshot" {
  value = data.aws_ebs_snapshot.shared_snapshot
}

"snap-0000000000001" = {
    "data_encryption_key_id" = ""
    "description" = "snap-test-2"
    "encrypted" = false
    "id" = "snap-0000000000001"
    "kms_key_id" = ""
    "most_recent" = false
    "owner_alias" = ""
    "owner_id" = ""
    "snapshot_id" = "snap-0000000000001"
    "snapshot_ids" = [
      "snap-0000000000001",
    ]
    "state" = "completed"
    "tags" = {}
    "volume_id" = ""
    "volume_size" = 100
  }
  "snap-0000000000000" = {
    "data_encryption_key_id" = ""
    "description" = "snap-test-1"
    "encrypted" = false
    "id" = "snap-0000000000000"
    "kms_key_id" = ""
    "most_recent" = false
    "owner_alias" = ""
    "owner_id" = ""
    "snapshot_id" = "snap-0000000000000"
    "snapshot_ids" = [
      "snap-0000000000000",
    ]
    "state" = "completed"
    "tags" = {}
    "volume_id" = "vol-0000000000000"
    "volume_size" = 8
  }
}

I don't know how or if Terraform can do this but I guess it will need to be something like 
resource "aws_ebs_volume" "shared_snapshot_volume" {
    for_each = toset(data.aws_ebs_snapshot_ids.shared_snapshot_ids.ids)
    snapshot_id = each.value
    availability_zone = "us-west-1b"

    tags = {
      Name    = data.aws_ebs_snapshot.shared_snapshot.[${each.value}].description
    }
}

This doesn't work since it's a nested interpolation. Please let me know if this is achievable for Terraform or I need to use something else.

A:

You can use an aws_ebs_snapshot data source to get the details for those snapshot IDs:
data "aws_ebs_snapshot" "shared_snapshots" {
  for_each = toset(data.aws_ebs_snapshot_ids.shared_snapshot_ids.ids)
  snapshot_ids = [each.value]
}

Then you can build your EBS volumes with detailed properties like snapshot_id and description like this:
resource "aws_ebs_volume" "shared_snapshot_volume" {
  for_each = data.aws_ebs_snapshot.shared_snapshots
    snapshot_id = each.value.snapshot_id
    availability_zone = "us-west-1b"

  tags = {
    Name = each.value.description
  }
}

