-
Notifications
You must be signed in to change notification settings - Fork 9
Notes on ZooKeeper Terraform Script
Richard Hightower edited this page Nov 28, 2017
·
1 revision
Initial plan for terraform
[defaults]
hostfile = inventory.ini
[ssh_connection]
ssh_args = -F ssh/ssh.config -o ControlMaster=auto -o ControlPersist=30m -o StrictHostKeyChecking=no
control_path = %(directory)s/%%h-%%p-%%r
[zoo-nodes]
zoo.node0
zoo.node1
zoo.node2
println("hi mom")
import java.io.File
import scala.io.Source
import scala.collection.mutable.ListBuffer
val cwd = new File(".")
val buffer = new ListBuffer[String]()
val allowedExt = Set(".sh", ".yml", ".ini", ".cfg", ".tf", ".scala", ".config")
def process(file:File, buffer:ListBuffer[String]) : Unit = {
buffer append file.listFiles().filter(f=>f.isFile)
.filter(f=> allowedExt.find {ext=> f.getName.endsWith(ext)}.isDefined)
.map(f=> "\n####" + f.getCanonicalPath + "\n```\n" +
Source.fromFile(f).getLines.mkString("\n") + "\n```").toList.mkString("\n")
file.listFiles().filter(f=>f.isDirectory)
.filter(f=> !f.getName.contains("terraform"))
.filter(f=>file!=f).foreach(dir=>process(dir, buffer))
}
process(cwd, buffer)
println(buffer.mkString("\n").replace(" /", " /"))
variable "name" {
description = "Name of thing you are creating (app name or service name), i.e., sdp, matching-engine, shopper-tools."
}
variable "role" {
description = "Role of thing you are creating, i.e., kafkaNode0, cassandraClusterNode1."
default = ""
}
variable "owner_contact" {
description = "Team contact"
}
variable "ci-group" {
description = "CIG CI for the stack"
}
variable "cost-center" {
description = "CostCenter tag"
}
variable "unique_name" {
description = "unique name for system"
}
variable "environment" {
description = "environment only, dev, qa, prod."
}
variable "region" {
description = "region only"
}
module "nic0" {
source = "../../tf-network-interface"
name = "${var.name}"
role = "${var.role}0"
owner_contact = "${var.owner_contact}"
ci-group = "${var.ci-group}"
cost-center = "${var.cost-center}"
unique_name = "${var.unique_name}"
environment = "${var.environment}"
region = "${var.region}"
az_letter = "a"
}
module "nic1" {
source = "../../tf-network-interface"
name = "${var.name}"
role = "${var.role}1"
owner_contact = "${var.owner_contact}"
ci-group = "${var.ci-group}"
cost-center = "${var.cost-center}"
unique_name = "${var.unique_name}"
environment = "${var.environment}"
region = "${var.region}"
az_letter = "b"
}
module "nic2" {
source = "../../tf-network-interface"
name = "${var.name}"
role = "${var.role}2"
owner_contact = "${var.owner_contact}"
ci-group = "${var.ci-group}"
cost-center = "${var.cost-center}"
unique_name = "${var.unique_name}"
environment = "${var.environment}"
region = "${var.region}"
az_letter = "c"
}
output "nic_id_0" {
value = "${module.nic0.eni-id}"
}
output "nic_id_1" {
value = "${module.nic1.eni-id}"
}
output "nic_id_2" {
value = "${module.nic2.eni-id}"
}
output "private_ip_0" {
value = "${module.nic0.private_ip}"
}
output "private_ip_1" {
value = "${module.nic1.private_ip}"
}
output "private_ip_2" {
value = "${module.nic2.private_ip}"
}
#!/bin/bash
UNIQUE_ID='abc123456' #`cat /dev/random | LC_CTYPE=C tr -dc "[:alpha:]" | head -c 8`
terraform "$@" \
-var 'environment=dev' \
-var 'name=shopperTools' \
-var 'role=zooKeeperNic' \
-var 'region=us-east-1' \
-var "unique_name=$UNIQUE_ID" \
-var '[email protected]' \
-var 'ci-group=CIGShoppingCart' \
-var 'cost-center=ENVNPShoppingCart'
#!/bin/bash
#
#if [ $# -lt 1 ];
#then
# echo "USAGE: connect <host>"
# exit 1
#fi
ssh-keygen -R `terraform output private_ip`
ssh -o "StrictHostKeyChecking no" \
-i ../../tf-aws-instance/resources/server/certs/test_rsa \
centos@`terraform output private_ip`
module "node0" {
az_letter = "a"
source = "../../tf-ec2-docker-host-instance"
os = "centos"
image_tag = "0.3"
image_name = "zookeeper"
image_repo = "dockyard.cloud.cloudurable.com/ci-groupphoenix/emi-zookeeper"
owner_contact = "${var.owner_contact}"
role = "${var.role}"
ci-group = "${var.ci-group}"
unique_name = "${var.unique_name}"
region = "${var.region}"
cost-center = "${var.cost-center}"
name = "${var.name}"
environment = "${var.environment}"
eni_id = "${var.eni_id}"
volume_0_device_name="xvdf"
volume_0_mount_point="/opt/zookeeper/data/snapshots"
volume_0_id = "${var.volume_snapshot_id}"
volume_1_device_name="xvdg"
volume_1_mount_point="/opt/zookeeper/data/logs"
volume_1_id = "${var.volume_log_id}"
pub_key = "${var.pub_key}"
image_environment_variables = [
"ENSEMBLE=${var.ensemble_0},${var.ensemble_1},${var.ensemble_2}",
"MY_ID=1",
"ZOO_DATA_DIR=/opt/zookeeper/data/snapshots",
"ZOO_DATA_LOG_DIR=/opt/zookeeper/data/logs"
]
image_volumes = [
"/opt/zookeeper/data/snapshots:/opt/zookeeper/data/snapshots:Z",
"/opt/zookeeper/data/logs:/opt/zookeeper/data/logs:Z",
]
}
variable "ensemble_0" {
description = "zookeeper 0 address"
}
variable "ensemble_1" {
description = "zookeeper 1 address"
}
variable "ensemble_2" {
description = "zookeeper 2 address"
}
variable "name" {
description = "Name of thing you are creating (app name or service name), i.e., sdp, matching-engine, shopper-tools."
}
variable "eni_id" {
description = "ENI ID of NiC"
}
variable "pub_key" {
description = "public key"
}
variable "volume_snapshot_id" {
description = "volume EBS snapshot ID"
}
variable "volume_log_id" {
description = "volume EBS log ID"
}
variable "role" {
description = "Role of thing you are creating, i.e., kafkaNode0, cassandraClusterNode1."
default = ""
}
variable "owner_contact" {
description = "Team contact"
}
variable "ci-group" {
description = "CIG CI for the stack"
}
variable "cost-center" {
description = "CostCenter tag"
}
variable "unique_name" {
description = "unique name for system"
}
variable "environment" {
description = "environment only, dev, qa, prod."
}
variable "region" {
description = "region only"
}
output "private_ip" {
value = "${module.node0.private_ip}"
}
output "aws_instance_id" {
value = "${module.node0.aws_instance_id}"
}
#!/bin/bash
UNIQUE_ID='abc123456' #`cat /dev/random | LC_CTYPE=C tr -dc "[:alpha:]" | head -c 8`
STATE_VOL_ARG="-state=../volumes/terraform.tfstate"
VOLUME_LOG=`terraform output $STATE_VOL_ARG log_volume_0_id`
VOLUME_SNAPSHOT=`terraform output $STATE_VOL_ARG snapshot_volume_0_id`
STATE_NIC_ARG="-state=../network-interfaces/terraform.tfstate"
NIC_ID=`terraform output $STATE_NIC_ARG nic_id_0`
PRIVATE_IP_0=`terraform output $STATE_NIC_ARG private_ip_0`
PRIVATE_IP_1=`terraform output $STATE_NIC_ARG private_ip_1`
PRIVATE_IP_2=`terraform output $STATE_NIC_ARG private_ip_2`
export TF_VAR_pub_key=`cat ../../tf-aws-instance/resources/server/certs/test_rsa.pub`
export TF_VAR_volume_log_id="${VOLUME_LOG}"
export TF_VAR_volume_snapshot_id="${VOLUME_SNAPSHOT}"
export TF_VAR_eni_id="$NIC_ID"
export TF_VAR_ensemble_0="$PRIVATE_IP_0"
export TF_VAR_ensemble_1="$PRIVATE_IP_1"
export TF_VAR_ensemble_2="$PRIVATE_IP_2"
terraform "$@" \
-var 'environment=dev' \
-var 'name=shopperTools' \
-var 'role=zooKeeperNode0' \
-var 'region=us-east-1' \
-var "unique_name=$UNIQUE_ID" \
-var '[email protected]' \
-var 'ci-group=CIGShoppingCart' \
-var 'cost-center=ENVNPShoppingCart'
#!/bin/bash
#
#if [ $# -lt 1 ];
#then
# echo "USAGE: connect <host>"
# exit 1
#fi
ssh-keygen -R `terraform output private_ip`
ssh -o "StrictHostKeyChecking no" \
-i ../../tf-aws-instance/resources/server/certs/test_rsa \
centos@`terraform output private_ip`
module "node1" {
az_letter = "b"
source = "../../tf-ec2-docker-host-instance"
os = "centos"
image_tag = "0.3"
image_name = "zookeeper"
image_repo = "dockyard.cloud.cloudurable.com/ci-groupphoenix/emi-zookeeper"
owner_contact = "${var.owner_contact}"
role = "${var.role}"
ci-group = "${var.ci-group}"
unique_name = "${var.unique_name}"
region = "${var.region}"
cost-center = "${var.cost-center}"
name = "${var.name}"
environment = "${var.environment}"
eni_id = "${var.eni_id}"
volume_0_device_name="xvdf"
volume_0_mount_point="/opt/zookeeper/data/snapshots"
volume_0_id = "${var.volume_snapshot_id}"
volume_1_device_name="xvdg"
volume_1_mount_point="/opt/zookeeper/data/logs"
volume_1_id = "${var.volume_log_id}"
pub_key = "${var.pub_key}"
image_environment_variables = [
"ENSEMBLE=${var.ensemble_0},${var.ensemble_1},${var.ensemble_2}",
"MY_ID=2",
"ZOO_DATA_DIR=/opt/zookeeper/data/snapshots",
"ZOO_DATA_LOG_DIR=/opt/zookeeper/data/logs"
]
image_volumes = [
"/opt/zookeeper/data/snapshots:/opt/zookeeper/data/snapshots:Z",
"/opt/zookeeper/data/logs:/opt/zookeeper/data/logs:Z",
]
}
variable "ensemble_0" {
description = "zookeeper 0 address"
}
variable "ensemble_1" {
description = "zookeeper 1 address"
}
variable "ensemble_2" {
description = "zookeeper 2 address"
}
variable "name" {
description = "Name of thing you are creating (app name or service name), i.e., sdp, matching-engine, shopper-tools."
}
variable "eni_id" {
description = "ENI ID of NiC"
}
variable "pub_key" {
description = "public key"
}
variable "volume_snapshot_id" {
description = "volume EBS snapshot ID"
}
variable "volume_log_id" {
description = "volume EBS log ID"
}
variable "role" {
description = "Role of thing you are creating, i.e., kafkaNode0, cassandraClusterNode1."
default = ""
}
variable "owner_contact" {
description = "Team contact"
}
variable "ci-group" {
description = "CIG CI for the stack"
}
variable "cost-center" {
description = "CostCenter tag"
}
variable "unique_name" {
description = "unique name for system"
}
variable "environment" {
description = "environment only, dev, qa, prod."
}
variable "region" {
description = "region only"
}
output "private_ip" {
value = "${module.node1.private_ip}"
}
output "aws_instance_id" {
value = "${module.node1.aws_instance_id}"
}
#!/bin/bash
UNIQUE_ID='abc123456' #`cat /dev/random | LC_CTYPE=C tr -dc "[:alpha:]" | head -c 8`
STATE_VOL_ARG="-state=../volumes/terraform.tfstate"
VOLUME_LOG=`terraform output $STATE_VOL_ARG log_volume_1_id`
VOLUME_SNAPSHOT=`terraform output $STATE_VOL_ARG snapshot_volume_1_id`
STATE_NIC_ARG="-state=../network-interfaces/terraform.tfstate"
NIC_ID=`terraform output $STATE_NIC_ARG nic_id_1`
PRIVATE_IP_0=`terraform output $STATE_NIC_ARG private_ip_0`
PRIVATE_IP_1=`terraform output $STATE_NIC_ARG private_ip_1`
PRIVATE_IP_2=`terraform output $STATE_NIC_ARG private_ip_2`
export TF_VAR_pub_key=`cat ../../tf-aws-instance/resources/server/certs/test_rsa.pub`
export TF_VAR_volume_log_id="${VOLUME_LOG}"
export TF_VAR_volume_snapshot_id="${VOLUME_SNAPSHOT}"
export TF_VAR_eni_id="$NIC_ID"
export TF_VAR_ensemble_0="$PRIVATE_IP_0"
export TF_VAR_ensemble_1="$PRIVATE_IP_1"
export TF_VAR_ensemble_2="$PRIVATE_IP_2"
terraform "$@" \
-var 'environment=dev' \
-var 'name=shopperTools' \
-var 'role=zooKeeperNode1' \
-var 'region=us-east-1' \
-var "unique_name=$UNIQUE_ID" \
-var '[email protected]' \
-var 'ci-group=CIGShoppingCart' \
-var 'cost-center=ENVNPShoppingCart'
#!/bin/bash
#
#if [ $# -lt 1 ];
#then
# echo "USAGE: connect <host>"
# exit 1
#fi
ssh-keygen -R `terraform output private_ip`
ssh -o "StrictHostKeyChecking no" \
-i ../../tf-aws-instance/resources/server/certs/test_rsa \
centos@`terraform output private_ip`
module "node2" {
az_letter = "c"
source = "../../tf-ec2-docker-host-instance"
os = "centos"
image_tag = "0.3"
image_name = "zookeeper"
image_repo = "dockyard.cloud.cloudurable.com/ci-groupphoenix/emi-zookeeper"
owner_contact = "${var.owner_contact}"
role = "${var.role}"
ci-group = "${var.ci-group}"
unique_name = "${var.unique_name}"
region = "${var.region}"
cost-center = "${var.cost-center}"
name = "${var.name}"
environment = "${var.environment}"
eni_id = "${var.eni_id}"
volume_0_device_name="xvdf"
volume_0_mount_point="/opt/zookeeper/data/snapshots"
volume_0_id = "${var.volume_snapshot_id}"
volume_1_device_name="xvdg"
volume_1_mount_point="/opt/zookeeper/data/logs"
volume_1_id = "${var.volume_log_id}"
pub_key = "${var.pub_key}"
image_environment_variables = [
"ENSEMBLE=${var.ensemble_0},${var.ensemble_1},${var.ensemble_2}",
"MY_ID=3",
"ZOO_DATA_DIR=/opt/zookeeper/data/snapshots",
"ZOO_DATA_LOG_DIR=/opt/zookeeper/data/logs"
]
image_volumes = [
"/opt/zookeeper/data/snapshots:/opt/zookeeper/data/snapshots:Z",
"/opt/zookeeper/data/logs:/opt/zookeeper/data/logs:Z",
]
}
variable "ensemble_0" {
description = "zookeeper 0 address"
}
variable "ensemble_1" {
description = "zookeeper 1 address"
}
variable "ensemble_2" {
description = "zookeeper 2 address"
}
variable "name" {
description = "Name of thing you are creating (app name or service name), i.e., sdp, matching-engine, shopper-tools."
}
variable "eni_id" {
description = "ENI ID of NiC"
}
variable "pub_key" {
description = "public key"
}
variable "volume_snapshot_id" {
description = "volume EBS snapshot ID"
}
variable "volume_log_id" {
description = "volume EBS log ID"
}
variable "role" {
description = "Role of thing you are creating, i.e., kafkaNode0, cassandraClusterNode1."
default = ""
}
variable "owner_contact" {
description = "Team contact"
}
variable "ci-group" {
description = "CIG CI for the stack"
}
variable "cost-center" {
description = "CostCenter tag"
}
variable "unique_name" {
description = "unique name for system"
}
variable "environment" {
description = "environment only, dev, qa, prod."
}
variable "region" {
description = "region only"
}
output "private_ip" {
value = "${module.node2.private_ip}"
}
output "aws_instance_id" {
value = "${module.node2.aws_instance_id}"
}
#!/bin/bash
UNIQUE_ID='abc123456' #`cat /dev/random | LC_CTYPE=C tr -dc "[:alpha:]" | head -c 8`
STATE_VOL_ARG="-state=../volumes/terraform.tfstate"
VOLUME_LOG=`terraform output $STATE_VOL_ARG log_volume_2_id`
VOLUME_SNAPSHOT=`terraform output $STATE_VOL_ARG snapshot_volume_2_id`
STATE_NIC_ARG="-state=../network-interfaces/terraform.tfstate"
NIC_ID=`terraform output $STATE_NIC_ARG nic_id_2`
PRIVATE_IP_0=`terraform output $STATE_NIC_ARG private_ip_0`
PRIVATE_IP_1=`terraform output $STATE_NIC_ARG private_ip_1`
PRIVATE_IP_2=`terraform output $STATE_NIC_ARG private_ip_2`
export TF_VAR_pub_key=`cat ../../tf-aws-instance/resources/server/certs/test_rsa.pub`
export TF_VAR_volume_log_id="${VOLUME_LOG}"
export TF_VAR_volume_snapshot_id="${VOLUME_SNAPSHOT}"
export TF_VAR_eni_id="$NIC_ID"
export TF_VAR_ensemble_0="$PRIVATE_IP_0"
export TF_VAR_ensemble_1="$PRIVATE_IP_1"
export TF_VAR_ensemble_2="$PRIVATE_IP_2"
terraform "$@" \
-var 'environment=dev' \
-var 'name=shopperTools' \
-var 'role=zooKeeperNode2' \
-var 'region=us-east-1' \
-var "unique_name=$UNIQUE_ID" \
-var '[email protected]' \
-var 'ci-group=CIGShoppingCart' \
-var 'cost-center=ENVNPShoppingCart'
---
- hosts: zoo-nodes
gather_facts: no
remote_user: centos
become: true
tasks:
- name: install net tools
yum:
name: net-tools
state: present
- name: install nc
yum:
name: nc
state: present
---
- hosts: zoo-nodes
gather_facts: no
remote_user: centos
tasks:
- name: Show zookeeper stats
shell: echo stat | nc localhost 2181
Host 10.207.*
ForwardAgent yes
IdentityFile ../tf-aws-instance/resources/server/certs/test_rsa
User centos
ControlMaster auto
ControlPath ~/.ssh/ansible-%r@%h:%p
ControlPersist 5m
Host zoo.node0
Hostname 10.207.73.192
IdentityFile ../tf-aws-instance/resources/server/certs/test_rsa
User centos
ControlMaster auto
ControlPath ~/.ssh/ansible-%r@%h:%p
ControlPersist 5m
Host zoo.node1
Hostname 10.207.95.93
IdentityFile ../tf-aws-instance/resources/server/certs/test_rsa
User centos
ControlMaster auto
ControlPath ~/.ssh/ansible-%r@%h:%p
ControlPersist 5m
Host zoo.node2
Hostname 10.207.120.73
IdentityFile ../tf-aws-instance/resources/server/certs/test_rsa
User centos
ControlMaster auto
ControlPath ~/.ssh/ansible-%r@%h:%p
ControlPersist 5m
module "volume_0_snapshot" {
source = "../../tf-ebs-volume"
name = "${var.name}"
role = "${var.role}Snapshot0"
owner_contact = "${var.owner_contact}"
ci-group = "${var.ci-group}"
cost-center = "${var.cost-center}"
unique_name = "${var.unique_name}"
environment = "${var.environment}"
region = "${var.region}"
az_letter = "a"
volume_size_gb = "${var.snapshot_volume_size_gb}"
volume_type = "${var.snapshot_volume_type}"
}
module "volume_1_snapshot" {
source = "../../tf-ebs-volume"
name = "${var.name}"
role = "${var.role}Snapshot1"
owner_contact = "${var.owner_contact}"
ci-group = "${var.ci-group}"
cost-center = "${var.cost-center}"
unique_name = "${var.unique_name}"
environment = "${var.environment}"
region = "${var.region}"
az_letter = "b"
volume_size_gb = "${var.snapshot_volume_size_gb}"
volume_type = "${var.snapshot_volume_type}"
}
module "volume_2_snapshot" {
source = "../../tf-ebs-volume"
name = "${var.name}"
role = "${var.role}Snapshot2"
owner_contact = "${var.owner_contact}"
ci-group = "${var.ci-group}"
cost-center = "${var.cost-center}"
unique_name = "${var.unique_name}"
environment = "${var.environment}"
region = "${var.region}"
az_letter = "c"
volume_size_gb = "${var.snapshot_volume_size_gb}"
volume_type = "${var.snapshot_volume_type}"
}
module "volume_0_log" {
source = "../../tf-ebs-volume"
name = "${var.name}"
role = "${var.role}Log0"
owner_contact = "${var.owner_contact}"
ci-group = "${var.ci-group}"
cost-center = "${var.cost-center}"
unique_name = "${var.unique_name}"
environment = "${var.environment}"
region = "${var.region}"
az_letter = "a"
volume_size_gb = "${var.log_volume_size_gb}"
volume_type = "${var.log_volume_type}"
}
module "volume_1_log" {
source = "../../tf-ebs-volume"
name = "${var.name}"
role = "${var.role}Log1"
owner_contact = "${var.owner_contact}"
ci-group = "${var.ci-group}"
cost-center = "${var.cost-center}"
unique_name = "${var.unique_name}"
environment = "${var.environment}"
region = "${var.region}"
az_letter = "b"
volume_size_gb = "${var.log_volume_size_gb}"
volume_type = "${var.log_volume_type}"
}
module "volume_2_log" {
source = "../../tf-ebs-volume"
name = "${var.name}"
role = "${var.role}Log2"
owner_contact = "${var.owner_contact}"
ci-group = "${var.ci-group}"
cost-center = "${var.cost-center}"
unique_name = "${var.unique_name}"
environment = "${var.environment}"
region = "${var.region}"
az_letter = "c"
volume_size_gb = "${var.log_volume_size_gb}"
volume_type = "${var.log_volume_type}"
}
variable "name" {
description = "Name of thing you are creating (app name or service name), i.e., sdp, matching-engine, shopper-tools."
}
variable "role" {
description = "Role of thing you are creating, i.e., kafkaNode0, cassandraClusterNode1."
default = "volume"
}
variable "owner_contact" {
description = "Team contact"
}
variable "ci-group" {
description = "CIG CI for the stack"
}
variable "cost-center" {
description = "CostCenter tag"
}
variable "unique_name" {
description = "unique name for system"
}
variable "environment" {
description = "environment only, dev, qa, prod."
}
variable "region" {
description = "region only"
}
variable "snapshot_volume_size_gb" {}
variable "snapshot_volume_type" {
default = "st1"
}
variable "log_volume_size_gb" {}
variable "log_volume_type" {
default = "gp2"
}
output "log_volume_0_id" {
value = "${module.volume_0_log.volume_id}"
}
output "log_volume_1_id" {
value = "${module.volume_1_log.volume_id}"
}
output "log_volume_2_id" {
value = "${module.volume_2_log.volume_id}"
}
output "snapshot_volume_0_id" {
value = "${module.volume_0_snapshot.volume_id}"
}
output "snapshot_volume_1_id" {
value = "${module.volume_1_snapshot.volume_id}"
}
output "snapshot_volume_2_id" {
value = "${module.volume_2_snapshot.volume_id}"
}
#!/bin/bash
UNIQUE_ID='abc123456' #`cat /dev/random | LC_CTYPE=C tr -dc "[:alpha:]" | head -c 8`
terraform "$@" \
-var 'log_volume_size_gb=1' \
-var 'log_volume_type=gp2' \
-var 'snapshot_volume_size_gb=1' \
-var 'snapshot_volume_type=gp2' \
-var 'environment=dev' \
-var 'name=shopperTools' \
-var 'role=zooKeeperVolumes' \
-var 'region=us-east-1' \
-var "unique_name=$UNIQUE_ID" \
-var '[email protected]' \
-var 'ci-group=CIGShoppingCart' \
-var 'cost-center=ENVNPShoppingCart'