I have a custom resource that reuses the core resource execute. It has 2 properties (retries & retry_delay) that have the same name as the properties of the execute resource. See below.
resources/wait.rb
property :name, String, default: 'just wait'
property :retries, Integer, default: 100
property :retry_delay, Integer, default: 10
default_action :create #added default_action to avoid FoodCritic error
action :create do
execute name do
command "some command"
retries new_resource.retries
retry_delay new_resource.retry_delay
end
end
When I try to use my custom wait resource (no properties passed in in order to rely on the default values of the retries and retry_delay properties) as in below, my kitchen converge fails because Chef thinks the values for retries is 0 (vs 100) and the value for retry_delay is 2 (vs 10)
recipes/myrecipe.rb
mycookbook_wait 'wait for process to finish' do
end
I was using this as a reference: https://docs.chef.io/custom_resources.html#new-resource-property
The workaround I had to do was rename the properties of my wait resource as in below:
resources/wait.rb with workaround
property :name, String, default: 'wait for Jenkins'
property :retry_count, Integer, default: 100
property :retry_delay_seconds, Integer, default: 10
default_action :create #added default_action to avoid FoodCritic error
action :create do
execute name do
command "some command"
retries retry_count
retry_delay retry_delay_seconds
end
end
How can I accomplish the same thing without having to make sure that my resource property names don’t collide with core resource property names?