I am currently working on a project where we are using DrupalVM as composer dependency.
Since ssh into the VM machine to execute commands could be a little cumbersome, and providing a site configuration file to take advantage of the --target option to execute commands remotely was not an option, because the generate commands can not be executed remotely if you want to use the interactive mode.
My options got narrowed to execute vagrant ssh and run commands within the VM (which I already mentioned I am not a big fan) or take advantage of the vagrant-exec plugin.
I decided to give a try to the vagrant-exec plugin and this what you need to do to use it in your project when DrupalVM is required via composer.
Execute plugin install command.
|vagrant plugin install vagrant-exec|
Create or update your config/Vagrantfile.local file with the following configuration:
|config.exec.commands '*', directory: '/var/www/drupal'|
Execute command using plugin
|vagrant exec bin/drupal generate:module|
After this easy steps you can now execute DrupalConsole or any other shell commands against the VM without the need to shh into the machine.