Skip to content

Instantly share code, notes, and snippets.

@samber
Created April 6, 2018 08:54
Show Gist options
  • Save samber/c8c3ed24d763d7d1f97683a3fb03ad2c to your computer and use it in GitHub Desktop.
Save samber/c8c3ed24d763d7d1f97683a3fb03ad2c to your computer and use it in GitHub Desktop.
# export TF_VAR_do_token="qwertyuiop"
variable "do_token" {}
variable "region" { default = "lon1" }
provider "digitalocean" {
token = "${var.do_token}"
}
resource "digitalocean_droplet" "webs" {
image = "docker-16-04"
name = "web-${terraform.workspace}-${count.index}"
region = "${var.region}"
size = "512mb"
count = 2
ssh_keys = [
"11:f4:d8:2d:c0:6a:a7:73:2d:6e:c4:5e:5c:1c:71:e0"
]
provisioner "remote-exec" {
inline = [
"docker run -d -p 8080:80 -h $(hostname) iadvize/hello-world"
]
}
}
resource "digitalocean_loadbalancer" "front_lb" {
name = "webs-loadbalancer-${terraform.workspace}"
region = "${var.region}"
forwarding_rule {
entry_port = 8080
entry_protocol = "http"
target_port = 8080
target_protocol = "http"
}
healthcheck {
port = 8080
protocol = "http"
path = "/"
}
droplet_ids = ["${digitalocean_droplet.webs.*.id}"]
}
output "ipv4" { value = "${digitalocean_droplet.webs.*.ipv4_address}" }
output "lb" { value = "${digitalocean_loadbalancer.front_lb.ip}" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment