How to set default action to destroy for Chef Provision command

Hi,

I’m using ChefDK v0.15.15. When getting help for chef provision command, I found the option --destroy which is said to set default action to destroy.

Chef Provisioning is documented at https://docs.chef.io/provisioning.html

Options:

    -c, --config CONFIG_FILE         Path to configuration file
        --cookbook COOKBOOK_PATH     Path to your provisioning cookbook
    -D, --debug                      Enable stacktraces and other debug output
    -d, --destroy                    Set default machine action to :destroy
        --[no-]policy                Enable/disable policyfile integration (defaults to enabled, use --no-policy to disable)
    -h, --help                       Show this message

In my recipe, I wrote:

machine 'abc' do
  run_list ['abc']
end

But when I actually run the command: chef provision --no-policy --destroy -r machine, the Chef-Client do the action converge instead.

You have to propagate the command line options to the machine resources. Use code like this in the resource:

action(ChefDK::ProvisioningData.context.action)

Daniel DeLeo