How to tag non-root snapshots when creating an AMI?

Hello,
I am creating AMIs from existing EC2 instance, that has 2 ebs volumes. I am using “aws_ami_from_instance”, but then the disk snapshots do not have tags. I found a way from hashi’s github to tag ‘manually’ the root snapshot, since “root_snapshot_id” is exported from the ami resource, but what can I do about the other disk?

resource "aws_ami_from_instance" "server_ami" {
  name                = "${var.env}.v${local.new_version}.ami"
  source_instance_id  = data.aws_instance.server.id
  tags = {
    Name              = "${var.env}.v${local.new_version}.ami"
    Version           = local.new_version
  }
}

resource "aws_ec2_tag" "server_ami_tags" {
  for_each    = { for tag in var.tags : tag.tag => tag }
  resource_id = aws_ami_from_instance.server_ami.root_snapshot_id
  key         = each.value.tag
  value       = each.value.value
}

@tyger According to the aws_ami_from_instance resource documentation, it has all of the attributes from the aws_ami resource, which includes ebs_block_device blocks that has a snapshot_id attribute. Perhaps you can use this to get the non-root snapshot IDs with a wildcard.