Skip to content

Commit

Permalink
Merge pull request #8529 from ministryofjustice/feature/conditional-r…
Browse files Browse the repository at this point in the history
…ole-switching

Add conditional OIDC role switching for Terraform plan and apply jobs
  • Loading branch information
sukeshreddyg authored Nov 19, 2024
2 parents 12567e9 + 8253789 commit 0eed362
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/reusable_terraform_plan_apply.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,18 @@ jobs:
echo ACCOUNT_NUMBER=$ACCOUNT_NUMBER >> $GITHUB_ENV
- name: configure aws credentials
if: github.event.ref != 'refs/heads/main'
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4.0.2
with:
role-to-assume: "arn:aws:iam::${{ env.ACCOUNT_NUMBER }}:role/github-actions-plan"
role-session-name: githubactionsrolesession
aws-region: ${{ inputs.aws_region }}

- name: configure aws credentials
if: github.event.ref == 'refs/heads/main'
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4.0.2
with:
role-to-assume: "arn:aws:iam::${{ env.ACCOUNT_NUMBER }}:role/github-actions"
role-to-assume: "arn:aws:iam::${{ env.ACCOUNT_NUMBER }}:role/github-actions-apply"
role-session-name: githubactionsrolesession
aws-region: ${{ inputs.aws_region }}

Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/scheduled-baseline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ jobs:
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4.0.2
with:
role-to-assume: "arn:aws:iam::${{ env.ACCOUNT_NUMBER }}:role/github-actions"
role-to-assume: "arn:aws:iam::${{ env.ACCOUNT_NUMBER }}:role/github-actions-apply"
role-session-name: githubactionsrolesession
aws-region: ${{ env.AWS_REGION }}
- uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3.1.2
Expand Down Expand Up @@ -189,7 +189,7 @@ jobs:
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4.0.2
with:
role-to-assume: "arn:aws:iam::${{ env.ACCOUNT_NUMBER }}:role/github-actions"
role-to-assume: "arn:aws:iam::${{ env.ACCOUNT_NUMBER }}:role/github-actions-apply"
role-session-name: githubactionsrolesession
aws-region: ${{ env.AWS_REGION }}
- uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3.1.2
Expand Down Expand Up @@ -241,7 +241,7 @@ jobs:
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4.0.2
with:
role-to-assume: "arn:aws:iam::${{ env.ACCOUNT_NUMBER }}:role/github-actions"
role-to-assume: "arn:aws:iam::${{ env.ACCOUNT_NUMBER }}:role/github-actions-apply"
role-session-name: githubactionsrolesession
aws-region: ${{ env.AWS_REGION }}
- uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3.1.2
Expand Down Expand Up @@ -294,7 +294,7 @@ jobs:
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4.0.2
with:
role-to-assume: "arn:aws:iam::${{ env.ACCOUNT_NUMBER }}:role/github-actions"
role-to-assume: "arn:aws:iam::${{ env.ACCOUNT_NUMBER }}:role/github-actions-apply"
role-session-name: githubactionsrolesession
aws-region: ${{ env.AWS_REGION }}
- name: Update permission sets
Expand Down

0 comments on commit 0eed362

Please sign in to comment.