k1LoW / awspec

RSpec tests for your AWS resources.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

route_table.has_route

darrylb-github opened this issue · comments

Hey,

I'm using this like so:

    describe route_table(myroutetable) do
      it { should exist }
      it { should have_route('0.0.0.0/0').target(nat: mynat) }
    end

This works on the first run, however if I run my tests again it fails because there are two matching NAT gateways - one deleted and one available. If I wait ~30mins until AWS purges the deleted NAT from the results, my tests pass again.

How can I work around this so that it only matches a NAT if it hasn't been deleted? I could lookup the nat ID and use it but I'd rather avoid that extra step if possible.

Thanks,
Darryl

I could lookup the nat ID and use it but I'd rather avoid that extra step if possible.

This isn't what you want to hear, so maybe someone else has more ideas, but that is exactly what I would do.

@darrylb-github,

You indeed should use the ID instead.

From lib/awspec/helper/finder/vpc.rb:

      def find_route_table(route_table_id)
        res = ec2_client.describe_route_tables({
                                                 filters: [{ name: 'route-table-id', values: [route_table_id] }]
                                               })
        resource = res.route_tables.single_resource(route_table_id)
        return resource if resource
        res = ec2_client.describe_route_tables({
                                                 filters: [{ name: 'tag:Name', values: [route_table_id] }]
                                               })
        res.route_tables.single_resource(route_table_id)
      end

It is already searching for ID or tag:Name, but by tag:Name I guess it should not work due the time is required for the purging to occur.

What could happen from inside awspec is to raise an exception when searching by tag:Name returns more than one result: you could capture that and do something else, like checking the status of the route.