generated from terraform-modules/template_aws_submodules
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
63 additions
and
0 deletions.
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| #!/bin/bash | ||
|
|
||
| PROFILE=$1 | ||
| CLUSTER=$2 | ||
| REGION=$3 | ||
|
|
||
| if [ -z "$PROFILE" ] | ||
| then | ||
| PROFILE=$(grep -E '^\bprofile\b *' *tfvars| sed -e 's/^.*profile.* =//' -e 's/\"//g' -e 's/^ *//' | head -n 1) | ||
| fi | ||
| if [ -z "$PROFILE" ] | ||
| then | ||
| echo "* unable to determine profile, please pass as argument 1" | ||
| exit 1 | ||
| else | ||
| echo "* using profile $PROFILE" | ||
| fi | ||
|
|
||
| if [ -z "$CLUSTER" ] | ||
| then | ||
| CLUSTER=$(grep -E '^\bcluster_name\b *' settings.auto.tfvars| sed -e 's/^.*cluster_name.* =//' -e 's/\"//g' -e 's/^ *//' | head -n 1) | ||
| fi | ||
| if [ -z "$CLUSTER" ] | ||
| then | ||
| echo "* unable to determine cluster name, please pass as argument 2" | ||
| exit 1 | ||
| else | ||
| echo "* using cluster $CLUSTER" | ||
| fi | ||
|
|
||
| ADMINROLE=$(terraform output role_cluster-admin-role_arn) | ||
| if [ -z "$ADMINROLE" ] | ||
| then | ||
| echo "* unable to determine cluster $CLUSTER admin role. Check that you are in the correct directory an terraform has been run" | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [ -z "$REGION" ] | ||
| then | ||
| echo "* getting region from profile $PROFILE" | ||
| REGION=$(aws configure --profile $PROFILE get region) | ||
| else | ||
| echo "* using region $REGION" | ||
| fi | ||
|
|
||
| NEWPROFILE="$PROFILE-eks-$CLUSTER" | ||
| EXISTS=$(aws configure list-profiles | grep -c "^$NEWPROFILE$") | ||
|
|
||
| if [ $EXISTS == 0 ] | ||
| then | ||
| echo "* creating new configuration profile $NEWPROFILE for assume role $ADMINROLE" | ||
| else | ||
| echo "* replacing configuration for profile $NEWPROFILE for assume role $ADMINROLE" | ||
| fi | ||
| echo "" | ||
|
|
||
| ( echo "aws configure set profile.$NEWPROFILE.source_profile $PROFILE" ; \ | ||
| echo "aws configure set profile.$NEWPROFILE.region $REGION" ; \ | ||
| echo "aws configure set profile.$NEWPROFILE.role_arn $ADMINROLE" ; \ | ||
| echo "aws configure set profile.$NEWPROFILE.role_session_name $USER" ) | sh -x | ||
|
|
||
| echo "" | ||
| echo "* test with: aws --profile $NEWPROFILE sts get-caller-identity" |