[installer] support AWS profiles
Use via `--profile=<profile_name>` or by setting `AWS_PROFILE` Fixes #1
This commit is contained in:
parent
363d36c004
commit
8b196480c2
20
bin/infra
20
bin/infra
|
@ -260,7 +260,12 @@ EOF
|
||||||
if [ -z "$region" ]; then
|
if [ -z "$region" ]; then
|
||||||
# Try to pull region from local config
|
# Try to pull region from local config
|
||||||
if [ -f "$HOME/.aws/config" ]; then
|
if [ -f "$HOME/.aws/config" ]; then
|
||||||
region=$(grep 'region' ~/.aws/config | sed -e 's/region = //')
|
if [ "$AWS_PROFILE" == "default" ]; then
|
||||||
|
region=$(awk '/\[default\]/{a=1;next}; /\[/{a=0}a' ~/.aws/config | grep 'region' | sed -e 's/region = //')
|
||||||
|
else
|
||||||
|
#shellcheck disable=SC1117
|
||||||
|
region=$(awk "/\[profile $AWS_PROFILE\]/{a=1;next}; /\[/{a=0}a" ~/.aws/config | grep 'region' | sed -e 's/region = //')
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
if [ -z "$region" ]; then
|
if [ -z "$region" ]; then
|
||||||
|
@ -378,10 +383,13 @@ VERBOSE=false
|
||||||
HELP=false
|
HELP=false
|
||||||
DRY_RUN=false
|
DRY_RUN=false
|
||||||
|
|
||||||
|
# Environment variables for Terraform
|
||||||
|
AWS_PROFILE="${AWS_PROFILE:-default}"
|
||||||
|
|
||||||
COMMAND=
|
COMMAND=
|
||||||
while [ "$1" != "" ]; do
|
while [ "$1" != "" ]; do
|
||||||
param=$(echo "$1" | sed -re 's/^([^=]*)=/\1/')
|
param=$(echo "$1" | sed -re 's/^([^=]*)=/\1/')
|
||||||
#val=$(echo "$1" | sed -e 's/^[^=]*=//g')
|
val=$(echo "$1" | sed -re 's/^([^=]*)=//')
|
||||||
case $param in
|
case $param in
|
||||||
-h | --help)
|
-h | --help)
|
||||||
HELP=true
|
HELP=true
|
||||||
|
@ -395,6 +403,9 @@ while [ "$1" != "" ]; do
|
||||||
--no-color)
|
--no-color)
|
||||||
disable_color
|
disable_color
|
||||||
;;
|
;;
|
||||||
|
--profile)
|
||||||
|
AWS_PROFILE="$val"
|
||||||
|
;;
|
||||||
--)
|
--)
|
||||||
shift
|
shift
|
||||||
break
|
break
|
||||||
|
@ -416,6 +427,11 @@ fi
|
||||||
# Set working directory to the project root
|
# Set working directory to the project root
|
||||||
cd "$(dirname "${BASH_SOURCE[0]}")/.."
|
cd "$(dirname "${BASH_SOURCE[0]}")/.."
|
||||||
|
|
||||||
|
# Export AWS_PROFILE if a non-default profile was chosen
|
||||||
|
if [ ! "$AWS_PROFILE" == "default" ]; then
|
||||||
|
export AWS_PROFILE
|
||||||
|
fi
|
||||||
|
|
||||||
# If cached prefix is in PREFIX file, then use it
|
# If cached prefix is in PREFIX file, then use it
|
||||||
if [ -f ./PREFIX ]; then
|
if [ -f ./PREFIX ]; then
|
||||||
INFRA_PREFIX=$(cat ./PREFIX)
|
INFRA_PREFIX=$(cat ./PREFIX)
|
||||||
|
|
Loading…
Reference in New Issue