Skip to content

Commit 4f8f1ad

Browse files
authored
feat(gha): oidc aws credentials if AWS provider is used (#29)
GitHub Actions conditionally assume into the `masterpoint-testing` AWS account for native Terraform tests, ONLY if the AWS provider is used. Some of our modules, for example the Spacelift modules like terraform-spacelift-automation, only uses the Spacelift provider so there is no need to assume into the AWS role. But others such as Tailscale, in order to perform tests, AWS credentials are needed, even for unit tests (TF plans). <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Chores** - Updated workflow to automatically detect AWS provider usage and configure AWS credentials as needed during testing. - **New Features** - Added AWS provider to the Terraform configuration, enabling AWS resource management. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 1533346 commit 4f8f1ad

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

.github/workflows/lint.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ jobs:
1313
runs-on: ubuntu-latest
1414
steps:
1515
- name: Check out Git repository
16-
uses: actions/checkout@v4
16+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
1717
- name: Trunk Check
18-
uses: trunk-io/trunk-action@v1
18+
uses: trunk-io/trunk-action@4d5ecc89b2691705fd08c747c78652d2fc806a94 # v1.1.19

.github/workflows/test.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ permissions:
1313
id-token: write
1414
pull-requests: read
1515

16+
env:
17+
AWS_REGION: us-east-1
18+
1619
jobs:
1720
tf-test:
1821
name: 🧪 ${{ matrix.tf }} test
@@ -41,5 +44,26 @@ jobs:
4144
shell: bash
4245
run: aqua install --tags ${{ matrix.tf }}
4346

47+
- name: Check if TF AWS provider is used
48+
id: check_aws_provider
49+
run: |
50+
if grep -q "aws" $(find . -name "versions.tf" -o -name "versions.tofu" -type f); then
51+
echo "Found aws in versions.tf or versions.tofu files"
52+
echo "contains_hashicorp=true" >> $GITHUB_OUTPUT
53+
else
54+
echo "No versions.tf or versions.tofu files contain aws"
55+
echo "contains_hashicorp=false" >> $GITHUB_OUTPUT
56+
fi
57+
58+
# Assume into the `masterpoint-testing` AWS account with OIDC for testing ONLY if the AWS provider is used
59+
# Not needed for modules that don't use the AWS provider, for example, exclusive Spacelift modules
60+
- name: Configure AWS Credentials on `masterpoint-testing` AWS Account
61+
if: steps.check_aws_provider.outputs.contains_hashicorp == 'true'
62+
uses: aws-actions/configure-aws-credentials@ececac1a45f3b08a01d2dd070d28d111c5fe6722 # v4.1.0
63+
with:
64+
role-to-assume: arn:aws:iam::115843287071:role/mp-ue1-testing-oidc-github
65+
role-session-name: GitHubActionsOIDC-MP-Infra-Repo
66+
aws-region: ${{ env.AWS_REGION }}
67+
4468
- run: ${{ matrix.tf }} init
4569
- run: ${{ matrix.tf }} test

0 commit comments

Comments
 (0)