diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2016-10-10 14:15:25 -0700 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2016-10-10 14:15:25 -0700 |
commit | eb372fb68fb96c4d59ac7c78ad98e40b6dbb4a8c (patch) | |
tree | 70ab5031276cc3b6cde5820044b11ecb18cb384d /lib/chef/dsl/declare_resource.rb | |
parent | 6f2315803b046d07eaef641cb2c427327c32e265 (diff) | |
download | chef-eb372fb68fb96c4d59ac7c78ad98e40b6dbb4a8c.tar.gz |
pass new_resource to edit_resource through instance_exec
helps with scoping issues, best practice would be to always use
the |new_resource| argument to the block when using edit_resource
inside of resources
https://github.com/chef/chef/issues/5438
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
Diffstat (limited to 'lib/chef/dsl/declare_resource.rb')
-rw-r--r-- | lib/chef/dsl/declare_resource.rb | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/chef/dsl/declare_resource.rb b/lib/chef/dsl/declare_resource.rb index 86227a0f9d..dca0558bf1 100644 --- a/lib/chef/dsl/declare_resource.rb +++ b/lib/chef/dsl/declare_resource.rb @@ -119,7 +119,13 @@ class Chef # def edit_resource!(type, name, created_at = nil, run_context: self.run_context, &resource_attrs_block) resource = find_resource!(type, name, run_context: run_context) - resource.instance_eval(&resource_attrs_block) if block_given? + if block_given? + if defined?(new_resource) + resource.instance_exec(new_resource, &resource_attrs_block) + else + resource.instance_exec(&resource_attrs_block) + end + end resource end |