Sha256: 1eb7e9100768e52a8a07e4acbaa4ece2952f4f5e153bc11eae27fc6a0c40f6be

Contents?: true

Size: 1.05 KB

Versions: 15

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.instance[: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

15 entries across 15 versions & 1 rubygems

Version Path
awspec-0.8.0 lib/awspec/matcher/belong_to_subnet.rb
awspec-0.7.0 lib/awspec/matcher/belong_to_subnet.rb
awspec-0.6.4 lib/awspec/matcher/belong_to_subnet.rb
awspec-0.6.3 lib/awspec/matcher/belong_to_subnet.rb
awspec-0.6.2 lib/awspec/matcher/belong_to_subnet.rb
awspec-0.6.1 lib/awspec/matcher/belong_to_subnet.rb
awspec-0.6.0 lib/awspec/matcher/belong_to_subnet.rb
awspec-0.5.0 lib/awspec/matcher/belong_to_subnet.rb
awspec-0.4.1 lib/awspec/matcher/belong_to_subnet.rb
awspec-0.4.0 lib/awspec/matcher/belong_to_subnet.rb
awspec-0.3.0 lib/awspec/matcher/belong_to_subnet.rb
awspec-0.2.3 lib/awspec/matcher/belong_to_subnet.rb
awspec-0.2.2 lib/awspec/matcher/belong_to_subnet.rb
awspec-0.2.1 lib/awspec/matcher/belong_to_subnet.rb
awspec-0.2.0 lib/awspec/matcher/belong_to_subnet.rb