Sha256: e99881430996380a208fa18e5193243f53ed29eb6134bc3a271fccd58590b7d7

Contents?: true

Size: 1.85 KB

Versions: 48

Compression:

Stored size: 1.85 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

    def has_vpc_attribute?(vpc_attribute)
      find_vpc_attribute(resource_via_client.vpc_id, vpc_attribute)
    end
  end
end

Version data entries

48 entries across 48 versions & 3 rubygems

Version Path
awspec-1.25.1 lib/awspec/type/vpc.rb
awspec-1.25.0 lib/awspec/type/vpc.rb
awspec-1.24.4 lib/awspec/type/vpc.rb
awspec-1.24.3 lib/awspec/type/vpc.rb
awspec-1.24.2 lib/awspec/type/vpc.rb
awspec-1.24.1 lib/awspec/type/vpc.rb
awspec-1.24.0 lib/awspec/type/vpc.rb
awspec-1.23.0 lib/awspec/type/vpc.rb
awspec-1.22.1 lib/awspec/type/vpc.rb
awspec-1.22.0 lib/awspec/type/vpc.rb
awspec-1.21.1 lib/awspec/type/vpc.rb
awspec-1.21.0 lib/awspec/type/vpc.rb
awspec-1.20.0 lib/awspec/type/vpc.rb
awspec-1.19.2 lib/awspec/type/vpc.rb
awspec-1.19.1 lib/awspec/type/vpc.rb
awspec-1.19.0 lib/awspec/type/vpc.rb
cthiesfork-awspec-1.2.4 lib/awspec/type/vpc.rb
awspec-api_gateway_extended-1.2.4 lib/awspec/type/vpc.rb
awspec-api_gateway_extended-1.2.3 lib/awspec/type/vpc.rb
awspec-1.18.6 lib/awspec/type/vpc.rb