Why does it delete snapshot even though I used ignore_changes?

I have made module that create aws ebs snapshot using volume_id.
In order to solve the dependency problem, the changed volume_id was ignored using lifecycle ignore_changes.
However, if you delete the volume_id from the list, the snapshot is also deleted.
Why is this happening?
please let me know.

locals {
  ami_list = {

    add_ebs = {
      "helloec2"    = {
        volume_id   = ["vol-05d530cd333625598",""]
      }
    }

  }
}

module "add_snapshot" {
    source         = "./module/AMI/Add_ebs"
    for_each       = local.ami_list.add_ebs
    name           = each.key
    volume_ids     = each.value.volume_id
}
# module add_snapshot
resource "aws_ebs_snapshot" "data_ebs_snapshot" {
  for_each         = toset(var.volume_ids)
  volume_id        = each.key
  tags = {
    Name           = "snapshot-data-${each.key}"
  }
  
  lifecycle {
    ignore_changes = [
      volume_id
    ]
  }
}

@kyo-hyun The ignore_changes meta-argument applies only to update scenarios, not destroy. When you remove the value from var.volume_ids, you are effectively removing the (instance of) resource from the config completely, which triggers its destruction on apply.

Logically speaking, you’d need to first remove the resource from the state before you remove it from the config in order to not destroy it. Unfortunately you can only do it via the terraform state rm command manually. You’d have to coordinate running this command and removing the volume ID from your variable somehow.

1 Like

Thank you for your answer. I understood 100% !!