Module: Enscalator::Plugins::AutoScale
- Defined in:
- lib/enscalator/plugins/auto_scale.rb
Overview
Auto scaling group plugin
Class Method Summary collapse
-
.included(klass) ⇒ Object
Callback to get name of the class which included this module.
Instance Method Summary collapse
-
#auto_scale_init(image_id, auto_scale_name: nil, launch_config_props: {}, auto_scale_props: {}, auto_scale_tags: []) ⇒ String
Create new auto scaling group.
Class Method Details
.included(klass) ⇒ Object
Callback to get name of the class which included this module
75 76 77 |
# File 'lib/enscalator/plugins/auto_scale.rb', line 75 def self.included(klass) send(:define_method, :app_template_name) { "#{klass.name.demodulize}" } end |
Instance Method Details
#auto_scale_init(image_id, auto_scale_name: nil, launch_config_props: {}, auto_scale_props: {}, auto_scale_tags: []) ⇒ String
Create new auto scaling group
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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/enscalator/plugins/auto_scale.rb', line 15 def auto_scale_init(image_id, auto_scale_name: nil, launch_config_props: {}, auto_scale_props: {}, auto_scale_tags: []) name = auto_scale_name || app_template_name auto_scale_name = "#{name}AutoScale" launch_config_resource_name = "#{name}LaunchConfig" auto_scale_resource_name = auto_scale_name auto_scale_key_name = gen_ssh_key_name auto_scale_name.underscore, region, stack_name pre_run do create_ssh_key auto_scale_key_name, region, force_create: false end resource launch_config_resource_name, Type: 'AWS::AutoScaling::LaunchConfiguration', Properties: { ImageId: image_id, InstanceType: 'm3.medium', KeyName: auto_scale_key_name, AssociatePublicIpAddress: false, SecurityGroups: [ref_private_security_group, ref_application_security_group] }.merge(launch_config_props) if auto_scale_props.key?(:Tags) warn('Do not use auto_scale_props to set Tags, auto_scale_tags is available for that purpose') auto_scale_props.delete_if { |k, _| k == :Tags } end = [ { Key: 'Name', Value: auto_scale_name, PropagateAtLaunch: true } ].concat() auto_scale_current_properties = { AvailabilityZones: availability_zones.values, VPCZoneIdentifier: ref_application_subnets, LaunchConfigurationName: ref(launch_config_resource_name), MinSize: 0, MaxSize: 1, DesiredCapacity: 1, Tags: }.merge(auto_scale_props) resource auto_scale_resource_name, Type: 'AWS::AutoScaling::AutoScalingGroup', Properties: auto_scale_current_properties # return resource name auto_scale_resource_name end |