2016-05-09 09:04:51 +02:00
|
|
|
provider "digitalocean" {
|
2016-09-22 13:49:09 +02:00
|
|
|
# You need to set this in your .bashrc
|
|
|
|
# export DIGITALOCEAN_TOKEN="Your API TOKEN"
|
|
|
|
#
|
2016-05-09 09:04:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "digitalocean_droplet" "mywebserver" {
|
2016-09-22 13:49:09 +02:00
|
|
|
# Obtain your ssh_key id number via your account. See Document https://developers.digitalocean.com/documentation/v2/#list-all-keys
|
|
|
|
ssh_keys = [12345678] # Key example
|
|
|
|
image = "${var.ubuntu}"
|
|
|
|
region = "${var.do_ams3}"
|
|
|
|
size = "512mb"
|
|
|
|
private_networking = true
|
|
|
|
backups = true
|
|
|
|
ipv6 = true
|
|
|
|
name = "mywebserver-ams3"
|
2016-05-09 09:04:51 +02:00
|
|
|
|
2016-09-22 13:49:09 +02:00
|
|
|
provisioner "remote-exec" {
|
|
|
|
inline = [
|
|
|
|
"export PATH=$PATH:/usr/bin",
|
|
|
|
"sudo apt-get update",
|
|
|
|
"sudo apt-get -y install nginx",
|
|
|
|
]
|
|
|
|
|
|
|
|
connection {
|
|
|
|
type = "ssh"
|
|
|
|
key_file = "file(${HOME}/.ssh/id_rsa)"
|
|
|
|
user = "root"
|
|
|
|
timeout = "2m"
|
|
|
|
}
|
|
|
|
}
|
2016-05-09 09:04:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "digitalocean_domain" "mywebserver" {
|
2016-09-22 13:49:09 +02:00
|
|
|
name = "www.mywebserver.com"
|
|
|
|
ip_address = "${digitalocean_droplet.mywebserver.ipv4_address}"
|
2016-05-09 09:04:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "digitalocean_record" "mywebserver" {
|
2016-09-22 13:49:09 +02:00
|
|
|
domain = "${digitalocean_domain.mywebserver.name}"
|
|
|
|
type = "A"
|
|
|
|
name = "mywebserver"
|
|
|
|
value = "${digitalocean_droplet.mywebserver.ipv4_address}"
|
2016-05-09 09:04:51 +02:00
|
|
|
}
|