First, I'm not expert in Ruby or Chef for that matter. I have a custom resource that takes a parameter that I'm trying to pass to another custom resource. It's not working. The parameter isn't getting set on the second resource, so the second resource is only seeing the default for the parameter.
# cookbook/recipes/default/caller.rb
# Call first_resource and pass 2 as the index
first_resource "Pass in 2" do
index 2
end
# cookbook/resources/first_resource.rb
resource_name :first_resource
property :index, Integer, default: 1
action :execute do
# call my second custom resource and pass index to it
second_resource "Call second resource with #{index}" do
index index
end
end
# cookbook/resources/second_resource.rb
resource_name :second_resource
property :index, Integer, 1
action :execute do
raise "The index is #{index}"
end
In essence, my recipe "caller.rb" needs to pass a variable (index) to the first resource, which in turn needs to pass said variable to a second resource. The issue I'm having is that the second resource is always getting the default value of 1, even though I'm passing in 2. I figure that the parameter's value for second_resource gets set when Chef does the compilation phase?
I can't pass the value from my recipe all the way through to the second resource.
I've read about load_current_value in the docs but when I use it outside of an action, I can't call any resources. I have also tried using load_current_value inside an action but then I get a NoMethodError.
Help!