updated .envrc-aws

pull/2/head
Hari Sekhon 3 years ago
parent 3d9815c979
commit 410a62ed51

@ -1,10 +1,12 @@
#!/usr/bin/env bash
# vim:ts=4:sts=4:sw=4:et
#
# Author: Hari Sekhon
# Date: 2021-07-27 12:42:32 +0100 (Tue, 27 Jul 2021)
#
# vim:ts=4:sts=4:sw=4:et
#
# https://github.com/HariSekhon/bash-tools
# https://github.com/HariSekhon/DevOps-Bash-tools
#
# License: see accompanying Hari Sekhon LICENSE file
#
@ -14,21 +16,39 @@
#
set -euo pipefail
[ -n "${debug:-}" ] && set -x
#srcdir="$(dirname "${bash_source[0]}")"
[ -n "${DEBUG:-}" ] && set -x
srcdir="$(dirname "${BASH_SOURCE[0]}")"
# XXX: Edit
# XXX: Edit - crucial to set to the right environment, the rest of the inferred settings below depend on this
export AWS_PROFILE="default"
# XXX: Edit
export AWS_DEFAULT_REGION="eu-west-2"
AWS_ACCOUNT="$(aws sts get-caller-identity --query Account --output text || aws configure get sso_account_id || :)"
export AWS_ACCOUNT
AWS_DEFAULT_REGION="$(aws configure get region || :)" # use region configured in profile by default
AWS_DEFAULT_REGION="${AWS_DEFAULT_REGION:-eu-west-2}" # XXX: Edit default fallback region
export AWS_DEFAULT_REGION
export AWS_DEFAULT_OUTPUT=json
# XXX: Edit
export EKS_CONTEXT="MYCONTEXT"
export EKS_CLUSTER="mycluster"
# If EKS_CLUSTER isn't set and there is only one EKS cluster in this account and region, then use it - smart, but slower, prefer setting it explicitly for speed
if [ -z "${EKS_CLUSTER:-}" ]; then
eks_clusters=()
while IFS='' read -r line; do
eks_clusters+=("$line")
done < <(aws eks list-clusters --output=json | jq -r '.clusters[]')
if [ "${#eks_clusters[@]}" -eq 1 ]; then
export EKS_CLUSTER="${eks_clusters[*]}"
fi
fi
if [ -n "${EKS_CLUSTER:-}" ]; then
# kubectl context is easily created by running adjacent aws_kube_creds.sh script first
export EKS_CONTEXT="arn:aws:eks:$AWS_DEFAULT_REGION:$AWS_ACCOUNT:cluster/$EKS_CLUSTER"
# shellcheck disable=SC1090
. "$srcdir/.envrc-kubernetes" "$EKS_CONTEXT"
# shellcheck disable=SC1090
. "$srcdir/.envrc-kubernetes" "$EKS_CONTEXT"
fi
# better to load this dynamically from credentials, using functions in .bash.d/aws.sh
#export AWS_ACCESS_KEY_ID=...

Loading…
Cancel
Save