terraform: fix formatting of consul.tf (#4580)

This commit is contained in:
Evan Farrell 2018-10-24 11:02:38 -04:00 committed by Hans Hasselberg
parent 344d78dc54
commit 4ea03e7db7
8 changed files with 233 additions and 231 deletions

View File

@ -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"]
}
}

View File

@ -1,3 +1,3 @@
output "server_address" {
value = "${aws_instance.server.0.public_dns}"
value = "${aws_instance.server.0.public_dns}"
}

View File

@ -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"
}
}

View File

@ -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"
access_config {
# Ephemeral
}
}
network_interface {
network = "default"
service_account {
scopes = ["https://www.googleapis.com/auth/compute.readonly"]
}
access_config {
# Ephemeral
}
}
connection {
user = "${lookup(var.user, var.platform)}"
private_key = "${file("${var.key_path}")}"
}
service_account {
scopes = ["https://www.googleapis.com/auth/compute.readonly"]
}
provisioner "file" {
source = "${path.module}/../shared/scripts/${lookup(var.service_conf, var.platform)}"
destination = "/tmp/${lookup(var.service_conf_dest, var.platform)}"
}
connection {
user = "${lookup(var.user, var.platform)}"
private_key = "${file("${var.key_path}")}"
}
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 "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" {
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"
source_tags = ["${var.tag_name}"]
target_tags = ["${var.tag_name}"]
ports = [
"8300", # Server RPC
"8301", # Serf LAN
"8302", # Serf WAN
"8400", # RPC
]
}
source_tags = ["${var.tag_name}"]
target_tags = ["${var.tag_name}"]
}

View File

@ -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}"
}

View File

@ -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"
}

View File

@ -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}"
key_pair = "consul-keypair"
count = "${var.servers}"
connection {
user = "${var.user_login}"
key_file = "${var.key_file_path}"
timeout = "1m"
}
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.conf"
destination = "/tmp/upstart.conf"
}
provisioner "file" {
source = "${path.module}/scripts/upstart-join.conf"
destination = "/tmp/upstart-join.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" {
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",
]
}
provisioner "remote-exec" {
scripts = [
"${path.module}/scripts/install.sh",
"${path.module}/scripts/server.sh",
"${path.module}/scripts/service.sh",
]
}
}

View File

@ -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."
}