Reputation: 5573
If we are defining a resource such that it will be used as such:
custom_resource 'name' do
some_property some_value
action :create
end
Is there a way I can use name
as a variable in my custom resource definition? Similar to how the file
resource uses the name as a path.
file '/var/www/myfile.php' do
content '<html>Some HTML</html>'
mode '0755'
owner 'web_admin'
group 'web_admin'
end
Upvotes: 2
Views: 1199
Reputation: 21226
By default all the custom resources have the name
property which you can access
new_resource.name
If you need some other property to become name property, as file
resource has path
property as name, you must add name_property: true
to its declaration in your resource like that:
property :some_property, String, name_property: true
https://docs.chef.io/custom_resources.html#define-properties
Upvotes: 2
Reputation: 10122
in your custom resource, you can reference the name
attribute the same as other attributes by using new_resource.name
for more information, checkout:
Upvotes: 1