Sha256: 055b8a94f9494ae32f9680e25e55b560a5942a8a9a54a4bbcdbab1cbbf7f0cfd

Contents?: true

Size: 1.22 KB

Versions: 4

Compression:

Stored size: 1.22 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
      ret = resource.client.describe_subnets({
                                               filters: [{ name: 'tag:Name', values: [subnet_id] }]
                                             })
      return false unless ret
      return ret[:subnets][0][: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 |subnet|
        subnet[: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 |subnet|
        subnet[: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

4 entries across 4 versions & 1 rubygems

Version Path
awspec-0.1.1 lib/awspec/matcher/belong_to_subnet.rb
awspec-0.1.0 lib/awspec/matcher/belong_to_subnet.rb
awspec-0.0.2 lib/awspec/matcher/belong_to_subnet.rb
awspec-0.0.1 lib/awspec/matcher/belong_to_subnet.rb