terraform/examples/digitalocean/main.tf

44 lines
1.1 KiB
HCL

provider "digitalocean" {
# You need to set this in your .bashrc
# export DIGITALOCEAN_TOKEN="Your API TOKEN"
#
}
resource "digitalocean_droplet" "mywebserver" {
# 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"
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"
}
}
}
resource "digitalocean_domain" "mywebserver" {
name = "www.mywebserver.com"
ip_address = "${digitalocean_droplet.mywebserver.ipv4_address}"
}
resource "digitalocean_record" "mywebserver" {
domain = "${digitalocean_domain.mywebserver.name}"
type = "A"
name = "mywebserver"
value = "${digitalocean_droplet.mywebserver.ipv4_address}"
}