|
39 | 39 | aws_role: ${{ inputs.environment == 'production'
|
40 | 40 | && 'arn:aws:iam::820242920762:role/GithubDeployMavisAndInfrastructure'
|
41 | 41 | || 'arn:aws:iam::393416225559:role/GithubDeployMavisAndInfrastructure' }}
|
| 42 | + aws_account_id: ${{ inputs.environment == 'production' |
| 43 | + && '820242920762' || '393416225559' }} |
42 | 44 |
|
43 | 45 | defaults:
|
44 | 46 | run:
|
45 | 47 | working-directory: terraform/app
|
46 | 48 |
|
47 | 49 | jobs:
|
| 50 | + validate-permissions: |
| 51 | + name: Validate permissions |
| 52 | + 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 | + ../scripts/validate-github-actions-policy.sh arn:aws:iam::${{ env.aws_account_id }}:policy/DeployMavisResources ../resources/github_actions_policy.json |
| 71 | +
|
| 72 | + update-permissions: |
| 73 | + name: Update permissions |
| 74 | + runs-on: ubuntu-latest |
| 75 | + needs: validate-permissions |
| 76 | + if: inputs.environment == 'production' && needs.validate-permissions.outputs.policy-mismatch == 'true' |
| 77 | + environment: ${{ inputs.environment }} |
| 78 | + permissions: |
| 79 | + id-token: write |
| 80 | + steps: |
| 81 | + - name: Checkout code |
| 82 | + uses: actions/checkout@v4 |
| 83 | + with: |
| 84 | + ref: ${{ inputs.image_tag || github.sha }} |
| 85 | + - name: Configure AWS Credentials |
| 86 | + uses: aws-actions/configure-aws-credentials@v4 |
| 87 | + with: |
| 88 | + role-to-assume: ${{ env.aws_role }} |
| 89 | + aws-region: eu-west-2 |
| 90 | + - name: Update IAM policy |
| 91 | + run: | |
| 92 | + ../scripts/update-github-actions-policy.sh arn:aws:iam::${{ env.aws_account_id }}:policy/DeployMavisResources ../resources/github_actions_policy.json |
| 93 | +
|
48 | 94 | plan:
|
49 | 95 | name: Terraform plan
|
50 | 96 | runs-on: ubuntu-latest
|
| 97 | + needs: [validate-permissions, update-permissions] |
| 98 | + if: always() && (needs.validate-permissions.outputs.policy-mismatch != 'true' || needs.update-permissions.result == 'success') |
51 | 99 | permissions:
|
52 | 100 | id-token: write
|
53 | 101 | steps:
|
|
0 commit comments