Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6f22213

Browse files
committedJan 21, 2018
Also delete snapshot after instance has been destroyed
1 parent 0d84032 commit 6f22213

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed
 

‎main.tf

+8
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ resource "aws_spot_instance_request" "parsec" {
9999
}
100100

101101
depends_on = ["null_resource.delete_volume"]
102+
depends_on = ["null_resource.delete_snapshot"]
102103
}
103104

104105
resource "null_resource" "delete_volume" {
@@ -107,3 +108,10 @@ resource "null_resource" "delete_volume" {
107108
command = "aws ec2 delete-volume --volume-id ${data.aws_ebs_volume.xvdb.volume_id}"
108109
}
109110
}
111+
112+
resource "null_resource" "delete_snapshot" {
113+
provisioner "local-exec" {
114+
when = "destroy"
115+
command = "aws ec2 delete-snapshot --snapshot-id ${data.aws_ebs_volume.xvdb.snapshot_id}"
116+
}
117+
}

‎output.tf

+4
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,8 @@ output "ami_name" {
2424

2525
output "xvdb_volume_id" {
2626
value = "${data.aws_ebs_volume.xvdb.volume_id}"
27+
}
28+
29+
output "xvdb_snapshot_id" {
30+
value = "${data.aws_ebs_volume.xvdb.snapshot_id}"
2731
}

0 commit comments

Comments
 (0)
Please sign in to comment.