Class: Chef::Provider::AwsImage

Inherits:
Chef::Provisioning::AWSDriver::AWSProvider show all
Includes:
Chef::Provisioning::AWSDriver::TaggingStrategy::EC2ConvergeTags
Defined in:
lib/chef/provider/aws_image.rb

Constant Summary

Constants inherited from Chef::Provisioning::AWSDriver::AWSProvider

Chef::Provisioning::AWSDriver::AWSProvider::AWSResource

Instance Attribute Summary

Attributes inherited from Chef::Provisioning::AWSDriver::AWSProvider

#purging

Instance Method Summary collapse

Methods included from Chef::Provisioning::AWSDriver::TaggingStrategy::EC2ConvergeTags

#aws_tagger, #converge_tags

Methods inherited from Chef::Provisioning::AWSDriver::AWSProvider

#action_handler, #converge_by, #region, #whyrun_supported?

Instance Method Details

#destroy_aws_object(image) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/chef/provider/aws_image.rb', line 9

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
    # This is an old image and doesn't have the tag added - lets try and find it from the block device mapping
    image.block_device_mappings.map do |dev, opts|
      snapshot = new_resource.driver.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
    # As part of the image creation process, the source instance was automatically
    # destroyed - we just need to make sure that has completed successfully
    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, AWS::Core::Resource::NotFound])
    end
  end
end