NOTE: I started in
CHEF-1814 but decided to open a new ticket since it has been long since closed out.
I took a swing at this since I just recently ran into an issue where being able to have delayed evaluation of resource attributes would save me a lot of trouble. Just want to add a bit about my line of thinking and why I chose this approach. Changing the timing a resource is evaluated would likely cause unexpected behavior of previously stable resources. I'm also not convinced that memorizing the value on read is the correct approach. Given that I'm providing a proc type instance, it is my assumption that it will be evaluated when I request it, every time I request it, not just the first time. Lastly, having a snowflake approach, I would argue, would be correct since this type of evaluation is different than it has been in the past. Whether that be by providing a lambda/proc or simply a block to the attribute.
That said, using plain proc instances would be problematic since there are times a resource wants a proc instance for an attribute, and evaluating it prior to returning to, say, the provider would likely cause issues the provider would not be expecting. To get around this I introduced a new class (DelayedEvaluator) that merely wraps up the proc type instance in something easily identifiable so we can know for sure if it is something that should be evaluated before being returned. I also threw in a helper method to create these instances (delayed_eval). Ideally, passing a block to the attribute would make the dsl much cleaner looking, but that requires quite a bit of fixing up in the resources. I would like to get some eyes on this and make sure it's the right direction before making all those changes.
Cookbook to monkey patch chef to show proof of concept: http://community.opscode.com/cookbooks/delayed_evaluator
Pull request: https://github.com/opscode/chef/pull/571