Have different required attributes fro different actions on a resource

how can I make it a resource, so that :

if the action is install, the install_dir attribute be required,

and if the action is patch, the patch_id attribute be required ?

On 2/16/15 11:13 AM, Medya wrote:

how can I make it a resource, so that :

if the action is install, the install_dir attribute be required,

and if the action is patch, the patch_id attribute be required ?

Probably in the after_created hook in the resource:

I'd consider whyrun assertions for this too :wink:

--aj

On Tue, Feb 17, 2015 at 8:46 AM, Lamont Granquist lamont@chef.io wrote:

On 2/16/15 11:13 AM, Medya wrote:

how can I make it a resource, so that :

if the action is install, the install_dir attribute be required,

and if the action is patch, the patch_id attribute be required ?

Probably in the after_created hook in the resource:

https://github.com/chef/chef/blob/master/lib/chef/resource/remote_file.rb#L128-L130

Yeah, but if its just validation logic then its not really conditional
on why-run. The fact that its conditional on a combination of
properties of the resource and the action means that you have to do it
after the resource is fully created. You could do in the after_create
hook, the initializer of the provider, load_current_resource or
define_resource_requirements. As long as its a feature of the resource
and doesn't depend on which provider is hooked up to the resource, then
it probably goes into the after_created hook to keep all the validation
with the resource (and then it should blow it up early at compile-time,
rather than converge).

On 2/16/15 11:58 AM, AJ Christensen wrote:

I'd consider whyrun assertions for this too :wink:

--aj

On Tue, Feb 17, 2015 at 8:46 AM, Lamont Granquist lamont@chef.io wrote:

On 2/16/15 11:13 AM, Medya wrote:

how can I make it a resource, so that :

 if the action is install, the install_dir attribute be required,

 and if the action is patch, the patch_id attribute be required ?

Probably in the after_created hook in the resource:

https://github.com/chef/chef/blob/master/lib/chef/resource/remote_file.rb#L128-L130