This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1 | |
| function createDockerVolume { | |
| cmd=$(docker volume ls -q | grep $1) | |
| if [[ "$cmd" == $1 ]]; | |
| then | |
| echo 'volume available' | |
| else |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| echo '·· Pre-Start executed >>>> ··' | |
| bash /var/mongo/pre-start.sh | |
| sleep 20 | |
| echo '·· Pre-Start done >>>> ··' | |
| echo '·· Starting DB Service >>>> ··' | |
| bash /var/mongo/start.sh | |
| sleep 20 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| admin = db.getSiblingDB("admin") | |
| admin.createUser( | |
| { | |
| user: "{{ env "DB_ADMIN_USER" }}", | |
| pwd: "{{ env "DB_ADMIN_PASS" }}", | |
| roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] | |
| } | |
| ) | |
| db.getSiblingDB("admin").auth("{{ env "DB_ADMIN_USER" }}", "{{ env "DB_ADMIN_PASS" }}" ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| consul-template -template "/var/mongo/admin.js.ctmpl:/var/mongo/admin.js" -once | |
| consul-template -template "/var/mongo/grantRole.js.ctmpl:/var/mongo/grantRole.js" -once | |
| consul-template -template "/var/mongo/replica.js.ctmpl:/var/mongo/replica.js" -once | |
| cat > /var/mongo/hosts.sh <<EOF | |
| . /etc/environment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| DBS=`aws ec2 describe-instances --filters "Name=tag:Name,Values=*Mongo*" --query 'Reservations[].Instances[].PrivateIpAddress' --region $AWS_DEFAULT_REGION` | |
| DB1=`echo $DBS | jq .[0] | sed -e 's/"//g'` | |
| DB2=`echo $DBS | jq .[1] | sed -e 's/"//g'` | |
| DB3=`echo $DBS | jq .[2] | sed -e 's/"//g'` | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| DB_HOST=`echo ${hostname} | sed -e 's/ip-//'` | |
| IP=`ip -f inet addr show eth0 | grep -Po 'inet \K[\d.]+'` | |
| DB_PORT=27017 | |
| BOOKSTORE_DBUSER=bookstore | |
| BOOKSTORE_DBPASS=bookstorepass1 | |
| CINEMA_DBUSER=cinemas | |
| CINEMA_DBPASS=cinemaspass1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # This script is meant to be run in the User Data of each EC2 Instance while it's booting. | |
| set -e | |
| # Send the log output from this script to user-data.log, syslog, and the console | |
| exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1 | |
| echo "export DB_ADMIN_USER=${dbAdminUser}" >> /etc/environment | |
| echo "export DB_ADMIN_PASS=${dbAdminUserPass}" >> /etc/environment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| data "aws_availability_zones" "available_zones" {} | |
| data "aws_ami" "db_image" { | |
| most_recent = true | |
| owners = ["${var.aws_account}"] | |
| filter { | |
| name = "name" | |
| values = ["mongo*"] | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| provider "aws" { | |
| access_key = "${var.access_key}" | |
| secret_key = "${var.secret_key}" | |
| region = "${var.region}" | |
| } | |
| terraform { | |
| required_version = ">= 0.11.9" | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| variable "ami_id" {} | |
| variable "num_of_instances" {} | |
| variable "instance_type" {} | |
| variable "subnet_id" {} | |
| variable "ssh_key" {} | |
| variable "volume_size" {} | |
| variable "user_data" {} | |
| variable "cluster_name" {} | |
| variable "instance_name" {} | |
| variable "associate_public_ip_address" {} |