Tweaks DO example Terraform.
This commit is contained in:
parent
4006bd441b
commit
f40600b9bb
|
@ -1,8 +1,8 @@
|
||||||
|
|
||||||
# Requirements
|
# Requirements
|
||||||
Terraform installed
|
|
||||||
Digital Ocean account with API key
|
* Terraform installed
|
||||||
SSH key uploaded to Digital Ocean
|
* Digital Ocean account with API key
|
||||||
|
* SSH key uploaded to Digital Ocean
|
||||||
|
|
||||||
### Variables
|
### Variables
|
||||||
Populate terraform.tfvars as follows (or execute with arguments as shown in Usage)
|
Populate terraform.tfvars as follows (or execute with arguments as shown in Usage)
|
||||||
|
@ -11,7 +11,7 @@ Populate terraform.tfvars as follows (or execute with arguments as shown in Usag
|
||||||
do_token = "ASDFQWERTYDERP"
|
do_token = "ASDFQWERTYDERP"
|
||||||
num_instances = "3"
|
num_instances = "3"
|
||||||
ssh_key_ID = "my_ssh_keyID_in_digital_ocean"
|
ssh_key_ID = "my_ssh_keyID_in_digital_ocean"
|
||||||
|
region = "desired DO region"
|
||||||
|
|
||||||
# Usage
|
# Usage
|
||||||
|
|
||||||
|
@ -19,10 +19,12 @@ Populate terraform.tfvars as follows (or execute with arguments as shown in Usag
|
||||||
-var 'key_path=~/.ssh/id_rsa' \
|
-var 'key_path=~/.ssh/id_rsa' \
|
||||||
-var 'do_token=ASDFQWERTYDERP' \
|
-var 'do_token=ASDFQWERTYDERP' \
|
||||||
-var 'num_instances=3' \
|
-var 'num_instances=3' \
|
||||||
- var 'ssh_key_ID=86:75:30:99:88:88:AA:FF:DD'
|
-var 'ssh_key_ID=86:75:30:99:88:88:AA:FF:DD' \
|
||||||
|
-var 'region=tor1'
|
||||||
|
|
||||||
terraform apply \
|
terraform apply \
|
||||||
-var 'key_path=~/.ssh/id_rsa' \
|
-var 'key_path=~/.ssh/id_rsa' \
|
||||||
-var 'do_token=ASDFQWERTYDERP' \
|
-var 'do_token=ASDFQWERTYDERP' \
|
||||||
-var 'num_instances=3' \
|
-var 'num_instances=3' \
|
||||||
- var 'ssh_key_ID=86:75:30:99:88:88:AA:FF:DD'
|
-var 'ssh_key_ID=86:75:30:99:88:88:AA:FF:DD' \
|
||||||
|
-var 'region=tor1'
|
||||||
|
|
|
@ -3,39 +3,38 @@ provider "digitalocean" {
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "digitalocean_droplet" "consul" {
|
resource "digitalocean_droplet" "consul" {
|
||||||
ssh_keys = ["${var.ssh_key_ID}"]
|
ssh_keys = ["${var.ssh_key_ID}"]
|
||||||
image = "${var.ubuntu}"
|
image = "${var.ubuntu}"
|
||||||
region = "${var.do_tor1}"
|
region = "${var.region}"
|
||||||
size = "2gb"
|
size = "2gb"
|
||||||
private_networking = true
|
private_networking = true
|
||||||
name = "consul${count.index + 1}"
|
name = "consul${count.index + 1}"
|
||||||
count = "${var.num_instances}"
|
count = "${var.num_instances}"
|
||||||
|
|
||||||
connection {
|
connection {
|
||||||
type = "ssh"
|
type = "ssh"
|
||||||
private_key = "${file("${var.key_path}")}"
|
private_key = "${file("${var.key_path}")}"
|
||||||
user = "root"
|
user = "root"
|
||||||
timeout = "2m"
|
timeout = "2m"
|
||||||
}
|
}
|
||||||
|
|
||||||
provisioner "file" {
|
provisioner "file" {
|
||||||
source = "${path.module}/../shared/scripts/debian_upstart.conf"
|
source = "${path.module}/../shared/scripts/debian_upstart.conf"
|
||||||
destination = "/tmp/upstart.conf"
|
destination = "/tmp/upstart.conf"
|
||||||
}
|
}
|
||||||
|
|
||||||
provisioner "remote-exec" {
|
provisioner "remote-exec" {
|
||||||
inline = [
|
inline = [
|
||||||
"echo ${var.num_instances} > /tmp/consul-server-count",
|
"echo ${var.num_instances} > /tmp/consul-server-count",
|
||||||
"echo ${digitalocean_droplet.consul.0.ipv4_address} > /tmp/consul-server-addr",
|
"echo ${digitalocean_droplet.consul.0.ipv4_address} > /tmp/consul-server-addr",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
provisioner "remote-exec" {
|
provisioner "remote-exec" {
|
||||||
scripts = [
|
scripts = [
|
||||||
"${path.module}/../shared/scripts/install.sh",
|
"${path.module}/../shared/scripts/install.sh",
|
||||||
"${path.module}/../shared/scripts/service.sh",
|
"${path.module}/../shared/scripts/service.sh",
|
||||||
"${path.module}/../shared/scripts/ip_tables.sh",
|
"${path.module}/../shared/scripts/ip_tables.sh",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
output "first_consule_node_address" {
|
output "first_consule_node_address" {
|
||||||
value = "${digitalocean_droplet.consul.0.ipv4_address}"
|
value = "${digitalocean_droplet.consul.0.ipv4_address}"
|
||||||
}
|
}
|
||||||
|
|
||||||
output "all_addresses" {
|
output "all_addresses" {
|
||||||
|
|
|
@ -2,3 +2,4 @@ key_path = "~/.ssh/id_rsa"
|
||||||
ssh_key_ID = "my_ssh_key_ID_or_fingerprint_NOT_SSH_KEY_NAME"
|
ssh_key_ID = "my_ssh_key_ID_or_fingerprint_NOT_SSH_KEY_NAME"
|
||||||
do_token = "ASDFQWERTYDERP"
|
do_token = "ASDFQWERTYDERP"
|
||||||
num_instances = "3"
|
num_instances = "3"
|
||||||
|
region = "tor1"
|
|
@ -1,79 +1,26 @@
|
||||||
variable "do_token" {}
|
variable "do_token" {}
|
||||||
|
|
||||||
variable "key_path" {}
|
variable "key_path" {}
|
||||||
|
|
||||||
variable "ssh_key_ID" {}
|
variable "ssh_key_ID" {}
|
||||||
|
|
||||||
|
variable "region" {}
|
||||||
|
|
||||||
variable "num_instances" {}
|
variable "num_instances" {}
|
||||||
|
|
||||||
## below sourced from
|
# Default OS
|
||||||
## https://github.com/hashicorp/terraform/blob/master/examples/digitalocean/variable.tf
|
|
||||||
|
|
||||||
# ####
|
|
||||||
# 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" {
|
variable "ubuntu" {
|
||||||
description = "Default LTS"
|
description = "Default LTS"
|
||||||
default = "ubuntu-14-04-x64"
|
default = "ubuntu-14-04-x64"
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "centos" {
|
variable "centos" {
|
||||||
description = "Default Centos"
|
description = "Default Centos"
|
||||||
default = "centos-72-x64"
|
default = "centos-72-x64"
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "coreos" {
|
variable "coreos" {
|
||||||
description = "Defaut Coreos"
|
description = "Defaut Coreos"
|
||||||
default = "coreos-899.17.0"
|
default = "coreos-899.17.0"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue