|
| 1 | +name: TF Test |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + pull_request: |
| 8 | + |
| 9 | +permissions: |
| 10 | + actions: read |
| 11 | + checks: write |
| 12 | + contents: read |
| 13 | + id-token: write |
| 14 | + pull-requests: read |
| 15 | + |
| 16 | +env: |
| 17 | + AWS_REGION: us-east-1 |
| 18 | + |
| 19 | +jobs: |
| 20 | + tf-test: |
| 21 | + name: 🧪 ${{ matrix.tf }} test |
| 22 | + runs-on: ubuntu-latest |
| 23 | + strategy: |
| 24 | + matrix: |
| 25 | + tf: [tofu, terraform] |
| 26 | + steps: |
| 27 | + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 28 | + |
| 29 | + - name: Aqua Cache |
| 30 | + uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3 |
| 31 | + if: ${{ !github.event.act }} # Don't enable the cache step if we're using act for testing |
| 32 | + with: |
| 33 | + path: ~/.local/share/aquaproj-aqua |
| 34 | + key: v1-aqua-installer-${{runner.os}}-${{runner.arch}}-${{hashFiles('aqua.yaml')}} |
| 35 | + restore-keys: | |
| 36 | + v1-aqua-installer-${{runner.os}}-${{runner.arch}}- |
| 37 | +
|
| 38 | + - name: Install Aqua |
| 39 | + uses: aquaproj/aqua-installer@5e54e5cee8a95ee2ce7c04cb993da6dfad13e59c # v3.2.1 |
| 40 | + with: |
| 41 | + aqua_version: v2.48.1 |
| 42 | + |
| 43 | + - name: Aqua Install |
| 44 | + shell: bash |
| 45 | + run: aqua install --tags ${{ matrix.tf }} |
| 46 | + |
| 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 | + |
| 68 | + - run: ${{ matrix.tf }} init |
| 69 | + - run: ${{ matrix.tf }} test |
0 commit comments