Django Terraform digitalOcean re-create environment in new droplet

I have saas based Django app, I want, when a customer asks me to use my software, then i will auto provision new droplet and auto-deploy the app there, and the info should be saved in my database, like ip, customer name, database info etc.

This is my terraform script and it is working very well coz, the database is now running on

terraform {
  required_providers {
    digitalocean = {
      source = "digitalocean/digitalocean"
      version = "~> 2.0"
    }
  }
}

provider "digitalocean" {
  token = "dop_v1_60f33a1<MyToken>a363d033" 
}


resource "digitalocean_droplet" "web" {
  image  = "ubuntu-18-04-x64"
  name   = "web-1"
  region = "nyc3"
  size   = "s-1vcpu-1gb"
  ssh_keys = ["93:<The SSH finger print>::01"]

  connection {
    host = self.ipv4_address
    user = "root"
    type = "ssh"
    private_key = file("/home/py/.ssh/id_rsa") # it works
    timeout = "2m"
  }

  provisioner "remote-exec" {
    inline = [
        "export PATH=$PATH:/usr/bin",
        # install docker-compse
        # install docker
        # clone my github repo
        "docker-compose up --build -d"
    ]
  }

}

I want, when i run the commands, it should be create new droplet, new database instance and connect the database with my django .env file.

Everything should be auto created. Can anyone please help me how can I do it?

or my approach is wrong? in this situation, what would be the best solution?

Back to Top