lib/cloudster/ec2.rb in cloudster-2.7.0 vs lib/cloudster/ec2.rb in cloudster-2.8.0
- old
+ new
@@ -11,42 +11,46 @@
# ==== Examples
# ec2 = Cloudster::Ec2.new(
# :name => 'AppServer',
# :key_name => 'mykey',
# :image_id => 'ami_image_id',
- # :instance_type => 't1.micro'
+ # :instance_type => 't1.micro',
+ # :security_groups => ["TopSecurityGroup"]
# )
#
# ==== Parameters
# * options<~Hash> -
# * :name: String containing the name for the Ec2 resource
# * :key_name: String containing the name of the keypair to be used for SSH
# * :image_id: String containing the AMI image id to be used while creating the Ec2 resource
# * :instance_type: String containing instance type ( Example : t1.micro )
+ # * :security_groups: Array containing names of existing SecurityGroups already defined using AWS console
def initialize(options = {})
require_options(options, [:name, :key_name, :image_id])
@name = options[:name]
@key_name = options[:key_name]
@image_id = options[:image_id]
@instance_type = options[:instance_type]
+ @security_groups = options[:security_groups]
end
# Returns a Ruby hash version of the Cloud Formation template for the resource instance
#
# ==== Examples
# ec2 = Cloudster::Ec2.new(
# :name => 'AppServer',
# :key_name => 'mykey',
# :image_id => 'ami_image_id',
- # :instance_type => 't1.micro'
+ # :instance_type => 't1.micro',
+ # :security_groups => ["SecurityGroup"]
# )
# ec2.template
#
# ==== Returns
# * Ruby hash version of the Cloud Formation template for the resource instance
def template
- @template ||= Ec2.template({:name =>@name, :key_name => @key_name, :image_id => @image_id, :instance_type => @instance_type})
+ @template ||= Ec2.template({:name =>@name, :key_name => @key_name, :image_id => @image_id, :instance_type => @instance_type, :security_groups => @security_groups})
end
# Class method that returns a Ruby hash version of the Cloud Formation template
#
# ==== Examples
@@ -62,17 +66,22 @@
# *Keys:
# * :name: String containing the name for the Ec2 resource
# * :key_name: String containing the name of the keypair to be used for SSH
# * :image_id: String containing the AMI image id to be used while creating the Ec2 resource
# * :instance_type: String containing instance type ( Example : t1.micro )
+ # * :security_groups: Array containing names of existing SecurityGroups already defined using AWS console
#
# ==== Returns
# * Ruby hash version of the Cloud Formation template
def self.template(options = {})
require_options(options, [:name, :key_name, :image_id])
properties = {}
properties.merge!({"KeyName" => options[:key_name], "ImageId" => options[:image_id]})
properties.merge!({"InstanceType" => options[:instance_type]}) unless options[:instance_type].nil?
+ unless options[:security_groups].nil?
+ security_groups = options[:security_groups].to_a
+ properties.merge!({"SecurityGroups" => security_groups})
+ end
template = {'Resources' => {
options[:name] => {
'Type' => 'AWS::EC2::Instance',
'Properties' => properties
}