Skip to content

Commit

Permalink
adding awscli
Browse files Browse the repository at this point in the history
  • Loading branch information
Renatovnctavares committed Aug 6, 2019
1 parent ee9aad5 commit 4b5eb63
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 5 deletions.
22 changes: 17 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FROM alpine:3.7

ENV TERRAFORM_VERSION=0.11.13
ENV AWSCLI_VERSION=1.16.169

VOLUME ["/work"]

Expand All @@ -10,11 +11,22 @@ RUN apk update && \
apk add bash ca-certificates git openssl unzip wget make && \
cd /tmp && \
wget https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip && \
unzip terraform_${TERRAFORM_VERSION}_linux_amd64.zip -d /usr/bin && \
rm -rf /tmp/* && \
rm -rf /var/cache/apk/* && \
rm -rf /var/tmp/*
unzip terraform_${TERRAFORM_VERSION}_linux_amd64.zip -d /usr/bin


RUN apk --no-cache add python py-pip py-setuptools groff less jq gettext-dev curl wget g++ zip && \
pip --no-cache-dir install awscli==$AWSCLI_VERSION && \
update-ca-certificates && \
rm -rf /var/tmp/ && \
rm -rf /tmp/* && \
rm -rf /var/cache/apk/*

COPY scripts /opt/scripts
RUN chmod 777 /opt/scripts/*
ENV PATH "$PATH:/opt/scripts"

ENTRYPOINT [ "terraform" ]

CMD [ "version" ]

CMD [ "--version" ]

26 changes: 26 additions & 0 deletions scripts/assume-role.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

DURATION="${AWS_ROLE_DURATION:-3600}"
SESSION_NAME="${AWS_ROLE_SESSION_NAME:-`date +%s`}"
EXPORT="${EXPORT:-no}"

# KST=access*K*ey, *S*ecretkey, session*T*oken
KST=(`aws sts assume-role --role-arn "arn:aws:iam::$AWS_ACCOUNT_ID:role/$AWS_ROLE" \
--role-session-name "$SESSION_NAME" \
--duration-seconds $DURATION \
--query '[Credentials.AccessKeyId,Credentials.SecretAccessKey,Credentials.SessionToken]' \
--output text`)

if [ "$EXPORT" == "yes" ]; then
echo ""
echo "export AWS_ACCESS_KEY_ID=${KST[0]}"
echo "export AWS_SECRET_ACCESS_KEY=${KST[1]}"
echo "export AWS_SESSION_TOKEN=${KST[2]}"
echo "export AWS_SECURITY_TOKEN=${KST[2]}"
else
echo ""
echo "AWS_ACCESS_KEY_ID=${KST[0]}"
echo "AWS_SECRET_ACCESS_KEY=${KST[1]}"
echo "AWS_SESSION_TOKEN=${KST[2]}"
echo "AWS_SECURITY_TOKEN=${KST[2]}"
fi

0 comments on commit 4b5eb63

Please sign in to comment.