Search code examples
amazon-web-servicesterraformamazon-aurora

Multiple RDS aurora mysql Database Schemas in the same cluster process using Terraform


I want to create multiple schemas under same cluster through Terraform module. I am using below module to create db however it creates only 1 schema per cluster and i dont see property to specify multiple schemas

module "rds-aurora-mysql" 

Is there any way through TF moudule to achieve the same?


Solution

  • Terraform's AWS provider only has functionality to provision the platform that hosts the MySQL DBMS (Aurora). Creating schemas, databases, roles etc... has to be done using the DBMS (running SQL queries).

    In order to do this through terraform, you'll have to use a provider created for MySQL (a quick google search found petoju/mysql - please complete the nessecary due dilligence when using open source libraries in a production environment!).

    Best practices for running database clusters in the cloud call for isolating the cluster in it's own private network (AWS VPC) with tightly controlled rules for incoming and outgoing traffic. This poses a problem as terraform will need to connect directly to MySQL in order to provision the resources.

    If you're running terraform from a CI/CD pipeline (GH Actions, CircleCI, etc...) that has limitied networking configuration, or on a local machine. You can create a 'bastion' ec2 instance that lives in a subnet with access to the outside internet. You can then setup an SSH tunnel to that instance from the CI runner that you can proxy the request through using the provider's proxy function or terraform's ALL_PROXY environment variable.

    If you have full control of the CI/CD runners (GH Actions self hosted runners) and they are running in another AWS VPC, you can setup VPC peering which will allow the runners to directly communicate with the Aurora clusters.