Sha256: e1ac922436e1695f6ec9b6bbfff44fff53a4575c8f3ed30cfca94f2ba653c4a5

Contents?: true

Size: 1.73 KB

Versions: 25

Compression:

Stored size: 1.73 KB

Contents

module Awspec::Type
  class Vpc < ResourceBase
    aws_resource Aws::EC2::Vpc
    tags_allowed

    def resource_via_client
      @resource_via_client ||= find_vpc(@display_name)
    end

    def id
      @id ||= resource_via_client.vpc_id if resource_via_client
    end

    STATES = %w(
      available pending
    )

    STATES.each do |state|
      define_method state + '?' do
        resource_via_client.state == state
      end
    end

    def has_route_table?(table_id)
      route_table = find_route_table(table_id)
      return false unless route_table
      route_table.vpc_id == id
    end

    def has_network_acl?(table_id)
      n = find_network_acl(table_id)
      return false unless n
      n.vpc_id == id
    end

    def connected_to_vpc?(vpc_id, accepter_or_requester = nil)
      connections = select_vpc_peering_connection_by_vpc_id(vpc_id, 'active')
      return connections.single_resource(vpc_id) unless accepter_or_requester

      if accepter_or_requester == 'accepter'
        connections.select do |conn|
          conn.accepter_vpc_info.vpc_id == @id
        end.single_resource(vpc_id)
      elsif accepter_or_requester == 'requester'
        connections.select do |conn|
          conn.requester_vpc_info.vpc_id == @id
        end.single_resource(vpc_id)
      end
    end

    def has_vpc_peering_connection?(vpc_peering_connection_id, accepter_or_requester = nil)
      connection = find_vpc_peering_connection(vpc_peering_connection_id)
      res = if accepter_or_requester == 'accepter'
              connection.accepter_vpc_info.vpc_id == @id
            elsif accepter_or_requester == 'requester'
              connection.requester_vpc_info.vpc_id == @id
            else
              connection
            end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
awspec-1.4.1 lib/awspec/type/vpc.rb
awspec-1.4.0 lib/awspec/type/vpc.rb
awspec-1.3.1 lib/awspec/type/vpc.rb
awspec-1.3.0 lib/awspec/type/vpc.rb
awspec-1.2.0 lib/awspec/type/vpc.rb