Class: Chef::Provider::AwsImage
- Inherits:
-
Chef::Provisioning::AWSDriver::AWSProvider
- Object
- LWRPBase
- Chef::Provisioning::AWSDriver::AWSProvider
- Chef::Provider::AwsImage
- 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
Instance Method Summary collapse
Methods included from Chef::Provisioning::AWSDriver::TaggingStrategy::EC2ConvergeTags
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 36 37 38 39 40 41 42 43 |
# File 'lib/chef/provider/aws_image.rb', line 9 def destroy_aws_object(image) instance_id = image..map { |t| [t.key, t.value] }.to_h["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_resource.snapshot(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 "deregister image #{new_resource} in #{region}" do image.deregister 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_resource.instance(instance_id) converge_by "waiting until instance #{instance.id} is :terminated" do if instance.exists? instance.wait_until_terminated do |w| w.delay = 5 w.max_attempts = 60 w.before_wait do |attempts, _response| action_handler.report_progress "waited #{(attempts - 1) * 5}/#{60 * 5}s for #{instance.id} status to terminate..." end end end end end end |