Created
July 20, 2022 20:11
-
-
Save stfnhh/4bb82d5582a2351f5021246c92f4744c to your computer and use it in GitHub Desktop.
tf
This file contains hidden or 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
#!/usr/bin/env bash | |
main() { | |
local role_arn=$(aws --profile "$AWS_PROFILE" configure get role_arn) | |
if [[ $? != 0 || $role_arn == "" ]]; then | |
exec terraform "$@" | |
exit 0 | |
fi | |
credentials=($( | |
aws sts assume-role \ | |
--role-arn="${role_arn}" \ | |
--role-session-name="terraform-access" \ | |
--profile="$AWS_PROFILE" \ | |
--query "Credentials.[AccessKeyId,SecretAccessKey,SessionToken]" \ | |
--output text \ | |
| tr " " "\n" | |
)) | |
unset AWS_PROFILE | |
export AWS_ACCESS_KEY_ID=${credentials[0]} | |
export AWS_SECRET_ACCESS_KEY=${credentials[1]} | |
export AWS_SESSION_TOKEN=${credentials[2]} | |
exec terraform "$@" | |
} | |
main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment