I've looked all over and can't find a coherent resource that describes how to do this straightforwardly. I have a project like so:
./
|-src/
|--..
|--Dockerfile
|-docker-compose.yaml
A terraform config file like this:
variable "do_token" {}
# Configure the DigitalOcean Provider
provider "digitalocean" {
token = "${var.do_token}"
}
# Create a web server
resource "digitalocean_droplet" "web" {
# ...
}
I want to be able to do something like
provider "digitalocean" {
ip = <my-ip>
# docker-compose up ?
}
My compose file sets up the application architecture properly. I just want a way to deploy that to a given box somewhere on digital ocean (via ip preferably) and the run docker-compose up
. How can I do this?
Provisioners
Terraform has provisioners which allow you to copy files and execute scripts on resource creation.
The Chef provisioner can also be used with a compose cookbook
Docker
Terraform has a plain Docker provider but doesn't manage Compose or Swarm definitions out of the box so you would need to define your compose environment piece by piece in volumes, networks, images, containers).
Kubernetes
For deploying real world apps With Terraform you are probably better of using the Kubernetes provider that will let you set up a replication controller to run pods that are accessed as services on Docker. This will require running a Kubernetes cluster and writing the Kubernetes definition, Kompose can help converting from Docker Compose.