Sha256: ea3589956d99f9bfdb25a31f8b205490efd593db50a01e3b56a7d13a0903fda5

Contents?: true

Size: 1.68 KB

Versions: 2

Compression:

Stored size: 1.68 KB

Contents

module Cloudster
  #==ElasticIp resource
  #Output values : public_ip
  class ElasticIp
    include Cloudster::Output

    # Initialize an ElasticIp
    #
    # ==== Notes
    # options parameter must include values for :name
    #
    # ==== Examples
    #   elastic_ip = Cloudster::ElasticIp.new(:name => 'ElasticIp')
    #
    # ==== Parameters
    # * options<~Hash> -
    #     * :name: String containing the name of ElastiCache resource
    def initialize(options = {})
      require_options(options, [:name])
      @name = options[:name]
    end

    # Merges the required CloudFormation template for adding an ElasticIp to an EC2 instance
    #
    #
    # ==== Examples
    #   elastic_ip = Cloudster::ElasticIp.new(:name => 'AppServerEIp')
    #   ec2 = Cloudster::Ec2.new(
    #    :name => 'AppServer',
    #    :key_name => 'mykey',
    #    :image_id => 'ami_image_id',
    #    :instance_type => 't1.micro'
    #   )
    #
    #   elastic_ip.add_to ec2
    #
    # ==== Parameters
    # * instance of EC2
    def add_to(ec2)
      ec2_template = ec2.template
      @instance_name = ec2.name
      elastic_ip_template = template
      ec2.template.inner_merge(elastic_ip_template)
    end

    private
      def template
        template = { "Resources" => {
          @name => {
            "Type" => "AWS::EC2::EIP",
              "Properties" => {
                "InstanceId" => {
                  "Ref" => @instance_name
                }
              }
            }
          }
        }
        outputs = {
          @name => {
            'public_ip' => {'Ref' => @name}
          }
        }
        template['Outputs'] = output_template(outputs)
        return template
      end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cloudster-2.20.0 lib/cloudster/elastic_ip.rb
cloudster-2.19.7 lib/cloudster/elastic_ip.rb