k1LoW / awspec

RSpec tests for your AWS resources.
MIT License
1.17k stars 193 forks source link

EC2 resource type only appears to take an instance ID #166

Open ajlanghorn opened 8 years ago

ajlanghorn commented 8 years ago

Is it possible to give the EC2 resource type something other than an instance ID to allow it to match? As an example:

describe ec2(i-a1b2c3d4) do
   ...
end

works fine, but:

describe ec2(foo) do
   ...
end

doesn't.

Given that instances often don't stay around for very long, and even if they do, the instance IDs aren't how (I figure) many people refer to instances (most people I know refer using tags), is it possible to use the Name tag value in place of the instance ID to get a match on the specific resource?

k1LoW commented 8 years ago

Hi @ajlanghorn !

If the Name tag value is unique in instances, ec2 resource can detect instance by the Name tag value. ( see https://github.com/k1LoW/awspec/blob/master/spec/type/ec2_spec.rb#L34 )

If there are instances with same name tag,

throw Awspec::DuplicatedResourceTypeError

(And see https://github.com/k1LoW/awspec/issues/155#issuecomment-229229696)

ajlanghorn commented 8 years ago

Hi @k1LoW! Thanks; I've got a few instances with the same value for the Name tag, but a different value for a separate tag. I'd love it if I can get something like:

describe ec2('name') do
    it { should have_tag('env').value('production') }
end

to work, because then I can differentiate based on the env tag's value, without changing the rest of my test.

k1LoW commented 8 years ago

Hi!

I think " *spec (like awspec / RSpec / Serverspec) should detect resource uniquely "

For example

  1. Running instance => Instance ID: i-abcdefg / tag name 'name' / tag env 'production'
  2. Running instance => Instance ID: i-123456 / tag name 'name' / tag env 'development'

Your spec can not report true or false.

So awspec throw Awspec::DuplicatedResourceTypeError.

Best Regards.