How to port active configuration to module configuration
Use Features: It basically does exactly what you want, it turns your existing configuration into a module_foobar/config/install/ 

Be aware though that Features merges config (it does add and update existing config, but it does not remove/delete unused config like core configuration management).