Last active
July 22, 2022 10:29
-
-
Save z0ph/343bd73190ea0f014a0879780fb66186 to your computer and use it in GitHub Desktop.
Loop on put alternate contacts across AWS Org
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
#!/bin/bash | |
# https://awscli.amazonaws.com/v2/documentation/api/latest/reference/account/put-alternate-contact.html | |
# Parameters | |
SECURITY_EMAIL="[email protected]" | |
SECURITY_PHONE="" | |
SECURITY_TITLE="Owner" | |
SECURITY_NAME="Victor Grenu" | |
BILLING_EMAIL="[email protected]" | |
BILLING_PHONE="" | |
BILLING_TITLE="Owner" | |
BILLING_NAME="Victor Grenu" | |
OPERATIONS_EMAIL="[email protected]" | |
OPERATIONS_PHONE="" | |
OPERATIONS_TITLE="Owner" | |
OPERATIONS_NAME="Victor Grenu" | |
MANAGEMENT_ACCOUNT=$(aws organizations describe-organization --query Organization.MasterAccountId --output text) | |
for ACCOUNT in $(aws organizations list-accounts --query 'Accounts[].Id' --output text); do | |
if [ "$MANAGEMENT_ACCOUNT" -eq "$ACCOUNT" ]; then | |
echo 'Skipping management account.' | |
continue | |
fi | |
for TYPE in SECURITY BILLING OPERATIONS; do | |
EMAIL="${TYPE}_EMAIL" | |
PHONE="${TYPE}_PHONE" | |
TITLE="${TYPE}_TITLE" | |
NAME="${TYPE}_NAME" | |
echo 'Put '$TYPE' contact for account '$ACCOUNT'...' | |
#echo "aws account put-alternate-contact --account-id '$ACCOUNT' --alternate-contact-type='${TYPE}' --email-address='${!EMAIL}' --phone-number='${!PHONE}' --title='${!TITLE}' --name='${!NAME}'" | |
$(aws account put-alternate-contact --account-id $ACCOUNT --alternate-contact-type=${TYPE} --email-address=${!EMAIL} --phone-number=${!PHONE} --title=${!TITLE} --name="${!NAME}") | |
if [ $? -ne 1 ]; then | |
echo "Done putting '$TYPE' contact for account '$ACCOUNT'.'" | |
fi | |
done | |
sleep 0.2 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment