lib/capistrano/asg/rolling/instance.rb in capistrano-asg-rolling-0.1.0 vs lib/capistrano/asg/rolling/instance.rb in capistrano-asg-rolling-0.2.0
- old
+ new
@@ -44,13 +44,16 @@
options[:subnet_id] = autoscaling_group.subnet_ids.sample if launch_template.network_interfaces.empty?
# Optionally override settings in the Launch Template.
options.merge!(overrides) if overrides
+ resource_tags = [
+ { key: 'Name', value: autoscaling_group.name_tag }
+ ]
options[:tag_specifications] = [
- { resource_type: 'instance', tags: [{ key: 'Name', value: autoscaling_group.name_tag }] },
- { resource_type: 'volume', tags: [{ key: 'Name', value: autoscaling_group.name_tag }] }
+ { resource_type: 'instance', tags: resource_tags },
+ { resource_type: 'volume', tags: resource_tags }
]
response = aws_ec2_client.run_instances(options)
instance = response.instances.first
@@ -88,14 +91,23 @@
aws_ec2_client.wait_until(:instance_terminated, instance_ids: [id]) if wait
@terminated = true
end
- def create_ami(name: nil, description: nil)
- now = Time.now
- name ||= "#{autoscale_group.name_tag} on #{now.strftime('%Y-%m-%d')} at #{now.strftime('%H.%M.%S')}"
+ def create_ami(name: nil, description: nil, tags: nil)
+ ami_tags = {
+ 'Name' => autoscale_group.name_tag,
+ 'capistrano-asg-rolling:version' => Capistrano::ASG::Rolling::VERSION
+ }
+ ami_tags.merge!(tags) if tags
- AMI.create(instance: self, name: name, description: description, tags: { 'Name' => autoscale_group.name_tag })
+ AMI.create(instance: self, name: name || ami_name, description: description, tags: ami_tags)
+ end
+
+ private
+
+ def ami_name
+ "#{autoscale_group.name_tag} on #{Time.now.strftime('%Y-%m-%d at %H.%M.%S')}"
end
end
end
end
end