forked from HariSekhon/DevOps-Bash-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaws_iam_generate_credentials_report_wait.sh
executable file
·47 lines (42 loc) · 1.41 KB
/
aws_iam_generate_credentials_report_wait.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env bash
# vim:ts=4:sts=4:sw=4:et
#
# Author: Hari Sekhon
# Date: 2019-12-19 10:02:31 +0000 (Thu, 19 Dec 2019)
#
# https://github.com/harisekhon/bash-tools
#
# License: see accompanying Hari Sekhon LICENSE file
#
# If you're using my code you're welcome to connect with me on LinkedIn and optionally send me feedback to help steer this or other code I publish
#
# https://www.linkedin.com/in/harisekhon
#
# https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_getting-report.html
# Generates an AWS IAM credentials report and waits for it to finish
#
# Called from adjacent scripts as a dependency so that they can then pull specific information from the report
#
# Requires iam:GenerateCredentialReport on resource: *
#
# See more AWS tools in the DevOps Python Tools repo and The Advanced Nagios Plugins Collection:
#
# - https://github.com/harisekhon/devops-python-tools
# - https://github.com/harisekhon/nagios-plugins
set -euo pipefail
[ -n "${DEBUG:-}" ] && set -x
SECONDS=0
MAX_SECONDS=60
# you must run this to generate the report before you can get this info, seems to be ready a couple secs later
while true; do
if aws iam generate-credential-report |
jq -r .State |
tee /dev/stderr |
grep -q COMPLETE; then
break
fi
if [ $SECONDS -gt $MAX_SECONDS ]; then
echo "AWS IAM Credentials report failed to return complete within $MAX_SECONDS"
exit 1
fi
done