Created
May 16, 2017 18:52
-
-
Save serkanh/a60306b0efea3372408a90a694191cc7 to your computer and use it in GitHub Desktop.
Elb creation wizard
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 | |
set -euox pipefail | |
echo "Please enter profile to use" | |
read PROFILE | |
echo "Please enter region to use" | |
read REGION | |
echo "Please enter ELBPORT to use" | |
read ELBPORT | |
echo "Please enter INSTANCEPORT to use" | |
read INSTANCEPORT | |
echo "Please enter ELB_NAME to use" | |
read ELB_NAME | |
if [ -z $ELB_NAME ]; then | |
echo "ELB name have to be set" | |
exit 1 | |
fi | |
ELBPORT=${ELBPORT:-'80'} | |
INSTANCEPORT=${INSTANCEPORT:-'8080'} | |
INSTANCEPORT=${INSTANCEPORT:-'3000'} | |
PROFILE=${PROFILE:-'HA'} | |
REGION=${REGION:-'us-east-1'} | |
getVpcNames(){ | |
aws --profile=HA ec2 describe-vpcs --query "Vpcs[*].Tags[].Value" --output text | |
} | |
# Gets the public subnets on a given vpc. | |
getPublicSubnets(){ | |
echo $(aws --profile=$PROFILE ec2 describe-subnets \ | |
--filters "Name=vpc-id,Values=$VPCID" \ | |
--query "Subnets[?Tags != null && Tags[?contains(Value,\`Public\`)==\`true\`]].SubnetId" --output text ) | |
} | |
# Gets the public subnets on a given vpc. | |
createElb(){ | |
aws --profile=$PROFILE elb create-load-balancer \ | |
--load-balancer-name $ELB_NAME \ | |
--listeners "Protocol=HTTP,LoadBalancerPort=$ELBPORT,InstanceProtocol=HTTP,InstancePort=$INSTANCEPORT" \ | |
--subnets $PUBLIC_SUBNETS \ | |
--security-groups sg-8c2d57f6 | |
} | |
#getVpcNames | |
VPC=$( getVpcNames | sed -e 's/vpc//g' ) | |
echo $VPC | |
select VPCNAME in $VPC; | |
do | |
VPCID=$(aws --profile=HA ec2 describe-vpcs --query "Vpcs[?Tags != null && Tags[?contains(Value,'${VPCNAME}')==\`true\`]].VpcId") | |
PUBLIC_SUBNETS=$(getPublicSubnets $VPCID) | |
createElb | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment