Why does Drupal insist on deleting my configuration? I've got a custom module with a configuration file config/schema/entity.schema.yml. This configuration file is imported via an update hook :
  $active_storage = \Drupal::service('config.storage');
  foreach ($files as $file) {
    $active_storage-&gt;write($file, $source-&gt;read($file));
  }

This works well, and the configuration in that file gets imported.
However, during the subsequent run of drush cim drush insist on deleting that configuration. I assume that is because the entity.schema.yml does not exist in the root config/synch folder.
Is this the expected behaviour? How can I make Drupal not delete the configuration which is imported from the module's /config/schema folder?
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 &quot;make the DB match those files in the sync directory&quot;. Export does the opposite. It's completely ignorant of other factors. So to make your changes &quot;stick&quot;

enable the module
run drush cex
afterwards drush cim should show &quot;no changes&quot;

NOTE: you can override config in settings.php files by using `$config[my.config.file][a_key] = &quot;my_value&quot;. 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.