Created
October 2, 2019 19:42
-
-
Save woneill/ef49add7fe6295493c7ef4be71d02fb5 to your computer and use it in GitHub Desktop.
This file contains 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 "external" "local_tools" { | |
program = ["sh", "-c", "${data.template_file.local_tools.rendered}"] | |
} | |
data "template_file" "local_tools" { | |
template = <<EOF | |
PATH="$PATH" | |
LOCAL_TOOLS_PATH="$(mktemp -d)" | |
platform="$(uname -s)" | |
case "$platform" in | |
Linux*) | |
AWS_URL="https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" | |
JQ_URL="https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64" | |
;; | |
Darwin*) | |
AWS_URL="https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" | |
JQ_URL="https://github.com/stedolan/jq/releases/download/jq-1.6/jq-osx-amd64" | |
;; | |
esac | |
>&2 echo Downloading aws | |
if ! which aws > /dev/null; then | |
curl -fL "$AWS_URL" -o "$LOCAL_TOOLS_PATH/awscli-bundle.zip" > /dev/stderr | |
if [ $? -ne 0 ]; then | |
>&2 echo "failed to $AWS_URL to $LOCAL_TOOLS_PATH/awscli-bundle.zip" | |
exit 1 | |
fi | |
unzip -o -d "$LOCAL_TOOLS_PATH" "$LOCAL_TOOLS_PATH/awscli-bundle.zip" > /dev/stderr | |
if [ $? -ne 0 ]; then | |
>&2 echo "failed to unzip $LOCAL_TOOLS_PATH/awscli-bundle.zip" | |
exit 1 | |
fi | |
$LOCAL_TOOLS_PATH/awscli-bundle/install -i "$LOCAL_TOOLS_PATH/.local/lib/aws" -b "$LOCAL_TOOLS_PATH/aws" > /dev/stderr | |
if [ $? -ne 0 ]; then | |
>&2 echo "failed to install awscli" | |
exit 1 | |
fi | |
fi | |
>&2 echo Downloading jq | |
if ! which jq > /dev/null; then | |
curl -fL "$JQ_URL" -o "$LOCAL_TOOLS_PATH/jq" > /dev/stderr | |
if [ $? -ne 0 ]; then | |
>&2 echo "failed to install jq" | |
exit 1 | |
else | |
chmod +x "$LOCAL_TOOLS_PATH/jq" | |
fi | |
fi | |
echo "{\"path\":\"$PATH:$LOCAL_TOOLS_PATH\"}" | |
EOF | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment