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
}