{"action":"created","comment":{"url":"https://api.github.com/repos/puppetlabs/puppetlabs-aws/pulls/comments/24278489","id":24278489,"diff_hunk":"@@ -105,13 +130,57 @@ def create\n       key = resource[:key_name] ? resource[:key_name] : false\n       config['key_name'] = key if key\n \n-      response = ec2_client(resource[:region]).run_instances(config)\n+      # must specify a subnet to launch inside a VPC\n+      if ! resource[:subnet]\n+        matching_groups = classic_groups\n+      else\n+        # filter by VPC, since describe_subnets doesn't work on empty tag:Name\n+        subnet_response = ec2.describe_subnets(filters: [\n+          {name: \"vpc-id\", values: vpc_groups.keys}])\n+\n+        # then find the name in the VPC subnets that we have\n+        subnets = subnet_response.data.subnets.select do |s|\n+          if resource[:subnet].empty?\n+            ! s.tags.any? { |t| t.key == 'Name' }\n+          else\n+            s.tags.any? { |t| t.key == 'Name' && t.value == resource[:subnet] }\n+          end\n+        end\n+\n+        # handle ambiguous name collisions by selecting first matching subnet / vpc\n+        subnet = subnets.first\n+        if subnets.length > 1\n+          subnet_map = subnets.map { |s| \"#{s.subnet_id} (vpc: #{s.vpc_id})\" }.join(', ')\n+          Puppet.warning \"Ambiguous subnet name '#{resource[:subnet]}' resolves to subnets #{subnet_map} - using #{subnet.subnet_id}\"\n+        end\n+\n+        if subnet.nil?\n+          raise Puppet::Error,\n+            \"Invalid security groups '#{groups.join(', ')}' not found in VPCs '#{vpc_groups.keys.join(', ')}'\"","path":"lib/puppet/provider/ec2_instance/v2.rb","position":97,"original_position":97,"commit_id":"0f5cab84c3a85d133ff55ab967c37bf29f12633a","original_commit_id":"0f5cab84c3a85d133ff55ab967c37bf29f12633a","user":{"login":"cmurphy","id":1220710,"avatar_url":"https://avatars.githubusercontent.com/u/1220710?v=3","gravatar_id":"","url":"https://api.github.com/users/cmurphy","html_url":"https://github.com/cmurphy","followers_url":"https://api.github.com/users/cmurphy/followers","following_url":"https://api.github.com/users/cmurphy/following{/other_user}","gists_url":"https://api.github.com/users/cmurphy/gists{/gist_id}","starred_url":"https://api.github.com/users/cmurphy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cmurphy/subscriptions","organizations_url":"https://api.github.com/users/cmurphy/orgs","repos_url":"https://api.github.com/users/cmurphy/repos","events_url":"https://api.github.com/users/cmurphy/events{/privacy}","received_events_url":"https://api.github.com/users/cmurphy/received_events","type":"User","site_admin":false},"body":"This would be more friendly if it raised an error earlier than this if vpc_groups is empty. Currently, it claims the group was \"`not found in VPCs ''`\" which is hard to read.","created_at":"2015-02-06T22:47:54Z","updated_at":"2015-02-06T22:47:54Z","html_url":"https://github.com/puppetlabs/puppetlabs-aws/pull/61#discussion_r24278489","pull_request_url":"https://api.github.com/repos/puppetlabs/puppetlabs-aws/pulls/61","_links":{"self":{"href":"https://api.github.com/repos/puppetlabs/puppetlabs-aws/pulls/comments/24278489"},"html":{"href":"https://github.com/puppetlabs/puppetlabs-aws/pull/61#discussion_r24278489"},"pull_request":{"href":"https://api.github.com/repos/puppetlabs/puppetlabs-aws/pulls/61"}}},"pull_request":{"url":"https://api.github.com/repos/puppetlabs/puppetlabs-aws/pulls/61","id":27834689,"html_url":"https://github.com/puppetlabs/puppetlabs-aws/pull/61","diff_url":"https://github.com/puppetlabs/puppetlabs-aws/pull/61.diff","patch_url":"https://github.com/puppetlabs/puppetlabs-aws/pull/61.patch","issue_url":"https://api.github.com/repos/puppetlabs/puppetlabs-aws/issues/61","number":61,"state":"open","locked":false,"title":"(CLOUD-160) Add subnet support to instance","user":{"login":"garethr","id":2029,"avatar_url":"https://avatars.githubusercontent.com/u/2029?v=3","gravatar_id":"","url":"https://api.github.com/users/garethr","html_url":"https://github.com/garethr","followers_url":"https://api.github.com/users/garethr/followers","following_url":"https://api.github.com/users/garethr/following{/other_user}","gists_url":"https://api.github.com/users/garethr/gists{/gist_id}","starred_url":"https://api.github.com/users/garethr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/garethr/subscriptions","organizations_url":"https://api.github.com/users/garethr/orgs","repos_url":"https://api.github.com/users/garethr/repos","events_url":"https://api.github.com/users/garethr/events{/privacy}","received_events_url":"https://api.github.com/users/garethr/received_events","type":"User","site_admin":false},"body":"Cleaned up commits in https://github.com/puppetlabs/puppetlabs-aws/pull/48 and opened this as an alternative.","created_at":"2015-01-22T11:15:51Z","updated_at":"2015-02-06T22:47:54Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c6f66d1affa14d20f5075e897db2fac3b2aeda7b","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/puppetlabs/puppetlabs-aws/pulls/61/commits","review_comments_url":"https://api.github.com/repos/puppetlabs/puppetlabs-aws/pulls/61/comments","review_comment_url":"https://api.github.com/repos/puppetlabs/puppetlabs-aws/pulls/comments/{number}","comments_url":"https://api.github.com/repos/puppetlabs/puppetlabs-aws/issues/61/comments","statuses_url":"https://api.github.com/repos/puppetlabs/puppetlabs-aws/statuses/0f5cab84c3a85d133ff55ab967c37bf29f12633a","head":{"label":"garethr:add-subnet-support-to-instance","ref":"add-subnet-support-to-instance","sha":"0f5cab84c3a85d133ff55ab967c37bf29f12633a","user":{"login":"garethr","id":2029,"avatar_url":"https://avatars.githubusercontent.com/u/2029?v=3","gravatar_id":"","url":"https://api.github.com/users/garethr","html_url":"https://github.com/garethr","followers_url":"https://api.github.com/users/garethr/followers","following_url":"https://api.github.com/users/garethr/following{/other_user}","gists_url":"https://api.github.com/users/garethr/gists{/gist_id}","starred_url":"https://api.github.com/users/garethr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/garethr/subscriptions","organizations_url":"https://api.github.com/users/garethr/orgs","repos_url":"https://api.github.com/users/garethr/repos","events_url":"https://api.github.com/users/garethr/events{/privacy}","received_events_url":"https://api.github.com/users/garethr/received_events","type":"User","site_admin":false},"repo":{"id":24759357,"name":"puppetlabs-aws","full_name":"garethr/puppetlabs-aws","owner":{"login":"garethr","id":2029,"avatar_url":"https://avatars.githubusercontent.com/u/2029?v=3","gravatar_id":"","url":"https://api.github.com/users/garethr","html_url":"https://github.com/garethr","followers_url":"https://api.github.com/users/garethr/followers","following_url":"https://api.github.com/users/garethr/following{/other_user}","gists_url":"https://api.github.com/users/garethr/gists{/gist_id}","starred_url":"https://api.github.com/users/garethr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/garethr/subscriptions","organizations_url":"https://api.github.com/users/garethr/orgs","repos_url":"https://api.github.com/users/garethr/repos","events_url":"https://api.github.com/users/garethr/events{/privacy}","received_events_url":"https://api.github.com/users/garethr/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/garethr/puppetlabs-aws","description":"Puppet module for managing AWS resources to build out infrastructure","fork":true,"url":"https://api.github.com/repos/garethr/puppetlabs-aws","forks_url":"https://api.github.com/repos/garethr/puppetlabs-aws/forks","keys_url":"https://api.github.com/repos/garethr/puppetlabs-aws/keys{/key_id}","collaborators_url":"https://api.github.com/repos/garethr/puppetlabs-aws/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/garethr/puppetlabs-aws/teams","hooks_url":"https://api.github.com/repos/garethr/puppetlabs-aws/hooks","issue_events_url":"https://api.github.com/repos/garethr/puppetlabs-aws/issues/events{/number}","events_url":"https://api.github.com/repos/garethr/puppetlabs-aws/events","assignees_url":"https://api.github.com/repos/garethr/puppetlabs-aws/assignees{/user}","branches_url":"https://api.github.com/repos/garethr/puppetlabs-aws/branches{/branch}","tags_url":"https://api.github.com/repos/garethr/puppetlabs-aws/tags","blobs_url":"https://api.github.com/repos/garethr/puppetlabs-aws/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/garethr/puppetlabs-aws/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/garethr/puppetlabs-aws/git/refs{/sha}","trees_url":"https://api.github.com/repos/garethr/puppetlabs-aws/git/trees{/sha}","statuses_url":"https://api.github.com/repos/garethr/puppetlabs-aws/statuses/{sha}","languages_url":"https://api.github.com/repos/garethr/puppetlabs-aws/languages","stargazers_url":"https://api.github.com/repos/garethr/puppetlabs-aws/stargazers","contributors_url":"https://api.github.com/repos/garethr/puppetlabs-aws/contributors","subscribers_url":"https://api.github.com/repos/garethr/puppetlabs-aws/subscribers","subscription_url":"https://api.github.com/repos/garethr/puppetlabs-aws/subscription","commits_url":"https://api.github.com/repos/garethr/puppetlabs-aws/commits{/sha}","git_commits_url":"https://api.github.com/repos/garethr/puppetlabs-aws/git/commits{/sha}","comments_url":"https://api.github.com/repos/garethr/puppetlabs-aws/comments{/number}","issue_comment_url":"https://api.github.com/repos/garethr/puppetlabs-aws/issues/comments/{number}","contents_url":"https://api.github.com/repos/garethr/puppetlabs-aws/contents/{+path}","compare_url":"https://api.github.com/repos/garethr/puppetlabs-aws/compare/{base}...{head}","merges_url":"https://api.github.com/repos/garethr/puppetlabs-aws/merges","archive_url":"https://api.github.com/repos/garethr/puppetlabs-aws/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/garethr/puppetlabs-aws/downloads","issues_url":"https://api.github.com/repos/garethr/puppetlabs-aws/issues{/number}","pulls_url":"https://api.github.com/repos/garethr/puppetlabs-aws/pulls{/number}","milestones_url":"https://api.github.com/repos/garethr/puppetlabs-aws/milestones{/number}","notifications_url":"https://api.github.com/repos/garethr/puppetlabs-aws/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/garethr/puppetlabs-aws/labels{/name}","releases_url":"https://api.github.com/repos/garethr/puppetlabs-aws/releases{/id}","created_at":"2014-10-03T13:27:41Z","updated_at":"2015-02-01T15:45:20Z","pushed_at":"2015-02-01T15:45:20Z","git_url":"git://github.com/garethr/puppetlabs-aws.git","ssh_url":"git@github.com:garethr/puppetlabs-aws.git","clone_url":"https://github.com/garethr/puppetlabs-aws.git","svn_url":"https://github.com/garethr/puppetlabs-aws","homepage":"","size":1213,"stargazers_count":1,"watchers_count":1,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":1,"default_branch":"master"}},"base":{"label":"puppetlabs:master","ref":"master","sha":"a0154952ae5f0aee30634171f6dd583c6342bbf8","user":{"login":"puppetlabs","id":234268,"avatar_url":"https://avatars.githubusercontent.com/u/234268?v=3","gravatar_id":"","url":"https://api.github.com/users/puppetlabs","html_url":"https://github.com/puppetlabs","followers_url":"https://api.github.com/users/puppetlabs/followers","following_url":"https://api.github.com/users/puppetlabs/following{/other_user}","gists_url":"https://api.github.com/users/puppetlabs/gists{/gist_id}","starred_url":"https://api.github.com/users/puppetlabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/puppetlabs/subscriptions","organizations_url":"https://api.github.com/users/puppetlabs/orgs","repos_url":"https://api.github.com/users/puppetlabs/repos","events_url":"https://api.github.com/users/puppetlabs/events{/privacy}","received_events_url":"https://api.github.com/users/puppetlabs/received_events","type":"Organization","site_admin":false},"repo":{"id":23803367,"name":"puppetlabs-aws","full_name":"puppetlabs/puppetlabs-aws","owner":{"login":"puppetlabs","id":234268,"avatar_url":"https://avatars.githubusercontent.com/u/234268?v=3","gravatar_id":"","url":"https://api.github.com/users/puppetlabs","html_url":"https://github.com/puppetlabs","followers_url":"https://api.github.com/users/puppetlabs/followers","following_url":"https://api.github.com/users/puppetlabs/following{/other_user}","gists_url":"https://api.github.com/users/puppetlabs/gists{/gist_id}","starred_url":"https://api.github.com/users/puppetlabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/puppetlabs/subscriptions","organizations_url":"https://api.github.com/users/puppetlabs/orgs","repos_url":"https://api.github.com/users/puppetlabs/repos","events_url":"https://api.github.com/users/puppetlabs/events{/privacy}","received_events_url":"https://api.github.com/users/puppetlabs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/puppetlabs/puppetlabs-aws","description":"Puppet module for managing AWS resources to build out infrastructure","fork":false,"url":"https://api.github.com/repos/puppetlabs/puppetlabs-aws","forks_url":"https://api.github.com/repos/puppetlabs/puppetlabs-aws/forks","keys_url":"https://api.github.com/repos/puppetlabs/puppetlabs-aws/keys{/key_id}","collaborators_url":"https://api.github.com/repos/puppetlabs/puppetlabs-aws/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/puppetlabs/puppetlabs-aws/teams","hooks_url":"https://api.github.com/repos/puppetlabs/puppetlabs-aws/hooks","issue_events_url":"https://api.github.com/repos/puppetlabs/puppetlabs-aws/issues/events{/number}","events_url":"https://api.github.com/repos/puppetlabs/puppetlabs-aws/events","assignees_url":"https://api.github.com/repos/puppetlabs/puppetlabs-aws/assignees{/user}","branches_url":"https://api.github.com/repos/puppetlabs/puppetlabs-aws/branches{/branch}","tags_url":"https://api.github.com/repos/puppetlabs/puppetlabs-aws/tags","blobs_url":"https://api.github.com/repos/puppetlabs/puppetlabs-aws/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/puppetlabs/puppetlabs-aws/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/puppetlabs/puppetlabs-aws/git/refs{/sha}","trees_url":"https://api.github.com/repos/puppetlabs/puppetlabs-aws/git/trees{/sha}","statuses_url":"https://api.github.com/repos/puppetlabs/puppetlabs-aws/statuses/{sha}","languages_url":"https://api.github.com/repos/puppetlabs/puppetlabs-aws/languages","stargazers_url":"https://api.github.com/repos/puppetlabs/puppetlabs-aws/stargazers","contributors_url":"https://api.github.com/repos/puppetlabs/puppetlabs-aws/contributors","subscribers_url":"https://api.github.com/repos/puppetlabs/puppetlabs-aws/subscribers","subscription_url":"https://api.github.com/repos/puppetlabs/puppetlabs-aws/subscription","commits_url":"https://api.github.com/repos/puppetlabs/puppetlabs-aws/commits{/sha}","git_commits_url":"https://api.github.com/repos/puppetlabs/puppetlabs-aws/git/commits{/sha}","comments_url":"https://api.github.com/repos/puppetlabs/puppetlabs-aws/comments{/number}","issue_comment_url":"https://api.github.com/repos/puppetlabs/puppetlabs-aws/issues/comments/{number}","contents_url":"https://api.github.com/repos/puppetlabs/puppetlabs-aws/contents/{+path}","compare_url":"https://api.github.com/repos/puppetlabs/puppetlabs-aws/compare/{base}...{head}","merges_url":"https://api.github.com/repos/puppetlabs/puppetlabs-aws/merges","archive_url":"https://api.github.com/repos/puppetlabs/puppetlabs-aws/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/puppetlabs/puppetlabs-aws/downloads","issues_url":"https://api.github.com/repos/puppetlabs/puppetlabs-aws/issues{/number}","pulls_url":"https://api.github.com/repos/puppetlabs/puppetlabs-aws/pulls{/number}","milestones_url":"https://api.github.com/repos/puppetlabs/puppetlabs-aws/milestones{/number}","notifications_url":"https://api.github.com/repos/puppetlabs/puppetlabs-aws/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/puppetlabs/puppetlabs-aws/labels{/name}","releases_url":"https://api.github.com/repos/puppetlabs/puppetlabs-aws/releases{/id}","created_at":"2014-09-08T18:42:08Z","updated_at":"2015-02-06T03:39:37Z","pushed_at":"2015-02-04T15:12:58Z","git_url":"git://github.com/puppetlabs/puppetlabs-aws.git","ssh_url":"git@github.com:puppetlabs/puppetlabs-aws.git","clone_url":"https://github.com/puppetlabs/puppetlabs-aws.git","svn_url":"https://github.com/puppetlabs/puppetlabs-aws","homepage":"","size":1895,"stargazers_count":41,"watchers_count":41,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":16,"mirror_url":null,"open_issues_count":20,"forks":16,"open_issues":20,"watchers":41,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/puppetlabs/puppetlabs-aws/pulls/61"},"html":{"href":"https://github.com/puppetlabs/puppetlabs-aws/pull/61"},"issue":{"href":"https://api.github.com/repos/puppetlabs/puppetlabs-aws/issues/61"},"comments":{"href":"https://api.github.com/repos/puppetlabs/puppetlabs-aws/issues/61/comments"},"review_comments":{"href":"https://api.github.com/repos/puppetlabs/puppetlabs-aws/pulls/61/comments"},"review_comment":{"href":"https://api.github.com/repos/puppetlabs/puppetlabs-aws/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/puppetlabs/puppetlabs-aws/pulls/61/commits"},"statuses":{"href":"https://api.github.com/repos/puppetlabs/puppetlabs-aws/statuses/0f5cab84c3a85d133ff55ab967c37bf29f12633a"}}}}