Skip to content

Instantly share code, notes, and snippets.

@z0ph
Last active July 22, 2022 10:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save z0ph/343bd73190ea0f014a0879780fb66186 to your computer and use it in GitHub Desktop.
Save z0ph/343bd73190ea0f014a0879780fb66186 to your computer and use it in GitHub Desktop.
Loop on put alternate contacts across AWS Org
#!/bin/bash
# https://awscli.amazonaws.com/v2/documentation/api/latest/reference/account/put-alternate-contact.html
# Parameters
SECURITY_EMAIL="victor@zoph.io"
SECURITY_PHONE=""
SECURITY_TITLE="Owner"
SECURITY_NAME="Victor Grenu"
BILLING_EMAIL="victor@zoph.io"
BILLING_PHONE=""
BILLING_TITLE="Owner"
BILLING_NAME="Victor Grenu"
OPERATIONS_EMAIL="victor@zoph.io"
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