4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/chef/provider/aws_image.rb', line 4
def destroy_aws_object(image)
instance_id = image.tags['From-Instance']
Chef::Log.debug("Found From-Instance tag [#{instance_id}] on #{image.id}")
unless instance_id
image.block_device_mappings.map do |dev, opts|
snapshot = ec2.snapshots[opts[:snapshot_id]]
desc = snapshot.description
m = /CreateImage\(([^\)]+)\)/.match(desc)
if m
Chef::Log.debug("Found [#{instance_id}] from snapshot #{snapshot.id} on #{image.id}")
instance_id = m[1]
end
end
end
converge_by "delete image #{new_resource} in #{region}" do
image.delete
end
if instance_id
instance = new_resource.driver.ec2.instances[instance_id]
converge_by "waiting until instance #{instance.id} is :terminated" do
wait_for_status(instance, :terminated, [AWS::EC2::Errors::InvalidInstanceID::NotFound])
end
end
end
|