Skip to content

Instantly share code, notes, and snippets.

@hapiben
Forked from robmorgan/provider.tf
Created May 19, 2017 01:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hapiben/4154c160c6d8d21ba82400039e931cb9 to your computer and use it in GitHub Desktop.
Save hapiben/4154c160c6d8d21ba82400039e931cb9 to your computer and use it in GitHub Desktop.
Use Terraform to create a droplet on Digital Ocean
variable "do_token" {}
variable "pub_key" {}
variable "pvt_key" {}
variable "ssh_fingerprint" {}
provider "digitalocean" {
token = "${var.do_token}"
}
resource "digitalocean_droplet" "www-1" {
image = "ubuntu-14-04-x64"
name = "www-1"
region = "fra1"
size = "512mb"
private_networking = true
ssh_keys = [
"${var.ssh_fingerprint}"
]
provisioner "remote-exec" {
connection {
user = "root"
type = "ssh"
key_file = "${var.pvt_key}"
timeout = "2m"
}
inline = [
"export PATH=$PATH:/usr/bin",
# install nginx
"sudo apt-get update",
"sudo apt-get -y install nginx"
# install php
"sudo apt-get install php5-fpm",
# cgi.fix_pathinfo=0
"sudo sed -i 's/HAPROXY_PUBLIC_IP/${digitalocean_droplet.haproxy-www.ipv4_address}/g' /etc/haproxy/haproxy.cfg",
# install composer
service nginx restart
# restart nginx to load changes
# restart php5-fpm
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment