'How to delete the AMI and snapshot simultaneously during terraform destroy?

In my case, AWS AMI was created by packer and deleting the image via terraform (0.11.6 version) using terraform import and terraform destroy. Once after importing the existing AMI, I could see the root_snapshot_id details inside the .tfstate file. But during the terraform destroy, only the AMI is getting deleted and the associated snapshot could not be deleted.

To achieve in a tricky way, I was trying to import the snapshot using terraform. But unfortunately, terraform does not support the import option for snapshots.

Expected: AMI should be deregistered and delete the appropriate snapshot simultaneously.

Actual result: Only AMI is deleted and snapshot still exists.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source