@@ -47,9 +47,43 @@ defaults:
4747 working-directory : terraform/app
4848
4949jobs :
50- plan :
51- name : Terraform plan
50+ validate-permissions :
51+ name : Validate permissions
5252 runs-on : ubuntu-latest
53+ permissions :
54+ id-token : write
55+ outputs :
56+ policy-mismatch : ${{ steps.compare-permissions.outputs.policy_mismatch }}
57+ steps :
58+ - name : Checkout code
59+ uses : actions/checkout@v4
60+ with :
61+ ref : ${{ inputs.image_tag || github.sha }}
62+ - name : Configure AWS Credentials
63+ uses : aws-actions/configure-aws-credentials@v4
64+ with :
65+ role-to-assume : ${{ env.aws_role }}
66+ aws-region : eu-west-2
67+ - name : Compare permissions
68+ id : compare-permissions
69+ run : |
70+ VERSION_ID=$(aws iam get-policy --policy-arn arn:aws:iam::393416225559:policy/DeployMavisResources --query 'Policy.DefaultVersionId' --output text)
71+ DEPLOYED_POLICY=$(aws iam get-policy-version --policy-arn arn:aws:iam::393416225559:policy/DeployMavisResources --version-id $VERSION_ID --query 'PolicyVersion.Document' --output json)
72+
73+ POLICY_DIFF=$(diff <(echo "$DEPLOYED_VERSION" | jq --sort-keys .) <(jq --sort-keys . ../github_actions_policy.json))
74+ if [ -n "$POLICY_DIFF" ]; then
75+ echo "Policy mismatch detected"
76+ echo "policy_mismatch=true" >> $GITHUB_OUTPUT
77+ else
78+ echo "No policy mismatch detected"
79+ fi
80+
81+ update-permissions :
82+ name : Update permissions
83+ runs-on : ubuntu-latest
84+ needs : validate-permissions
85+ if : inputs.environment == 'sandbox-alpha' && needs.validate-permissions.outputs.policy-mismatch == 'true'
86+ environment : ${{ inputs.environment }}
5387 permissions :
5488 id-token : write
5589 steps :
@@ -66,6 +100,23 @@ jobs:
66100 run : |
67101 set -e
68102 ./../scripts/update-github-actions-policy.sh arn:aws:iam::${{ env.aws_role }}:policy/DeployMavisResources ../resources/github_actions_policy.json
103+
104+ plan :
105+ name : Terraform plan
106+ runs-on : ubuntu-latest
107+ needs : update-permissions
108+ permissions :
109+ id-token : write
110+ steps :
111+ - name : Checkout code
112+ uses : actions/checkout@v4
113+ with :
114+ ref : ${{ inputs.image_tag || github.sha }}
115+ - name : Configure AWS Credentials
116+ uses : aws-actions/configure-aws-credentials@v4
117+ with :
118+ role-to-assume : ${{ env.aws_role }}
119+ aws-region : eu-west-2
69120 - name : Set image tag
70121 run : |
71122 IMAGE_TAG="${{ inputs.image_tag || github.sha }}"
0 commit comments