Skip to content

Commit 48c965d

Browse files
committed
Merge pull request #3576 from cleblanc87/aws-cli-profiles
feat(contrib): AWS cli profile param
2 parents d89ea98 + 2604a92 commit 48c965d

2 files changed

Lines changed: 28 additions & 11 deletions

File tree

contrib/ec2/provision-ec2-cluster.sh

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ if ! which aws > /dev/null; then
2323
exit 1
2424
fi
2525

26+
if [ ! -z "$AWS_CLI_PROFILE" ]; then
27+
EXTRA_AWS_CLI_ARGS+="--profile $AWS_CLI_PROFILE"
28+
fi
29+
2630
if [ -z "$DEIS_NUM_INSTANCES" ]; then
2731
DEIS_NUM_INSTANCES=3
2832
fi
@@ -47,7 +51,8 @@ bailout() {
4751
aws cloudformation create-stack \
4852
--template-body "$($THIS_DIR/gen-json.py)" \
4953
--stack-name $STACK_NAME \
50-
--parameters "$(<$THIS_DIR/cloudformation.json)"
54+
--parameters "$(<$THIS_DIR/cloudformation.json)" \
55+
$EXTRA_AWS_CLI_ARGS
5156

5257
# loop until the instances are created
5358
ATTEMPTS=60
@@ -62,20 +67,22 @@ until [ $(wc -w <<< $INSTANCE_IDS) -eq $DEIS_NUM_INSTANCES -a "$STACK_STATUS" =
6267
exit 1
6368
fi
6469

65-
STACK_STATUS=$(aws --output text cloudformation describe-stacks --stack-name $STACK_NAME --query 'Stacks[].StackStatus')
66-
if [ $STACK_STATUS != "CREATE_IN_PROGRESS" -a $STACK_STATUS != "CREATE_COMPLETE" ] ; then
70+
STACK_STATUS=$(aws --output text cloudformation describe-stacks --stack-name $STACK_NAME --query 'Stacks[].StackStatus' $EXTRA_AWS_CLI_ARGS)
71+
if [ $STACK_STATUS != "CREATE_IN_PROGRESS" -a $STACK_STATUS != "CREATE_COMPLETE" ] ; then
6772
echo "error creating stack: "
6873
aws --output text cloudformation describe-stack-events \
6974
--stack-name $STACK_NAME \
70-
--query 'StackEvents[?ResourceStatus==`CREATE_FAILED`].[LogicalResourceId,ResourceStatusReason]'
75+
--query 'StackEvents[?ResourceStatus==`CREATE_FAILED`].[LogicalResourceId,ResourceStatusReason]' \
76+
$EXTRA_AWS_CLI_ARGS
7177
bailout
7278
exit 1
7379
fi
7480

7581
INSTANCE_IDS=$(aws ec2 describe-instances \
7682
--filters Name=tag:aws:cloudformation:stack-name,Values=$STACK_NAME Name=instance-state-name,Values=running \
7783
--query 'Reservations[].Instances[].[ InstanceId ]' \
78-
--output text)
84+
--output text \
85+
$EXTRA_AWS_CLI_ARGS)
7986

8087
echo "Waiting for instances to be provisioned ($STACK_STATUS, $(expr 61 - $COUNTER)0s) ..."
8188
sleep $SLEEPTIME
@@ -100,7 +107,8 @@ until [ `wc -w <<< $INSTANCE_STATUSES` -eq $DEIS_NUM_INSTANCES ]; do
100107
--filters Name=instance-status.reachability,Values=passed \
101108
--instance-ids $INSTANCE_IDS \
102109
--query 'InstanceStatuses[].[ InstanceId ]' \
103-
--output text)
110+
--output text \
111+
$EXTRA_AWS_CLI_ARGS)
104112
let COUNTER=COUNTER+1
105113
done
106114
@@ -109,20 +117,23 @@ echo "Instances are available:"
109117
aws ec2 describe-instances \
110118
--filters Name=tag:aws:cloudformation:stack-name,Values=$STACK_NAME Name=instance-state-name,Values=running \
111119
--query 'Reservations[].Instances[].[InstanceId,PublicIpAddress,InstanceType,Placement.AvailabilityZone,State.Name]' \
112-
--output text
120+
--output text \
121+
$EXTRA_AWS_CLI_ARGS
113122
114123
# get ELB public DNS name through cloudformation
115124
# TODO: is "first output value" going to be reliable enough?
116125
export ELB_DNS_NAME=$(aws cloudformation describe-stacks \
117126
--stack-name $STACK_NAME \
118127
--max-items 1 \
119128
--query 'Stacks[].[ Outputs[0].[ OutputValue ] ]' \
120-
--output=text)
129+
--output=text \
130+
$EXTRA_AWS_CLI_ARGS)
121131
122132
# get ELB friendly name through aws elb
123133
ELB_NAME=$(aws elb describe-load-balancers \
124134
--query 'LoadBalancerDescriptions[].[ DNSName,LoadBalancerName ]' \
125-
--output=text | grep -F $ELB_DNS_NAME | head -n1 | cut -f2)
135+
--output=text \
136+
$EXTRA_AWS_CLI_ARGS | grep -F $ELB_DNS_NAME | head -n1 | cut -f2)
126137
echo "Using ELB $ELB_NAME at $ELB_DNS_NAME"
127138
128139
echo_green "Your Deis cluster has been successfully deployed to AWS CloudFormation and is started."
@@ -131,7 +142,8 @@ echo_green "Please continue to follow the instructions in the documentation."
131142
FIRST_INSTANCE=$(aws ec2 describe-instances \
132143
--filters Name=tag:aws:cloudformation:stack-name,Values=$STACK_NAME Name=instance-state-name,Values=running \
133144
--query 'Reservations[].Instances[].[PublicIpAddress]' \
134-
--output text | head -1)
145+
--output text \
146+
$EXTRA_AWS_CLI_ARGS | head -1)
135147
export DEISCTL_TUNNEL=$FIRST_INSTANCE
136148
echo_green "Enabling proxy protocol"
137149

contrib/ec2/update-ec2-cluster.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,18 @@ if ! which aws > /dev/null; then
2323
exit 1
2424
fi
2525

26+
if [ ! -z "$AWS_CLI_PROFILE" ]; then
27+
EXTRA_AWS_CLI_ARGS+="--profile $AWS_CLI_PROFILE"
28+
fi
29+
2630
# check that the CoreOS user-data file is valid
2731
$CONTRIB_DIR/util/check-user-data.sh
2832

2933
# update the deis EC2 cloudformation
3034
aws cloudformation update-stack \
3135
--template-body "$($THIS_DIR/gen-json.py)" \
3236
--stack-name $NAME \
33-
--parameters "$(<$THIS_DIR/cloudformation.json)"
37+
--parameters "$(<$THIS_DIR/cloudformation.json)" \
38+
$EXTRA_AWS_CLI_ARGS
3439

3540
echo_green "Your Deis cluster on AWS CloudFormation has been successfully updated."

0 commit comments

Comments
 (0)