diff --git a/terraform/aws/consul.tf b/terraform/aws/consul.tf index be70ce385fb5..a1d7476fa7e7 100644 --- a/terraform/aws/consul.tf +++ b/terraform/aws/consul.tf @@ -1,77 +1,76 @@ 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.id}"] - subnet_id = "${lookup(var.subnets, count.index % var.servers)}" + 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.id}"] + subnet_id = "${lookup(var.subnets, count.index % var.servers)}" - connection { - user = "${lookup(var.user, var.platform)}" - private_key = "${file("${var.key_path}")}" - } + connection { + user = "${lookup(var.user, var.platform)}" + private_key = "${file("${var.key_path}")}" + } - #Instance tags - tags { - Name = "${var.tagName}-${count.index}" - ConsulRole = "Server" - } + #Instance tags + tags { + Name = "${var.tagName}-${count.index}" + ConsulRole = "Server" + } - provisioner "file" { - source = "${path.module}/../shared/scripts/${lookup(var.service_conf, var.platform)}" - destination = "/tmp/${lookup(var.service_conf_dest, var.platform)}" - } + 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_ip} > /tmp/consul-server-addr", + ] + } - provisioner "remote-exec" { - inline = [ - "echo ${var.servers} > /tmp/consul-server-count", - "echo ${aws_instance.server.0.private_ip} > /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", - ] - } + 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." - vpc_id = "${var.vpc_id}" + name = "consul_${var.platform}" + description = "Consul internal traffic + maintenance." + vpc_id = "${var.vpc_id}" - // These are for internal traffic - ingress { - from_port = 0 - to_port = 65535 - protocol = "tcp" - self = true - } + // 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 - } + 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"] - } + // 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"] - } + // This is for outbound internet access + egress { + from_port = 0 + to_port = 0 + protocol = "-1" + cidr_blocks = ["0.0.0.0/0"] + } } diff --git a/terraform/aws/outputs.tf b/terraform/aws/outputs.tf index f6edc7da66cb..17d4a19b01ce 100644 --- a/terraform/aws/outputs.tf +++ b/terraform/aws/outputs.tf @@ -1,3 +1,3 @@ output "server_address" { - value = "${aws_instance.server.0.public_dns}" + value = "${aws_instance.server.0.public_dns}" } diff --git a/terraform/aws/variables.tf b/terraform/aws/variables.tf index d86354f49251..038d281a325f 100644 --- a/terraform/aws/variables.tf +++ b/terraform/aws/variables.tf @@ -17,20 +17,20 @@ variable "ami" { description = "AWS AMI Id, if you change, make sure it is compatible with instance type, not all AMIs allow all instance types " default = { - ap-south-1-ubuntu = "ami-08a5e367" - us-east-1-ubuntu = "ami-d651b8ac" + ap-south-1-ubuntu = "ami-08a5e367" + us-east-1-ubuntu = "ami-d651b8ac" ap-northeast-1-ubuntu = "ami-8422ebe2" - eu-west-1-ubuntu = "ami-17d11e6e" + eu-west-1-ubuntu = "ami-17d11e6e" ap-southeast-1-ubuntu = "ami-e6d3a585" - ca-central-1-ubuntu = "ami-e59c2581" - us-west-1-ubuntu = "ami-2d5c6d4d" - eu-central-1-ubuntu = "ami-5a922335" - sa-east-1-ubuntu = "ami-a3e39ecf" + ca-central-1-ubuntu = "ami-e59c2581" + us-west-1-ubuntu = "ami-2d5c6d4d" + eu-central-1-ubuntu = "ami-5a922335" + sa-east-1-ubuntu = "ami-a3e39ecf" ap-southeast-2-ubuntu = "ami-391ff95b" - eu-west-2-ubuntu = "ami-e1f2e185" + eu-west-2-ubuntu = "ami-e1f2e185" ap-northeast-2-ubuntu = "ami-0f6fb461" - us-west-2-ubuntu = "ami-ecc63a94" - us-east-2-ubuntu = "ami-9686a4f3" + us-west-2-ubuntu = "ami-ecc63a94" + us-east-2-ubuntu = "ami-9686a4f3" us-east-1-rhel6 = "ami-0d28fe66" us-east-2-rhel6 = "ami-aff2a9ca" us-west-2-rhel6 = "ami-3d3c0a0d" @@ -95,11 +95,11 @@ variable "tagName" { } variable "subnets" { - type = "map" + type = "map" description = "map of subnets to deploy your infrastructure in, must have as many keys as your server count (default 3), -var 'subnets={\"0\"=\"subnet-12345\",\"1\"=\"subnets-23456\"}' " } variable "vpc_id" { - type = "string" + type = "string" description = "ID of the VPC to use - in case your account doesn't have default VPC" -} \ No newline at end of file +} diff --git a/terraform/google/consul.tf b/terraform/google/consul.tf index 373a2a5d5c86..4b3993768a1b 100644 --- a/terraform/google/consul.tf +++ b/terraform/google/consul.tf @@ -1,68 +1,69 @@ resource "google_compute_instance" "consul" { - count = "${var.servers}" + count = "${var.servers}" - name = "consul-${count.index}" - zone = "${var.region_zone}" - tags = ["${var.tag_name}"] + name = "consul-${count.index}" + zone = "${var.region_zone}" + tags = ["${var.tag_name}"] - machine_type = "${var.machine_type}" + machine_type = "${var.machine_type}" - disk { - image = "${lookup(var.machine_image, var.platform)}" - } + disk { + image = "${lookup(var.machine_image, var.platform)}" + } - network_interface { - network = "default" + network_interface { + network = "default" - access_config { - # Ephemeral - } + access_config { + # Ephemeral } + } - service_account { - scopes = ["https://www.googleapis.com/auth/compute.readonly"] - } + service_account { + scopes = ["https://www.googleapis.com/auth/compute.readonly"] + } - connection { - user = "${lookup(var.user, var.platform)}" - private_key = "${file("${var.key_path}")}" - } + connection { + user = "${lookup(var.user, var.platform)}" + private_key = "${file("${var.key_path}")}" + } - provisioner "file" { - source = "${path.module}/../shared/scripts/${lookup(var.service_conf, var.platform)}" - destination = "/tmp/${lookup(var.service_conf_dest, var.platform)}" - } + 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 ${google_compute_instance.consul.0.network_interface.0.address} > /tmp/consul-server-addr", - ] - } + provisioner "remote-exec" { + inline = [ + "echo ${var.servers} > /tmp/consul-server-count", + "echo ${google_compute_instance.consul.0.network_interface.0.address} > /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", - ] - } + provisioner "remote-exec" { + scripts = [ + "${path.module}/../shared/scripts/install.sh", + "${path.module}/../shared/scripts/service.sh", + "${path.module}/../shared/scripts/ip_tables.sh", + ] + } } resource "google_compute_firewall" "consul_ingress" { - name = "consul-internal-access" - network = "default" + name = "consul-internal-access" + network = "default" - allow { - protocol = "tcp" - ports = [ - "8300", # Server RPC - "8301", # Serf LAN - "8302", # Serf WAN - "8400", # RPC - ] - } + allow { + protocol = "tcp" + + ports = [ + "8300", # Server RPC + "8301", # Serf LAN + "8302", # Serf WAN + "8400", # RPC + ] + } - source_tags = ["${var.tag_name}"] - target_tags = ["${var.tag_name}"] + source_tags = ["${var.tag_name}"] + target_tags = ["${var.tag_name}"] } diff --git a/terraform/google/outputs.tf b/terraform/google/outputs.tf index 66d031cb225a..67315c469b63 100644 --- a/terraform/google/outputs.tf +++ b/terraform/google/outputs.tf @@ -1,4 +1,3 @@ output "server_address" { - value = "${google_compute_instance.consul.0.network_interface.0.address}" + value = "${google_compute_instance.consul.0.network_interface.0.address}" } - diff --git a/terraform/google/variables.tf b/terraform/google/variables.tf index d877e359d785..a95e3dc446cf 100644 --- a/terraform/google/variables.tf +++ b/terraform/google/variables.tf @@ -1,72 +1,73 @@ variable "platform" { - default = "ubuntu" - description = "The OS Platform" + default = "ubuntu" + description = "The OS Platform" } variable "user" { - default = { - ubuntu = "ubuntu" - rhel6 = "root" - rhel7 = "root" - centos6 = "root" - centos7 = "root" - } + default = { + ubuntu = "ubuntu" + rhel6 = "root" + rhel7 = "root" + centos6 = "root" + centos7 = "root" + } } variable "machine_image" { - default = { - ubuntu = "ubuntu-os-cloud/ubuntu-1404-trusty-v20160314" - rhel6 = "rhel-cloud/rhel-6-v20160303" - rhel7 = "rhel-cloud/rhel-7-v20160303" - centos6 = "centos-cloud/centos-6-v20160301" - centos7 = "centos-cloud/centos-7-v20160301" - } + default = { + ubuntu = "ubuntu-os-cloud/ubuntu-1404-trusty-v20160314" + rhel6 = "rhel-cloud/rhel-6-v20160303" + rhel7 = "rhel-cloud/rhel-7-v20160303" + centos6 = "centos-cloud/centos-6-v20160301" + centos7 = "centos-cloud/centos-7-v20160301" + } } variable "service_conf" { - default = { - ubuntu = "debian_upstart.conf" - rhel6 = "rhel_upstart.conf" - rhel7 = "rhel_consul.service" - centos6 = "rhel_upstart.conf" - centos7 = "rhel_consul.service" - } + default = { + ubuntu = "debian_upstart.conf" + rhel6 = "rhel_upstart.conf" + rhel7 = "rhel_consul.service" + centos6 = "rhel_upstart.conf" + centos7 = "rhel_consul.service" + } } + variable "service_conf_dest" { - default = { - ubuntu = "upstart.conf" - rhel6 = "upstart.conf" - rhel7 = "consul.service" - centos6 = "upstart.conf" - centos7 = "consul.service" - } + default = { + ubuntu = "upstart.conf" + rhel6 = "upstart.conf" + rhel7 = "consul.service" + centos6 = "upstart.conf" + centos7 = "consul.service" + } } variable "key_path" { - description = "Path to the private key used to access the cloud servers" + description = "Path to the private key used to access the cloud servers" } variable "region" { - default = "us-central1" - description = "The region of Google Cloud where to launch the cluster" + default = "us-central1" + description = "The region of Google Cloud where to launch the cluster" } variable "region_zone" { - default = "us-central1-f" - description = "The zone of Google Cloud in which to launch the cluster" + default = "us-central1-f" + description = "The zone of Google Cloud in which to launch the cluster" } variable "servers" { - default = "3" - description = "The number of Consul servers to launch" + default = "3" + description = "The number of Consul servers to launch" } variable "machine_type" { - default = "f1-micro" - description = "Google Cloud Compute machine type" + default = "f1-micro" + description = "Google Cloud Compute machine type" } variable "tag_name" { - default = "consul" - description = "Name tag for the servers" + default = "consul" + description = "Name tag for the servers" } diff --git a/terraform/openstack/consul.tf b/terraform/openstack/consul.tf index 8c4cd67d8aea..d55734d03fbf 100644 --- a/terraform/openstack/consul.tf +++ b/terraform/openstack/consul.tf @@ -1,60 +1,60 @@ provider "openstack" { - user_name = "${var.username}" - tenant_name = "${var.tenant_name}" - password = "${var.password}" - auth_url = "${var.auth_url}" + user_name = "${var.username}" + tenant_name = "${var.tenant_name}" + password = "${var.password}" + auth_url = "${var.auth_url}" } resource "openstack_compute_keypair_v2" "consul_keypair" { - name = "consul-keypair" - region = "${var.region}" + name = "consul-keypair" + region = "${var.region}" public_key = "${var.public_key}" } resource "openstack_compute_floatingip_v2" "consul_ip" { region = "${var.region}" - pool = "${lookup(var.pub_net_id, var.region)}" - count = "${var.servers}" + pool = "${lookup(var.pub_net_id, var.region)}" + count = "${var.servers}" } resource "openstack_compute_instance_v2" "consul_node" { - name = "consul-node-${count.index}" - region = "${var.region}" - image_id = "${lookup(var.image, var.region)}" - flavor_id = "${lookup(var.flavor, var.region)}" + name = "consul-node-${count.index}" + region = "${var.region}" + image_id = "${lookup(var.image, var.region)}" + flavor_id = "${lookup(var.flavor, var.region)}" floating_ip = "${element(openstack_compute_floatingip_v2.consul_ip.*.address,count.index)}" - key_pair = "consul-keypair" - count = "${var.servers}" - - connection { - user = "${var.user_login}" - key_file = "${var.key_file_path}" - timeout = "1m" - } - - 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 ${count.index} > /tmp/consul-server-index", - "echo ${openstack_compute_instance_v2.consul_node.0.network.0.fixed_ip_v4} > /tmp/consul-server-addr", - ] - } - - provisioner "remote-exec" { - scripts = [ - "${path.module}/scripts/install.sh", - "${path.module}/scripts/server.sh", - "${path.module}/scripts/service.sh", - ] - } + key_pair = "consul-keypair" + count = "${var.servers}" + + connection { + user = "${var.user_login}" + key_file = "${var.key_file_path}" + timeout = "1m" + } + + 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 ${count.index} > /tmp/consul-server-index", + "echo ${openstack_compute_instance_v2.consul_node.0.network.0.fixed_ip_v4} > /tmp/consul-server-addr", + ] + } + + provisioner "remote-exec" { + scripts = [ + "${path.module}/scripts/install.sh", + "${path.module}/scripts/server.sh", + "${path.module}/scripts/service.sh", + ] + } } diff --git a/terraform/openstack/variables.tf b/terraform/openstack/variables.tf index 59fe1076d33e..45c70d4505b9 100644 --- a/terraform/openstack/variables.tf +++ b/terraform/openstack/variables.tf @@ -3,42 +3,44 @@ variable "password" {} variable "tenant_name" {} variable "auth_url" {} variable "public_key" {} + variable "user_login" { - default = "stack" + default = "stack" } + variable "key_file_path" {} variable "nb_of_nodes" { - default = "4" + default = "4" } variable "pub_net_id" { - default = { - tr2="PublicNetwork-01" - tr2-1 = "" - } + default = { + tr2 = "PublicNetwork-01" + tr2-1 = "" + } } variable "region" { - default = "tr2" - description = "The region of openstack, for image/flavor/network lookups." + default = "tr2" + description = "The region of openstack, for image/flavor/network lookups." } variable "image" { - default = { - tr2 = "eee08821-c95a-448f-9292-73908c794661" - tr2-1 = "" - } + default = { + tr2 = "eee08821-c95a-448f-9292-73908c794661" + tr2-1 = "" + } } variable "flavor" { - default = { - tr2 = "100" - tr2-1 = "" - } + default = { + tr2 = "100" + tr2-1 = "" + } } variable "servers" { - default = "3" - description = "The number of Consul servers to launch." + default = "3" + description = "The number of Consul servers to launch." }