Sha256: b2ac08dae8fd2378917e84f840bb5bbd0cbe2fad78f15887548235b27d98fe85

Contents?: true

Size: 1.05 KB

Versions: 39

Compression:

Stored size: 1.05 KB

Contents

RSpec::Matchers.define :belong_to_subnet do |subnet_id|
  match do |resource|
    # EC2
    if resource.instance_of?(Awspec::Type::Ec2)
      return true if resource.subnet_id == subnet_id
      subnet = resource.find_subnet(subnet_id)
      return false unless subnet
      return subnet[:subnet_id] == resource.subnet_id
    end

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

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

      res = resource.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] == resource.availability_zone if ret
    end
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
awspec-0.25.3 lib/awspec/matcher/belong_to_subnet.rb
awspec-0.25.2 lib/awspec/matcher/belong_to_subnet.rb
awspec-0.25.1 lib/awspec/matcher/belong_to_subnet.rb
awspec-0.25.0 lib/awspec/matcher/belong_to_subnet.rb
awspec-0.24.2 lib/awspec/matcher/belong_to_subnet.rb
awspec-0.24.1 lib/awspec/matcher/belong_to_subnet.rb
awspec-0.24.0 lib/awspec/matcher/belong_to_subnet.rb
awspec-0.23.0 lib/awspec/matcher/belong_to_subnet.rb
awspec-0.22.1 lib/awspec/matcher/belong_to_subnet.rb
awspec-0.22.0 lib/awspec/matcher/belong_to_subnet.rb
awspec-0.21.6 lib/awspec/matcher/belong_to_subnet.rb
awspec-0.21.5 lib/awspec/matcher/belong_to_subnet.rb
awspec-0.21.4 lib/awspec/matcher/belong_to_subnet.rb
awspec-0.21.3 lib/awspec/matcher/belong_to_subnet.rb
awspec-0.21.2 lib/awspec/matcher/belong_to_subnet.rb
awspec-0.21.1 lib/awspec/matcher/belong_to_subnet.rb
awspec-0.21.0 lib/awspec/matcher/belong_to_subnet.rb
awspec-0.20.2 lib/awspec/matcher/belong_to_subnet.rb
awspec-0.20.1 lib/awspec/matcher/belong_to_subnet.rb
awspec-0.20.0 lib/awspec/matcher/belong_to_subnet.rb