Skip to content

Using custom database configuration

Since Grove 0.9.0 you can use custom database configuration. You can set the database name and username, but not the password, host or port. The main reason is that Terraform should manage the database resources, so it should be able to create and destroy them, update the configuration for every instance if the host and port are changed, and be able to regenerate the password if password requirements are changed.

Use cases

So, when should you use custom database configuration if you cannot set the password? Here are some use cases:

  • You want to use a custom database name or username.
  • You want to use a custom database name or username for the forum.
  • You want to migrate an instance from another platform (like Ocim) to use Grove with an existing database.

Setting up custom database configuration

To use custom database configuration, you need to first import the database resource into Terraform state. You can do this by running the following command:

cd ./control
./tf import <module path> <id>

For example, if you want to import the database resource for the my-instance instance on DigitalOcean, you can run:

cd ./control
./tf import module.mysql.digitalocean_database_cluster.database_cluster 245bcfd0-7f31-4ce6-a2bc-475a116cca97

If everything went well, you should see that the database resource is imported into the Terraform state. You can now use the custom database configuration by setting the required Tutor variables in your config.yml file, for example:

# instances/my-instance/config.yml
MONGODB_USERNAME: custom-mongouser
MONGODB_DATABASE: custom-mongodb
FORUM_MONGODB_DATABASE: custom-forum-mongodb
OPENEDX_MYSQL_USERNAME: custom-mysqluser

The forum database is using the same MongoDB username as the main MongoDB database.

At this point, tutor and terraform will use the custom database configuration. However, the database password will be generated by terraform.

If you want to migrate an instance from another platform, you can use the same process, but make sure to set different username for the database. This way you can prevent conflicts with the existing user that is used by the other platform.

So what to do when migrating an instance? First, you need to import the database resource into Terraform state. Then, you need to set the custom database configuration in the config.yml file. Finally, you need to deploy the instance with the new configuration.

Changing database name

In some cases, especially when you import resources, you may want to configure specific name and identifier for your database. In these cases, you can set the following variables in your cluster.yml or private.yml configuration:

TF_VAR_mongodbatlas_cluster_name: atlas-cluster-name
TF_VAR_rds_identifier: rds-cluster-name

Although you have the opportunity to set custom names, be aware: whenever you change the names, that will result in resource replacement, hence all your data will be destroyed.