{"action":"created","issue":{"url":"https://api.github.com/repos/k1LoW/awspec/issues/155","repository_url":"https://api.github.com/repos/k1LoW/awspec","labels_url":"https://api.github.com/repos/k1LoW/awspec/issues/155/labels{/name}","comments_url":"https://api.github.com/repos/k1LoW/awspec/issues/155/comments","events_url":"https://api.github.com/repos/k1LoW/awspec/issues/155/events","html_url":"https://github.com/k1LoW/awspec/issues/155","id":162819644,"number":155,"title":"Terminated and running instances having the same name will cause tests to fail","user":{"login":"gwiddel","id":3018104,"avatar_url":"https://avatars.githubusercontent.com/u/3018104?v=3","gravatar_id":"","url":"https://api.github.com/users/gwiddel","html_url":"https://github.com/gwiddel","followers_url":"https://api.github.com/users/gwiddel/followers","following_url":"https://api.github.com/users/gwiddel/following{/other_user}","gists_url":"https://api.github.com/users/gwiddel/gists{/gist_id}","starred_url":"https://api.github.com/users/gwiddel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gwiddel/subscriptions","organizations_url":"https://api.github.com/users/gwiddel/orgs","repos_url":"https://api.github.com/users/gwiddel/repos","events_url":"https://api.github.com/users/gwiddel/events{/privacy}","received_events_url":"https://api.github.com/users/gwiddel/received_events","type":"User","site_admin":false},"labels":[{"id":241093116,"url":"https://api.github.com/repos/k1LoW/awspec/labels/wontfix","name":"wontfix","color":"ffffff","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-06-29T00:59:20Z","updated_at":"2016-12-19T11:04:54Z","closed_at":null,"body":"I ran into this issue while building out stacks with terraform, where I'm frequently destroying/recreating entire ec2 clusters. If you terminate an instance, then create a new identical instance (same name), awspec seems to test against the terminated instance rather than the running one. IMO if two instances exist with the same name tag, one running and one terminated, it should assume the running one.\n"},"comment":{"url":"https://api.github.com/repos/k1LoW/awspec/issues/comments/267938420","html_url":"https://github.com/k1LoW/awspec/issues/155#issuecomment-267938420","issue_url":"https://api.github.com/repos/k1LoW/awspec/issues/155","id":267938420,"user":{"login":"kief","id":453192,"avatar_url":"https://avatars.githubusercontent.com/u/453192?v=3","gravatar_id":"","url":"https://api.github.com/users/kief","html_url":"https://github.com/kief","followers_url":"https://api.github.com/users/kief/followers","following_url":"https://api.github.com/users/kief/following{/other_user}","gists_url":"https://api.github.com/users/kief/gists{/gist_id}","starred_url":"https://api.github.com/users/kief/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kief/subscriptions","organizations_url":"https://api.github.com/users/kief/orgs","repos_url":"https://api.github.com/users/kief/repos","events_url":"https://api.github.com/users/kief/events{/privacy}","received_events_url":"https://api.github.com/users/kief/received_events","type":"User","site_admin":false},"created_at":"2016-12-19T11:04:54Z","updated_at":"2016-12-19T11:04:54Z","body":"I'm having a similar issue. The solution of testing for ``should be_terminated`` doesn't help, because I'm not trying to test whether it's terminated.\r\n\r\nFor example, I have a spec like this:\r\n\r\n  describe ec2('My Server') do\r\n    it { should be_running }\r\n  end\r\n\r\nMy workflow is like this:\r\n\r\n1. Edit and apply terraform template\r\n2. Run tests\r\n3. Make a change to terraform that causes the server to be destroyed and a new instance to be created\r\n4. Run tests\r\n\r\nAssuming my server was successfully recreated, I expect my tests to pass. Instead, I get:\r\n\r\n  1) private_instance ec2 'My Server' should be running\r\n     On host `10.0.2.225'\r\n     Failure/Error: it { should be_running }\r\n     NoMethodError:\r\n       undefined method `state' for nil:NilClass\r\n\r\n     # /var/lib/gems/2.3.0/gems/awspec-0.61.0/lib/awspec/type/ec2.rb:29:in `block (2 levels) in <class:Ec2>'\r\n     # /var/lib/gems/2.3.0/gems/serverspec-2.37.2/lib/serverspec/matcher/be_running.rb:7:in `block (2 levels) in <top (required)>'\r\n     # ./spec/gocd_server/private_instance_spec.rb:9:in `block (3 levels) in <top (required)>'\r\n\r\nThis is because the terminated instance with the same name still exists for a little while.\r\n\r\nThe issue seems to be in helper/finder/ec2.rb:31:\r\n\r\n      def find_ec2_status(id)\r\n        res = ec2_client.describe_instance_status({\r\n                                                    instance_ids: [id]\r\n                                                  })\r\n        res.instance_statuses.first if res.instance_statuses.count == 1\r\n      end\r\n\r\nIf res.instance_status.count is not 1 (as it will be when you rebuild a server with a given Name), then this returns nil.\r\n\r\nAt the very least, it should throw ``Awspec::DuplicatedResourceTypeError``. Better yet would be to return the running instance. But I can see this complicates things, as find_ec2 may be called in other situations where this behaviour isn't expected.\r\n\r\nI'm happy to make a change and submit a pull request. But I'm not sure what the best solution is for the overall library.\r\n\r\n"}}
{"actor":{"display_login":"kief"}}