Yes this is the expected behavior. Config import and export is really quite simplistic (uncharitably: dumb). All it is doing when you run a config operation is to look at the active state of the DB and the active state of the sync directory and make one look like the other. On config:import
(cim) you are saying "make the DB match those files in the sync directory". Export does the opposite. It's completely ignorant of other factors. So to make your changes "stick"
- enable the module
- run
drush cex
- afterwards
drush cim
should show "no changes"
NOTE: you can override config in settings.php files by using `$config[my.config.file][a_key] = "my_value". This bypasses whatever the files say to do. This is very useful for per environment overrides or sensitive inputs like API keys.
A simpler approach over this manual writing you have is to add your config yml file to your_module/config/install/
. When the module is installed this will be imported to the active config state. As commenters have mention when you then run drush config:export (cex) the files will be added to your config sync directory.
Note that your config in /install are essentially one time use. They should also not include the uuid in the top line of the file that is generated in cex built yml.
If you want to install config again from your /install directory you can accomplish this manually by running: drush cim -y --partial --source=modules/custom/my_module/config/install
--partial means do not remove any configuration.
drush cex
and commit before importing again