2015-05-09 20:50:11 +00:00
|
|
|
# Specify the provider and access details
|
|
|
|
provider "aws" {
|
|
|
|
region = "${var.region}"
|
|
|
|
access_key = "${var.access_key}"
|
|
|
|
secret_key = "${var.secret_key}"
|
|
|
|
}
|
|
|
|
|
2014-10-12 00:09:51 +00:00
|
|
|
resource "aws_instance" "server" {
|
|
|
|
ami = "${lookup(var.ami, var.region)}"
|
2015-03-14 18:00:22 +00:00
|
|
|
instance_type = "${var.instance_type}"
|
2014-10-12 00:09:51 +00:00
|
|
|
key_name = "${var.key_name}"
|
|
|
|
count = "${var.servers}"
|
|
|
|
security_groups = ["${aws_security_group.consul.name}"]
|
|
|
|
|
|
|
|
connection {
|
|
|
|
user = "ubuntu"
|
|
|
|
key_file = "${var.key_path}"
|
|
|
|
}
|
|
|
|
|
|
|
|
provisioner "file" {
|
|
|
|
source = "${path.module}/scripts/upstart.conf"
|
|
|
|
destination = "/tmp/upstart.conf"
|
|
|
|
}
|
|
|
|
|
|
|
|
provisioner "file" {
|
|
|
|
source = "${path.module}/scripts/upstart-join.conf"
|
|
|
|
destination = "/tmp/upstart-join.conf"
|
|
|
|
}
|
|
|
|
|
|
|
|
provisioner "remote-exec" {
|
|
|
|
inline = [
|
|
|
|
"echo ${var.servers} > /tmp/consul-server-count",
|
|
|
|
"echo ${aws_instance.server.0.private_dns} > /tmp/consul-server-addr",
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
provisioner "remote-exec" {
|
|
|
|
scripts = [
|
|
|
|
"${path.module}/scripts/install.sh",
|
|
|
|
"${path.module}/scripts/server.sh",
|
|
|
|
"${path.module}/scripts/service.sh",
|
|
|
|
]
|
|
|
|
}
|
2015-05-09 20:50:11 +00:00
|
|
|
|
|
|
|
#Instance tags
|
|
|
|
tags {
|
|
|
|
Name = "${var.tagName}-${count.index}"
|
|
|
|
}
|
2014-10-12 00:09:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_security_group" "consul" {
|
|
|
|
name = "consul"
|
|
|
|
description = "Consul internal traffic + maintenance."
|
|
|
|
|
|
|
|
// These are for internal traffic
|
|
|
|
ingress {
|
|
|
|
from_port = 0
|
|
|
|
to_port = 65535
|
|
|
|
protocol = "tcp"
|
|
|
|
self = true
|
|
|
|
}
|
|
|
|
|
|
|
|
ingress {
|
|
|
|
from_port = 0
|
|
|
|
to_port = 65535
|
|
|
|
protocol = "udp"
|
|
|
|
self = true
|
|
|
|
}
|
|
|
|
|
|
|
|
// These are for maintenance
|
|
|
|
ingress {
|
|
|
|
from_port = 22
|
|
|
|
to_port = 22
|
|
|
|
protocol = "tcp"
|
|
|
|
cidr_blocks = ["0.0.0.0/0"]
|
|
|
|
}
|
|
|
|
}
|