Setting up a database in a template

First of all: Coder is running on my server at the office, and I want to host the workspaces on it too with Docker.

I've got a PHP project I'm trying to create a template for.
It requires a MySQL/MariaDB database to run, so I'm trying to set that up now, but I'm not sure how to go about it.

Do I create another terraform resource for it, like:

resource "docker_image" "mariadb" {
  name         = "docker.io/mariadb:latest"
  keep_locally = false
}

resource "docker_container" "mariadb" {
  image = docker_image.mariadb.latest
  name  = "${data.coder_workspace.me.owner}-${data.coder_workspace.me.name}-mariadb"
  ports {
    internal = 3306
    external = 3306
  }
  env = ["MARIADB_ROOT_PASSWORD=elastic"]
}

provider "mysql" {
  endpoint = "localhost:3306"
  username = "root"
  password = "elastic"
}

resource "mysql_database" "app" {
  name = "project_db_name"
}


Or is there another preferred way to do it?
Was this page helpful?