{"action":"created","issue":{"url":"https://api.github.com/repos/chef/chef/issues/4718","repository_url":"https://api.github.com/repos/chef/chef","labels_url":"https://api.github.com/repos/chef/chef/issues/4718/labels{/name}","comments_url":"https://api.github.com/repos/chef/chef/issues/4718/comments","events_url":"https://api.github.com/repos/chef/chef/issues/4718/events","html_url":"https://github.com/chef/chef/issues/4718","id":141348206,"number":4718,"title":"12.5-style custom resources - resources may be declared many times but only belong to a single scope","user":{"login":"Poohblah","id":3742215,"avatar_url":"https://avatars.githubusercontent.com/u/3742215?v=3","gravatar_id":"","url":"https://api.github.com/users/Poohblah","html_url":"https://github.com/Poohblah","followers_url":"https://api.github.com/users/Poohblah/followers","following_url":"https://api.github.com/users/Poohblah/following{/other_user}","gists_url":"https://api.github.com/users/Poohblah/gists{/gist_id}","starred_url":"https://api.github.com/users/Poohblah/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Poohblah/subscriptions","organizations_url":"https://api.github.com/users/Poohblah/orgs","repos_url":"https://api.github.com/users/Poohblah/repos","events_url":"https://api.github.com/users/Poohblah/events{/privacy}","received_events_url":"https://api.github.com/users/Poohblah/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":17,"created_at":"2016-03-16T17:39:42Z","updated_at":"2016-03-30T23:13:46Z","closed_at":null,"body":"## Description\r\n\r\n12.5-style fused resources fail when a service definition is defined multiple times in different scopes.\r\n\r\nLet's say that I need to write a recipe that creates a firewall rule on port 5678 and consumes a resource - call it 'foo' - which is defined in an upstream cookbook. I'm treating the resource as a black box. To create a firewall rule, I need to include the default firewall recipe and execute the `firewall_rule` resource.  However, unbeknownst to me, the foo resource *also* needs to create a firewall rule (this firewall rule happens to be on port 1234), so the foo resource *also* includes the default firewall recipe.  This is where the conflict occurs. The firewall recipe only gets included once; however, since my cookbook includes the recipe before the foo resource, then the service is defined in the `run_context` of my recipe and not the `run_context` of the foo resource.  This causes the foo resource to be unable to find the firewall service and converge to fail.\r\n\r\nI believe this may be related to https://github.com/chef/chef/issues/4669.\r\n\r\n## Chef Version\r\n\r\n12.8.1 via chef-dk 0.11.2\r\n\r\n## Platform Version\r\n\r\nOnly tested with Linux chef-dk using Linux guest vms run via testkitchen for convergence\r\n\r\n## Replication Case\r\n\r\n`cookbooks/test/resources/lwrp.rb`:\r\n\r\n```\r\naction :foo do\r\n  include_recipe 'firewall'\r\n\r\n  firewall_rule 'foo' do\r\n    port 1234\r\n  end\r\nend\r\n```\r\n\r\n`cookbooks/consumes_test/recipes/default.rb`:\r\n\r\n```\r\ninclude_recipe 'firewall'\r\n\r\nfirewall_rule 'bar' do\r\n  port 5678\r\nend\r\n\r\ntest_lwrp 'baz'\r\n```\r\n\r\n## Client Output\r\n\r\n```\r\n[birdsnest /tmp/consumes_test](master|…)[I]% kitchen converge       \r\n-----> Starting Kitchen (v1.5.0)\r\n-----> Converging <default-centos-71>...\r\n       Preparing files for transfer\r\n       Preparing dna.json\r\n       Resolving cookbook dependencies with Berkshelf 4.2.1...\r\n       Removing non-cookbook files before transfer\r\n       Preparing validation.pem\r\n       Preparing client.rb\r\n-----> Chef Omnibus installation detected (install only if missing)\r\n       Transferring files to <default-centos-71>\r\n       Starting Chef Client, version 12.8.1\r\n       resolving cookbooks for run list: [\"consumes_test::default\"]\r\n       Synchronizing Cookbooks:\r\n         - consumes_test (0.1.0)\r\n         - firewall (2.5.0)\r\n         - test (0.1.0)\r\n         - chef-sugar (3.3.0)\r\n       Installing Cookbook Gems:\r\n       Compiling Cookbooks...\r\n       Recipe: chef-sugar::default\r\n         * chef_gem[chef-sugar] action install (up to date)\r\n         Converging 9 resources\r\n         * chef_gem[chef-sugar] action install (up to date)\r\n       Recipe: firewall::default\r\n         * firewall[default] action install\r\n           - install firewalld, create template for /etc/sysconfig\r\n         * yum_package[firewalld] action install (up to date)\r\n         * service[firewalld] action enable (up to date)\r\n         * service[firewalld] action start\r\n           - start service service[firewalld]\r\n         * file[create empty /etc/sysconfig/firewalld-chef.rules] action create (skipped due to not_if)\r\n         * firewall_rule[allow world to ssh] action create\r\n         \r\n         * firewall_rule[allow world to winrm] action create (skipped due to only_if)\r\n         * firewall_rule[allow world to mosh] action create (skipped due to only_if)\r\n         * firewall_rule[established] action create\r\n         \r\n         * firewall_rule[ipv6_icmp] action create\r\n         \r\n       Recipe: consumes_test::default\r\n         * firewall_rule[bar] action create\r\n         \r\n         * test_lwrp[baz] action foo\r\n           * firewall_rule[foo] action create\r\n             \r\n             ================================================================================\r\n             Error executing action `create` on resource 'firewall_rule[foo]'\r\n             ================================================================================\r\n             \r\n             Chef::Exceptions::ResourceNotFound\r\n             ----------------------------------\r\n             Cannot find a resource matching firewall[default] (did you define it first?)\r\n             \r\n             Cookbook Trace:\r\n             ---------------\r\n             /tmp/kitchen/cache/cookbooks/firewall/libraries/provider_firewall_rule.rb:27:in `block in <class:FirewallRuleGeneric>'\r\n             \r\n             Resource Declaration:\r\n             ---------------------\r\n             # In /tmp/kitchen/cache/cookbooks/test/resources/lwrp.rb\r\n             \r\n        4:   firewall_rule 'foo' do\r\n        5:     port 1234\r\n        6:   end\r\n        7: end\r\n             \r\n             Compiled Resource:\r\n             ------------------\r\n             # Declared in /tmp/kitchen/cache/cookbooks/test/resources/lwrp.rb:4:in `block in class_from_file'\r\n             \r\n             firewall_rule(\"foo\") do\r\n        action [:create]\r\n        retries 0\r\n        retry_delay 2\r\n        default_guard_interpreter :default\r\n        declared_type :firewall_rule\r\n        cookbook_name \"consumes_test\"\r\n        port 1234\r\n        notify_firewall true\r\n        firewall_name \"default\"\r\n             end\r\n             \r\n           \r\n           ================================================================================\r\n           Error executing action `foo` on resource 'test_lwrp[baz]'\r\n           ================================================================================\r\n           \r\n           Chef::Exceptions::ResourceNotFound\r\n           ----------------------------------\r\n           firewall_rule[foo] (/tmp/kitchen/cache/cookbooks/test/resources/lwrp.rb line 4) had an error: Chef::Exceptions::ResourceNotFound: Cannot find a resource matching firewall[default] (did you define it first?)\r\n           \r\n           Cookbook Trace:\r\n           ---------------\r\n           /tmp/kitchen/cache/cookbooks/firewall/libraries/provider_firewall_rule.rb:27:in `block in <class:FirewallRuleGeneric>'\r\n           \r\n           Resource Declaration:\r\n           ---------------------\r\n           # In /tmp/kitchen/cache/cookbooks/consumes_test/recipes/default.rb\r\n           \r\n            13: test_lwrp 'baz'\r\n           \r\n           Compiled Resource:\r\n           ------------------\r\n           # Declared in /tmp/kitchen/cache/cookbooks/consumes_test/recipes/default.rb:13:in `from_file'\r\n           \r\n           test_lwrp(\"baz\") do\r\n             action [:foo]\r\n             retries 0\r\n             retry_delay 2\r\n             default_guard_interpreter :default\r\n             declared_type :test_lwrp\r\n             cookbook_name \"consumes_test\"\r\n             recipe_name \"default\"\r\n           end\r\n           \r\n       Recipe: firewall::default\r\n         * firewall[default] action restart\r\n            (skipped due to only_if)\r\n          (skipped due to only_if)\r\n       * file[/etc/sysconfig/firewalld-chef.rules] action create\r\n         - update content in file /etc/sysconfig/firewalld-chef.rules from 946196 to 1c2b57\r\n         --- /etc/sysconfig/firewalld-chef.rules\t2016-03-16 17:11:16.331129951 +0000\r\n         +++ /etc/sysconfig/.chef-firewalld-chef.rules20160316-14566-rw5ffp\t2016-03-16 17:13:16.657262951 +0000\r\n         @@ -1,4 +1,5 @@\r\n          # position 50\r\n         +firewall-cmd --direct --add-rule ipv4 filter INPUT 50 -p tcp -m tcp -m multiport --dports 22 -m comment --comment 'allow world to ssh' -j ACCEPT\r\n          firewall-cmd --direct --add-rule ipv4 filter INPUT 50 -m state --state RELATED,ESTABLISHED -m comment --comment 'established' -j ACCEPT\r\n          firewall-cmd --direct --add-rule ipv6 filter INPUT 50 -m state --state RELATED,ESTABLISHED -m comment --comment 'established' -j ACCEPT\r\n          firewall-cmd --direct --add-rule ipv6 filter INPUT 50 -p ipv6-icmp -m comment --comment 'ipv6_icmp' -j ACCEPT\r\n         - restore selinux security context\r\n       [2016-03-16T17:13:16+00:00] WARN: Cloning resource attributes for service[firewalld] from prior resource (CHEF-3694)\r\n       [2016-03-16T17:13:16+00:00] WARN: Previous service[firewalld]: /tmp/kitchen/cache/cookbooks/firewall/libraries/provider_firewall_firewalld.rb:38:in `block (2 levels) in <class:FirewallFirewalld>'\r\n       [2016-03-16T17:13:16+00:00] WARN: Current  service[firewalld]: /tmp/kitchen/cache/cookbooks/firewall/libraries/provider_firewall_firewalld.rb:92:in `block in <class:FirewallFirewalld>'\r\n       \r\n       \r\n       Running handlers:\r\n       [2016-03-16T17:13:19+00:00] ERROR: Running exception handlers\r\n       Running handlers complete\r\n       [2016-03-16T17:13:19+00:00] ERROR: Exception handlers complete\r\n       Chef Client failed. 8 resources updated in 06 seconds\r\n       [2016-03-16T17:13:19+00:00] FATAL: Stacktrace dumped to /tmp/kitchen/cache/chef-stacktrace.out\r\n       [2016-03-16T17:13:19+00:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report\r\n       [2016-03-16T17:13:19+00:00] ERROR: test_lwrp[baz] (consumes_test::default line 13) had an error: Chef::Exceptions::ResourceNotFound: firewall_rule[foo] (/tmp/kitchen/cache/cookbooks/test/resources/lwrp.rb line 4) had an error: Chef::Exceptions::ResourceNotFound: Cannot find a resource matching firewall[default] (did you define it first?)\r\n       [2016-03-16T17:13:21+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)\r\n>>>>>> Converge failed on instance <default-centos-71>.\r\n>>>>>> Please see .kitchen/logs/default-centos-71.log for more details\r\n>>>>>> ------Exception-------\r\n>>>>>> Class: Kitchen::ActionFailed\r\n>>>>>> Message: SSH exited (1) for command: [sh -c '\r\n\r\nsudo -E /opt/chef/bin/chef-client --local-mode --config /tmp/kitchen/client.rb --log_level warn --force-formatter --no-color --json-attributes /tmp/kitchen/dna.json --chef-zero-port 8889\r\n']\r\n>>>>>> ----------------------\r\nzlib(finalizer): the stream was freed prematurely.\r\n```\r\n\r\n## Stacktrace\r\n\r\n```\r\n[vagrant@default-centos-71 ~]$ sudo cat /tmp/kitchen/cache/chef-stacktrace.out\r\nGenerated at 2016-03-16 17:13:19 +0000\r\nChef::Exceptions::ResourceNotFound: test_lwrp[baz] (consumes_test::default line 13) had an error: Chef::Exceptions::ResourceNotFound: firewall_rule[foo] (/tmp/kitchen/cache/cookbooks/test/resources/lwrp.rb line 4) had an error: Chef::Exceptions::ResourceNotFound: Cannot find a resource matching firewall[default] (did you define it first?)\r\n/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/lib/chef/resource_collection/resource_set.rb:63:in `lookup'\r\n/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/lib/chef/resource_collection/resource_set.rb:142:in `block (2 levels) in find_resource_by_hash'\r\n/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/lib/chef/resource_collection/resource_set.rb:141:in `each'\r\n/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/lib/chef/resource_collection/resource_set.rb:141:in `block in find_resource_by_hash'\r\n/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/lib/chef/resource_collection/resource_set.rb:139:in `each'\r\n/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/lib/chef/resource_collection/resource_set.rb:139:in `find_resource_by_hash'\r\n/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/lib/chef/resource_collection/resource_set.rb:85:in `block in find'\r\n/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/lib/chef/resource_collection/resource_set.rb:82:in `each'\r\n/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/lib/chef/resource_collection/resource_set.rb:82:in `find'\r\n/tmp/kitchen/cache/cookbooks/firewall/libraries/provider_firewall_rule.rb:27:in `block in <class:FirewallRuleGeneric>'\r\n/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/lib/chef/provider/lwrp_base.rb:87:in `instance_eval'\r\n/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/lib/chef/provider/lwrp_base.rb:87:in `block in action'\r\n/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/lib/chef/provider.rb:144:in `run_action'\r\n/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/lib/chef/resource.rb:596:in `run_action'\r\n/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/lib/chef/runner.rb:73:in `run_action'\r\n/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/lib/chef/runner.rb:105:in `block (2 levels) in converge'\r\n/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/lib/chef/runner.rb:105:in `each'\r\n/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/lib/chef/runner.rb:105:in `block in converge'\r\n/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/lib/chef/resource_collection/resource_list.rb:84:in `block in execute_each_resource'\r\n/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/lib/chef/resource_collection/stepable_iterator.rb:116:in `call'\r\n/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/lib/chef/resource_collection/stepable_iterator.rb:116:in `call_iterator_block'\r\n/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/lib/chef/resource_collection/stepable_iterator.rb:85:in `step'\r\n/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/lib/chef/resource_collection/stepable_iterator.rb:104:in `iterate'\r\n/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/lib/chef/resource_collection/stepable_iterator.rb:55:in `each_with_index'\r\n/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/lib/chef/resource_collection/resource_list.rb:82:in `execute_each_resource'\r\n/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/lib/chef/runner.rb:104:in `converge'\r\n/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/lib/chef/provider.rb:361:in `compile_and_converge_action'\r\n(eval):2:in `action_foo'\r\n/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/lib/chef/provider.rb:144:in `run_action'\r\n/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/lib/chef/resource.rb:596:in `run_action'\r\n/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/lib/chef/runner.rb:73:in `run_action'\r\n/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/lib/chef/runner.rb:105:in `block (2 levels) in converge'\r\n/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/lib/chef/runner.rb:105:in `each'\r\n/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/lib/chef/runner.rb:105:in `block in converge'\r\n/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/lib/chef/resource_collection/resource_list.rb:84:in `block in execute_each_resource'\r\n/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/lib/chef/resource_collection/stepable_iterator.rb:116:in `call'\r\n/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/lib/chef/resource_collection/stepable_iterator.rb:116:in `call_iterator_block'\r\n/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/lib/chef/resource_collection/stepable_iterator.rb:85:in `step'\r\n/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/lib/chef/resource_collection/stepable_iterator.rb:104:in `iterate'\r\n/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/lib/chef/resource_collection/stepable_iterator.rb:55:in `each_with_index'\r\n/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/lib/chef/resource_collection/resource_list.rb:82:in `execute_each_resource'\r\n/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/lib/chef/runner.rb:104:in `converge'\r\n/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/lib/chef/client.rb:668:in `block in converge'\r\n/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/lib/chef/client.rb:663:in `catch'\r\n/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/lib/chef/client.rb:663:in `converge'\r\n/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/lib/chef/client.rb:702:in `converge_and_save'\r\n/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/lib/chef/client.rb:280:in `run'\r\n/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/lib/chef/application.rb:270:in `block in fork_chef_client'\r\n/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/lib/chef/application.rb:258:in `fork'\r\n/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/lib/chef/application.rb:258:in `fork_chef_client'\r\n/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/lib/chef/application.rb:223:in `block in run_chef_client'\r\n/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/lib/chef/local_mode.rb:44:in `with_server_connectivity'\r\n/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/lib/chef/application.rb:211:in `run_chef_client'\r\n/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/lib/chef/application/client.rb:445:in `block in interval_run_chef_client'\r\n/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/lib/chef/application/client.rb:435:in `loop'\r\n/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/lib/chef/application/client.rb:435:in `interval_run_chef_client'\r\n/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/lib/chef/application/client.rb:424:in `run_application'\r\n/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/lib/chef/application.rb:58:in `run'\r\n/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.8.1/bin/chef-client:26:in `<top (required)>'\r\n/opt/chef/bin/chef-client:50:in `load'\r\n/opt/chef/bin/chef-client:50:in `<main>'\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/chef/chef/issues/comments/203677679","html_url":"https://github.com/chef/chef/issues/4718#issuecomment-203677679","issue_url":"https://api.github.com/repos/chef/chef/issues/4718","id":203677679,"user":{"login":"lamont-granquist","id":454857,"avatar_url":"https://avatars.githubusercontent.com/u/454857?v=3","gravatar_id":"","url":"https://api.github.com/users/lamont-granquist","html_url":"https://github.com/lamont-granquist","followers_url":"https://api.github.com/users/lamont-granquist/followers","following_url":"https://api.github.com/users/lamont-granquist/following{/other_user}","gists_url":"https://api.github.com/users/lamont-granquist/gists{/gist_id}","starred_url":"https://api.github.com/users/lamont-granquist/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lamont-granquist/subscriptions","organizations_url":"https://api.github.com/users/lamont-granquist/orgs","repos_url":"https://api.github.com/users/lamont-granquist/repos","events_url":"https://api.github.com/users/lamont-granquist/events{/privacy}","received_events_url":"https://api.github.com/users/lamont-granquist/received_events","type":"User","site_admin":false},"created_at":"2016-03-30T23:13:46Z","updated_at":"2016-03-30T23:13:46Z","body":"re: `when consuming an upstream cookbook there's nothing I can do about it.`\r\n\r\nsubmit a PR to the cookbook and fix it.  extract the recipe into a resource or definition/method and replace the default recipe with a call to that.\r\n\r\ne.g. https://github.com/chef-cookbooks/aws/pull/231"}}