open-consul/terraform/aws/consul.tf
Johanan Lieberman a3065ff3e1 Fix string concatenation in consul.tf
Since Terraform 0.7 doesn't support the concat() function for string
concatenation, a replacement for concat() needs to be used when
joining strings.
2016-08-04 13:12:56 +00:00

75 lines
1.8 KiB
HCL

resource "aws_instance" "server" {
ami = "${lookup(var.ami, "${var.region}-${var.platform}")}"
instance_type = "${var.instance_type}"
key_name = "${var.key_name}"
count = "${var.servers}"
security_groups = ["${aws_security_group.consul.name}"]
connection {
user = "${lookup(var.user, var.platform)}"
key_file = "${var.key_path}"
}
#Instance tags
tags {
Name = "${var.tagName}-${count.index}"
}
provisioner "file" {
source = "${path.module}/../shared/scripts/${lookup(var.service_conf, var.platform)}"
destination = "/tmp/${lookup(var.service_conf_dest, var.platform)}"
}
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}/../shared/scripts/install.sh",
"${path.module}/../shared/scripts/service.sh",
"${path.module}/../shared/scripts/ip_tables.sh",
]
}
}
resource "aws_security_group" "consul" {
name = "consul_${var.platform}"
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"]
}
// This is for outbound internet access
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}