Last active
November 1, 2017 17:01
-
-
Save pacohope/7e956a2ec3671fbd460803fd40efc38e to your computer and use it in GitHub Desktop.
Policy to Role listing. Given a CloudFormation in JSON that has ManagedPolicy objects connected to Roles, print a list of the policies and the roles that are attached.
This file contains 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
def mapper(f): | |
if type == "array" then map(f) | |
elif type == "object" then | |
. as $in | |
| reduce keys[] as $key | |
({}; | |
[$in[$key] | f ] as $value | |
| if $value | length == 0 then . else . + {($key): $value[0]} | |
end) | |
else . | |
end; | |
.Resources |= mapper(select(.Type=="AWS::IAM::ManagedPolicy")) | | |
.Resources | | |
keys[] as $k | | |
{"\(.[$k] | .Properties.Roles[]?.Ref?)":"\($k)"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example execution:
jq -c -f policy-role.jq IAMPolicies.json
Example output: