File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3939 aws_role : ${{ inputs.environment == 'production'
4040 && 'arn:aws:iam::820242920762:role/GithubDeployMavisAndInfrastructure'
4141 || 'arn:aws:iam::393416225559:role/GithubDeployMavisAndInfrastructure' }}
42+ aws_account_id : ${{ inputs.environment == 'production'
43+ && '820242920762' || '393416225559' }}
4244
4345defaults :
4446 run :
6062 with :
6163 role-to-assume : ${{ env.aws_role }}
6264 aws-region : eu-west-2
65+ - name : Update IAM policy
66+ run : |
67+ set -e
68+ ./../scripts/update-github-actions-policy.sh arn:aws:iam::${{ env.aws_role }}:policy/DeployMavisResources ../resources/github_actions_policy.json
6369 - name : Set image tag
6470 run : |
6571 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