diff --git a/examples/digitalocean/README.md b/examples/digitalocean/README.md new file mode 100644 index 000000000..11cce5762 --- /dev/null +++ b/examples/digitalocean/README.md @@ -0,0 +1,15 @@ +# Digital Ocean Droplet launch and setting the Domain records at Digital ocean. + +The example launches a Ubuntu 14.04, runs apt-get update and installs nginx. Also demostrates how to create DNS records under Domains at DigitalOcean. + +To run, configure your Digital Ocean provider as described in https://www.terraform.io/docs/providers/digitalocean/index.html + +## Prerequisites +You need to export you DigitalOcean API Token as an environment variable + +export DIGITALOCEAN_TOKEN="Put Your Token Here" + +## Run this example using: + + terraform plan + terraform apply diff --git a/examples/digitalocean/main.tf b/examples/digitalocean/main.tf new file mode 100644 index 000000000..becfe2f98 --- /dev/null +++ b/examples/digitalocean/main.tf @@ -0,0 +1,43 @@ +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}" +} diff --git a/examples/digitalocean/outputs.tf b/examples/digitalocean/outputs.tf new file mode 100644 index 000000000..689d40a69 --- /dev/null +++ b/examples/digitalocean/outputs.tf @@ -0,0 +1,7 @@ +output "Public ip" { + value = "${digitalocean_droplet.mywebserver.ipv4_address}" +} + +output "Name" { + value = "${digitalocean_droplet.mywebserver.name}" +} diff --git a/examples/digitalocean/variable.tf b/examples/digitalocean/variable.tf new file mode 100644 index 000000000..0382c15b5 --- /dev/null +++ b/examples/digitalocean/variable.tf @@ -0,0 +1,71 @@ +# #### +# Current Availiable Datacenter Regions +# As of 05-07-2016 +# + +variable "do_ams2" { + description = "Digital Ocean Amsterdam Data Center 2" + default = "ams2" +} + +variable "do_ams3" { + description = "Digital Ocean Amsterdam Data Center 3" + default = "ams3" +} + +variable "do_fra1" { + description = "Digital Ocean Frankfurt Data Center 1" + default = "fra1" +} + +variable "do_lon1" { + description = "Digital Ocean London Data Center 1" + default = "lon1" +} + +variable "do_nyc1" { + description = "Digital Ocean New York Data Center 1" + default = "nyc1" +} + +variable "do_nyc2" { + description = "Digital Ocean New York Data Center 2" + default = "nyc2" +} + +variable "do_nyc3" { + description = "Digital Ocean New York Data Center 3" + default = "nyc3" +} + +variable "do_sfo1" { + description = "Digital Ocean San Francisco Data Center 1" + default = "sfo1" +} + +variable "do_sgp1" { + description = "Digital Ocean Singapore Data Center 1" + default = "sgp1" +} + +variable "do_tor1" { + description = "Digital Ocean Toronto Datacenter 1" + default = "tor1" +} + +# Default Os + +variable "ubuntu" { + description = "Default LTS" + default = "ubuntu-14-04-x64" +} + +variable "centos" { + description = "Default Centos" + default = "centos-72-x64" +} + +variable "coreos" { + description = "Defaut Coreos" + default = "coreos-899.17.0" +}