Skip to content

Instantly share code, notes, and snippets.

@iamkirkbater
Last active December 18, 2023 15:34
Show Gist options
  • Save iamkirkbater/483414290089cb77769785a1e9c39a46 to your computer and use it in GitHub Desktop.
Save iamkirkbater/483414290089cb77769785a1e9c39a46 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -o pipefail
REGIONS=("us-east-1" "eu-west-1" "us-west-2" "us-east-2")
usage() {
cat <<EOF
usage: $0 [ OPTIONS ] --role [role-name]
Options
-a --account AWS Account to run this against
-d --dry-run Do not make any modifications but preview the expected operations
-h --help Show this message and exit
-p --profile AWS Payer Account Profile to use
-r --region Run against a single AWS Region
EOF
}
# Remove this if check if there is not a need for parameters to be passed in.
if [ $# -lt 2 ]; then
usage
exit 1
fi
export AWS_PAGER=''
AWS_PROFILE=
ACCOUNT=
while [ "$1" != "" ]; do
case $1 in
-a | --account ) shift
ACCOUNT="$1"
;;
-d | --dry-run ) DRY_RUN=true
;;
-h | --help ) usage
exit 1
;;
-p | --profile ) shift
AWS_PROFILE="$1"
;;
-r | --region ) shift
REGIONS=("$1")
;;
* ) echo "Unexpected parameter $1"
usage
exit 1
esac
shift
done
if [[ -z $ACCOUNT ]]; then
echo 'ERROR: Account must be set.'
usage
exit 1
fi
if [[ -z $AWS_PROFILE ]]; then
echo 'ERROR: AWS Profile must be set.'
usage
exit 1
fi
if [[ -z $REGIONS ]]; then
echo 'ERROR: Region must not be empty.'
usage
exit 1
fi
echo "Using profile $AWS_PROFILE"
creds=$(osdctl account cli -i $ACCOUNT -p $AWS_PROFILE -o env)
if [[ $? -ne 0 ]]; then
echo "Error assuming role in account."
exit 2
fi
export $creds
function request_increase {
SERVICECODE=$1
QUOTACODE=$2
AMOUNT=$3
if [[ -z $SERVICECODE ]]; then
echo "ERROR: Service Code must be provided"
exit 3
fi
if [[ -z $QUOTACODE ]]; then
echo "ERROR: Quota Code must be provided"
exit 3
fi
if [[ -z $AMOUNT ]]; then
echo "ERROR: Quota Amount must be provided"
exit 3
fi
quota=$(aws service-quotas get-service-quota --service-code $SERVICECODE --quota-code $QUOTACODE | jq .Quota)
quota_name=$(jq -r .QuotaName <<< $quota)
quota_value=$(jq -r .Value <<< $quota | awk '{print int($1)}')
echo " Getting usage for quota $quota_name"
if [[ $quota_value -lt $AMOUNT ]]; then
echo " $SERVICECODE/$QUOTACODE needs to be increased: $quota_value => $AMOUNT"
if [[ $DRY_RUN ]]; then
echo " DRY RUN: aws service-quotas request-service-quota-increase --service-code $SERVICECODE --quota-code $QUOTACODE --desired-value $AMOUNT"
else
aws service-quotas request-service-quota-increase --service-code $SERVICECODE --quota-code $QUOTACODE --desired-value $AMOUNT
echo " Increase Requested."
fi
else
echo " $SERVICECODE/$QUOTACODE is at or above request: $quota_value > $AMOUNT"
fi
echo
}
for region in "${REGIONS[@]}"; do
export AWS_REGION=$region
echo "Using Region: $region"
request_increase vpc L-0EA8095F 200
request_increase ec2 L-1216C47A 2500
request_increase elasticloadbalancing L-69A177A2 255
request_increase ec2 L-0263D0A3 6
request_increase ebs L-7A658B76 75
request_increase vpc L-2AEEBF1A 30
if [[ $region == "us-east-1" ]]; then
request_increase ec2 L-0263D0A3 10
fi
unset AWS_REGION
echo "=========="
done
@iamkirkbater
Copy link
Author

Adds newer quota increases and fixes issue with bash not liking AWS returning numbers with decimals (like 5.0 instead of 5)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment