Usage :
chmod u+x ./zen.sh
./zen.sh my-dcos-stack
#!/bin/bash | |
set -o errexit -o nounset -o pipefail | |
if [ -z "${1:-}" ] | |
then | |
echo Usage: $(basename "$0") STACK_NAME | |
exit 1 | |
fi | |
STACK_NAME="$1" | |
VPC_CIDR=10.0.0.0/16 | |
PRIVATE_SUBNET_CIDR=10.0.0.0/17 | |
PUBLIC_SUBNET_CIDR=10.0.128.0/20 | |
echo "Creating Zen Template Dependencies" | |
vpc=$(aws ec2 create-vpc --cidr-block "$VPC_CIDR" --instance-tenancy default | jq -r .Vpc.VpcId) | |
aws ec2 wait vpc-available --vpc-ids "$vpc" | |
aws ec2 create-tags --resources "$vpc" --tags Key=Name,Value="$STACK_NAME" | |
aws ec2 modify-vpc-attribute --vpc-id $vpc --enable-dns-support --enable-dns-hostnames | |
echo "VpcId: $vpc" | |
ig=$(aws ec2 create-internet-gateway | jq -r .InternetGateway.InternetGatewayId) | |
aws ec2 attach-internet-gateway --internet-gateway-id "$ig" --vpc-id "$vpc" | |
aws ec2 create-tags --resources "$ig" --tags Key=Name,Value="$STACK_NAME" | |
echo "InternetGatewayId: $ig" | |
private_subnet=$(aws ec2 create-subnet --vpc-id "$vpc" --cidr-block "$PRIVATE_SUBNET_CIDR" | jq -r .Subnet.SubnetId) | |
aws ec2 wait subnet-available --subnet-ids "$private_subnet" | |
aws ec2 create-tags --resources "$private_subnet" --tags Key=Name,Value="${STACK_NAME}-private" | |
echo "Private SubnetId: $private_subnet" | |
public_subnet=$(aws ec2 create-subnet --vpc-id "$vpc" --cidr-block "$PUBLIC_SUBNET_CIDR" | jq -r .Subnet.SubnetId) | |
aws ec2 wait subnet-available --subnet-ids "$public_subnet" | |
aws ec2 create-tags --resources "$public_subnet" --tags Key=Name,Value="${STACK_NAME}-public" | |
echo "Public SubnetId: $public_subnet" | |
# Replace values in zen_cli_values.json according to the output | |
sed -i -e "s/__private_subnet_id__/$private_subnet/g" ./zen_cli_values.json | |
sed -i -e "s/__public_subnet_id__/$public_subnet/g" ./zen_cli_values.json | |
sed -i -e "s/__vpc_id__/$vpc/g" ./zen_cli_values.json | |
sed -i -e "s/__igw_id__/$igw/g" ./zen_cli_values.json | |
curl -O https://downloads.dcos.io/dcos/EarlyAccess/commit/14509fe1e7899f439527fb39867194c7a425c771/cloudformation/zen-1.json?_ga=1.107072385.2003301116.1469179716 | |
aws cloudformation create-stack \ | |
--stack-name $1 | |
--template-body file://./zen-1.json?_ga=1.107072385.2003301116.1469179716 | |
--parameters file://./zen_cli_values.json --tags Key=cluster,Value=$1 --capabilities CAPABILITY_IAM | |
[{ | |
"ParameterKey": "PublicSubnet", | |
"ParameterValue": __public_subnet_id__ | |
},{ | |
"ParameterKey": "MasterInstanceType", | |
"ParameterValue": "m3.xlarge" | |
},{ | |
"ParameterKey": "PrivateAgentInstanceCount", | |
"ParameterValue": "5" | |
},{ | |
"ParameterKey": "PrivateSubnet", | |
"ParameterValue": __private_subnet_id__ | |
},{ | |
"ParameterKey": "PublicAgentInstanceType", | |
"ParameterValue": "m3.xlarge" | |
},{ | |
"ParameterKey": "PublicAgentInstanceCount", | |
"ParameterValue": "5" | |
},{ | |
"ParameterKey": "KeyName", | |
"ParameterValue": "cloudera" | |
},{ | |
"ParameterKey": "Vpc", | |
"ParameterValue": __vpc_id__ | |
},{ | |
"ParameterKey": "InternetGateway", | |
"ParameterValue": __igw_id__ | |
}] | |