Create a new resource in ruby_block

Hello,
I’m trying to create a new aws_route53_record resource from aws cookbook (https://github.com/chef-cookbooks/aws) in ruby_block and run it immediately. Is something like that possible/supported?
The reason I need to do this is that I will know the hostname only in the middle of my ruby_block. I tried to use lazy evaluation, but it doesn’t seem to work, because apparently I can’t set name attribute lazily. This:

route53_record “create a record” do
name lazy { node.run_state[:record_name] + ‘.foo.bar.com’ }
value lazy { node.run_state[:ips] }
type "A"
zone_id "ID VALUE"
overwrite true
fail_on_error false
action :create
end

fails on “undefined method `+’ for nil:NilClass”.

You cannot set the name as a property like that. This appears to be a bug in the resource in that there is no name_property property, which is how you usually fix this. Probably just an oversight, but in the short term to answer your question: no. ruby_block is only for normal Ruby code, not Chef recipe DSL. For that you’ll need to make a custom resource. It will be a very short custom resource and you might only use it once, but that’s still the easiest approach :slight_smile: