Sha256: 5b500f4c0c35add9878ddf513d2e1efc7749da2ef4c7e894e8b6c458b11812a3

Contents?: true

Size: 936 Bytes

Versions: 7

Compression:

Stored size: 936 Bytes

Contents

module Hashicorptools
  module Ec2Utilities
    def current_ami(tag = tag_name)
      amis(tag).first
    end

    def amis(tag = tag_name)
      sort_by_created_at(  ec2.images.with_owner('self').with_tag('Name', tag).to_a )
    end

    def ec2
      return @_ec2 unless @_ec2.nil?

      reg = if self.methods.include?(:region)
              self.region
            else
              'us-east-1'
            end

      @_ec2 = AWS::EC2.new(region: reg)
    end

    def vpc_with_name(name)
      vpcs = ec2.client.describe_vpcs({filters: [{name: 'tag:Name', values: [name]}]}).vpc_set
      vpcs.first
    end

    def internet_gateway_for_vpc(vpc_id)
      igs = ec2.client.describe_internet_gateways({filters: [{name: 'attachment.vpc-id', values: [vpc_id]}]}).internet_gateway_set
      igs.first
    end

    def sort_by_created_at(collection)
      collection.sort{|a, b| b.creation_date <=> a.creation_date }
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
hashicorptools-0.5.1 lib/hashicorptools/ec2_utilities.rb
hashicorptools-0.5.0 lib/hashicorptools/ec2_utilities.rb
hashicorptools-0.4.0 lib/hashicorptools/ec2_utilities.rb
hashicorptools-0.3.0 lib/hashicorptools/ec2_utilities.rb
hashicorptools-0.2.3 lib/hashicorptools/ec2_utilities.rb
hashicorptools-0.2.2 lib/hashicorptools/ec2_utilities.rb
hashicorptools-0.1.2 lib/hashicorptools/ec2_utilities.rb