|
| 1 | +name: Update Lambda Permissions |
| 2 | +run-name: Updating permissions on ${{ inputs.environment }} using ${{ inputs.branch_name }} by ${{ github.actor }} |
| 3 | + |
| 4 | +on: |
| 5 | + workflow_dispatch: |
| 6 | + inputs: |
| 7 | + environment: |
| 8 | + description: Environment to deploy to |
| 9 | + required: true |
| 10 | + default: "dev" |
| 11 | + type: environment |
| 12 | + |
| 13 | + stack_name: |
| 14 | + description: Name of stack to apply permissions to |
| 15 | + required: true |
| 16 | + type: string |
| 17 | + |
| 18 | + branch_name: |
| 19 | + description: Branch to deploy |
| 20 | + required: true |
| 21 | + |
| 22 | +permissions: |
| 23 | + id-token: write |
| 24 | + contents: read |
| 25 | + actions: write |
| 26 | + |
| 27 | +jobs: |
| 28 | + build-permissions: |
| 29 | + name: Building permissions package for ${{ inputs.environment }} |
| 30 | + runs-on: [self-hosted, ci] |
| 31 | + environment: ${{ inputs.environment }} |
| 32 | + |
| 33 | + steps: |
| 34 | + - name: Git clone - ${{ github.ref }} |
| 35 | + uses: actions/checkout@v4 |
| 36 | + with: |
| 37 | + ref: ${{ github.ref }} |
| 38 | + |
| 39 | + - name: Setup asdf cache |
| 40 | + uses: actions/cache@v4 |
| 41 | + with: |
| 42 | + path: ~/.asdf |
| 43 | + key: ${{ runner.os }}-asdf-${{ hashFiles('**/.tool-versions') }} |
| 44 | + restore-keys: | |
| 45 | + ${{ runner.os }}-asdf- |
| 46 | +
|
| 47 | + - name: Install asdf |
| 48 | + uses: asdf-vm/actions/[email protected] |
| 49 | + |
| 50 | + - name: Install zip |
| 51 | + run: sudo apt-get install zip |
| 52 | + |
| 53 | + - name: Setup Python environment |
| 54 | + run: | |
| 55 | + poetry install --no-root |
| 56 | + source $(poetry env info --path)/bin/activate |
| 57 | +
|
| 58 | + - name: Configure Management Credentials |
| 59 | + uses: aws-actions/configure-aws-credentials@v4 |
| 60 | + with: |
| 61 | + aws-region: eu-west-2 |
| 62 | + role-to-assume: ${{ secrets.MGMT_ROLE_ARN }} |
| 63 | + role-session-name: github-actions-ci-${{ inputs.environment }}-${{ github.run_id }} |
| 64 | + |
| 65 | + - name: Create lambda permissions layer |
| 66 | + run: | |
| 67 | + account=$(echo '${{ inputs.environment }}' | cut -d '-' -f1) |
| 68 | + make get-s3-perms ENV=${account} TF_WORKSPACE_NAME=${{ inputs.stack_name }} |
| 69 | +
|
| 70 | + - name: Save NRLF permissions in cache |
| 71 | + uses: actions/cache/save@v4 |
| 72 | + with: |
| 73 | + key: ${{ github.run_id }}-nrlf-permissions |
| 74 | + path: dist/nrlf_permissions.zip |
| 75 | + |
| 76 | + apply-permissions: |
| 77 | + name: Applying permissions to ${{ inputs.environment }} |
| 78 | + runs-on: [self-hosted, ci] |
| 79 | + environment: ${{ inputs.environment }} |
| 80 | + |
| 81 | + needs: build-permissions |
| 82 | + |
| 83 | + steps: |
| 84 | + - name: Git clone - ${{ github.ref }} |
| 85 | + uses: actions/checkout@v4 |
| 86 | + with: |
| 87 | + ref: ${{ github.ref }} |
| 88 | + |
| 89 | + - name: Restore NRLF permissions cache |
| 90 | + uses: actions/cache/restore@v4 |
| 91 | + with: |
| 92 | + key: ${{ github.run_id }}-nrlf-permissions |
| 93 | + path: dist/nrlf_permissions.zip |
| 94 | + fail-on-cache-miss: true |
| 95 | + |
| 96 | + - name: Terraform Init |
| 97 | + run: | |
| 98 | + terraform -chdir=terraform/infrastructure init |
| 99 | + terraform -chdir=terraform/infrastructure workspace new ${{ inputs.stack_name }} || \ |
| 100 | + terraform -chdir=terraform/infrastructure workspace select ${{ inputs.stack_name }} |
| 101 | +
|
| 102 | + - name: Terraform Apply |
| 103 | + run: | |
| 104 | + terraform -chdir=terraform/infrastructure apply -auto-approve \ |
| 105 | + --var-file=etc/${{ vars.ACCOUNT_NAME }}.tfvars \ |
| 106 | + --var assume_role_arn=${{ secrets.DEPLOY_ROLE_ARN }} \ |
| 107 | + --var use_shared_resources=$(poetry run python scripts/are_resources_shared_for_stack.py ${{ inputs.stack_name }}) \ |
0 commit comments