Sha256: aff4df229ace59bcf08e5f6b92d0fb232c881bda322580f2cd9d44d8934612c1

Contents?: true

Size: 960 Bytes

Versions: 1

Compression:

Stored size: 960 Bytes

Contents

module Awspec::Helper
  module Finder
    module Subnet
      def filter_type_matcher(search_key)
        deafult = 'tag:Name'
        case search_key
        when /subnet-[a-zA-Z0-9]{8}/
          return 'subnet-id'
        when %r{[1-9][0-9]{1,2}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}//[0-9]{1,3}}
          return 'cidrBlock'
        else
          return deafult
        end
      end

      def find_subnet(search_key)
        res = ec2_client.describe_subnets({
                                            filters: [{ name: filter_type_matcher(search_key), values: [search_key] }]
                                          })
        res.subnets.single_resource(search_key)
      end

      def select_subnet_by_vpc_id(vpc_id)
        res = ec2_client.describe_subnets({
                                            filters: [{ name: 'vpc-id', values: [vpc_id] }]
                                          })
        res.subnets
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
awspec-0.80.0 lib/awspec/helper/finder/subnet.rb