terraform test for digitalocean

we will use terraform tool to create new instance on digitalocean cloud

1 upload your ssh public key on digitalocean

2 create digitalocean API token

3 find ssh public key id on digitalocean API

1
2
export $DO_TOKEN='**********your api token************'
$ curl -X GET "https://api.digitalocean.com/v2/account/keys" -H "Authorization: Bearer $DO_TOKEN"

4 edite your var file . terraform.tfvars

1
2
3
4
do_token="**********your api token************"
size="2GB"
ssh_keys="77xx22"
key_file="/Users/username/.ssh/id_ras"

5 create your provider file like: ubuntu_do.tf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
variable "do_token" {}
variable "ssh_keys" {}
variable "key_file" {}
variable "size" {
default = "2gb"
}
provider "digitalocean" {
token = "${var.do_token}"
}
resource "digitalocean_droplet" "vpn-100" {
name = "vpn-100"
image = "ubuntu-14-04-x64"
private_networking = true
region = "nyc2"
size = "${var.size}"
ssh_keys = ["${var.ssh_keys}"]
provisioner "remote-exec" {
connection {
user = "root"
key_file = "${var.key_file}"
}
inline = [
"apt-get update -y",
"apt-get install -y nginx",
]
}
}

6 Ok . create all file then deploy it on current dir

1
terraform apply

7 login Do web site . look find vpn-100