Sha256: 7ebec1dfa21666914c63ceb90d2d71756569fbffa8075ada4936d1323cee68ad

Contents?: true

Size: 1.12 KB

Versions: 2

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true

RSpec::Matchers.define :belong_to_subnet do |subnet_id|
  match do |type|
    # EC2, NetworkInterface
    if type.instance_of?(Awspec::Type::Ec2) || type.instance_of?(Awspec::Type::NetworkInterface)
      return true if type.subnet_id == subnet_id

      subnet = type.find_subnet(subnet_id)
      return false unless subnet

      return subnet[:subnet_id] == type.subnet_id
    end

    # RDS
    if type.instance_of?(Awspec::Type::Rds)
      subnets = type.resource_via_client[:db_subnet_group][:subnets]
      ret = subnets.find do |s|
        s[:subnet_identifier] == subnet_id
      end

      return ret[:subnet_availability_zone][:name] == type.availability_zone if ret

      res = type.ec2_client.describe_subnets({
                                               filters: [{ name: 'tag:Name', values: [subnet_id] }]
                                             })
      return false unless res

      ret = subnets.find do |s|
        s[:subnet_identifier] == res[:subnets][0][:subnet_id]
      end

      return ret[:subnet_availability_zone][:name] == type.availability_zone if ret
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
awspec-1.26.0 lib/awspec/matcher/belong_to_subnet.rb
awspec-1.25.2 lib/awspec/matcher/belong_to_subnet.rb