Skip to content

Instantly share code, notes, and snippets.

@davidlares
Last active September 11, 2019 19:56
Show Gist options
  • Save davidlares/6d9d4ff54a55f166d873cac04472f62c to your computer and use it in GitHub Desktop.
Save davidlares/6d9d4ff54a55f166d873cac04472f62c to your computer and use it in GitHub Desktop.
Terraform's Digital Ocean instance configuration files with an Nginx Server
apt-get update && apt-get install nginx -y
Aleatory data
output "ip" {
value = "${digitalocean_droplet.web.ipv4_address}"
}
provider "digitalocean" {
token = var.token
}
resource "digitalocean_ssh_key" "default" {
name = "example"
"public_key" = "${file("~/.ssh/id_rsa.pub")}"
}
resource "digitalocean_droplet" "web" {
image = "ubuntu-18-04-x64"
name = "davidDroplet"
region = "nyc3"
size = "s-1vcpu-1gb"
ssh_keys = ["${digitalocean_ssh_key.default.fingerprint}"]
connection {
user = "root"
type = "ssh"
host = "${digitalocean_droplet.web.ipv4_address}"
private_key = "${file("~/.ssh/id_rsa")}"
}
provisioner "remote-exec" {
inline = [
"chmod +x /tmp/data.sh",
"cd /tmp/ && ./data.sh"
]
}
provisioner "file" {
source = "data.txt"
destination = "/tmp/data.txt"
}
provisioner "file" {
source = "data.sh"
destination = "/tmp/data.sh"
}
}
resource "digitalocean_domain" "default" {
name = "yourdomain.com"
ip_address = "${digitalocean_droplet.web.ipv4_address}"
}
token = "YOUR_DIGITAL_OCEAN_API_TOKEN"
variable "token" {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment