File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 6060 with :
6161 role-to-assume : ${{ env.aws_role }}
6262 aws-region : eu-west-2
63+ - name : Update IAM policy
64+ run : |
65+ set -e
66+ ./../scripts/update-github-actions-policy.sh ${{ env.aws_role }} ../resources/github_actions_policy.json
6367 - name : Set image tag
6468 run : |
6569 IMAGE_TAG="${{ inputs.image_tag || github.sha }}"
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+
3+ if [ " $# " -ne 2 ]; then
4+ echo " Usage: $0 <policy-arn> <policy-file>"
5+ exit 1
6+ fi
7+
8+ POLICY_ARN=$1
9+ POLICY_FILE=$2
10+
11+ # Get existing policy versions
12+ EXISTING_VERSIONS=$( aws iam list-policy-versions --policy-arn " $POLICY_ARN " --query ' Versions[].VersionId' --output text)
13+
14+ # If there are 5 or more versions, delete the oldest one
15+ if [ " $( echo " $EXISTING_VERSIONS " | wc -w) " -ge 5 ]; then
16+ OLDEST_VERSION=$( echo " $EXISTING_VERSIONS " | awk ' {print $NF}' )
17+ echo " Deleting oldest version: $OLDEST_VERSION "
18+ aws iam delete-policy-version --policy-arn " $POLICY_ARN " --version-id " $OLDEST_VERSION "
19+ else
20+ echo " No need to delete any policy versions."
21+ fi
22+
23+ # Create a new version of the policy
24+ aws iam create-policy-version --policy-arn " $POLICY_ARN " --policy-document " file://$POLICY_FILE " --set-as-default
You can’t perform that action at this time.
0 commit comments