From 86b1ef4d99ddc1f2b5e1445167e275ebf6034e46 Mon Sep 17 00:00:00 2001 From: David Arnold <10138997+djaboxx@users.noreply.github.com> Date: Tue, 25 Mar 2025 09:03:29 -0700 Subject: [PATCH 1/6] Update terraform-test.yml --- .github/workflows/terraform-test.yml | 99 ++++------------------------ 1 file changed, 14 insertions(+), 85 deletions(-) diff --git a/.github/workflows/terraform-test.yml b/.github/workflows/terraform-test.yml index af5d0ab..7cbedd7 100644 --- a/.github/workflows/terraform-test.yml +++ b/.github/workflows/terraform-test.yml @@ -1,99 +1,28 @@ -name: "Terraform Test and Tag" - +name: Terraform CI/CD on: - push: - branches: - - main pull_request: + types: [closed] branches: - main - workflow_dispatch: - -# Set concurrency to prevent overlapping workflow runs -concurrency: - group: ${{ github.workflow }} - cancel-in-progress: false - -permissions: - contents: write - pull-requests: write - jobs: - terraform: - name: "Terraform Test" + terraform-ci-cd: + if: github.event.pull_request.merged == true runs-on: ubuntu-latest - env: - GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} - GITHUB_OWNER: ${{ vars.GH_ORG }} + permissions: + contents: write steps: - - name: Checkout - uses: actions/checkout@v4 + - uses: actions/checkout@v3 with: fetch-depth: 0 - + - name: Setup Terraform uses: hashicorp/setup-terraform@v3 with: - terraform_version: "~>1.6.0" - terraform_wrapper: false - - - name: Format Terraform files - run: terraform fmt -recursive - id: fmt + terraform_version: "1.10.5" # Specify your desired version - - name: Check for file changes - id: check_changes - run: | - if [ -n "$(git status --porcelain)" ]; then - echo "changes_detected=true" >> $GITHUB_ENV - else - echo "changes_detected=false" >> $GITHUB_ENV - fi - - - name: Commit and push changes - if: env.changes_detected == 'true' - run: | - git config --global user.name 'github-actions[bot]' - git config --global user.email 'github-actions[bot]@users.noreply.github.com' - git add . - git commit -m "chore: format terraform files" - - # For push events on main branch, create a PR instead of pushing directly - if [[ "${{ github.event_name }}" == "push" && "${{ github.ref }}" == "refs/heads/main" ]]; then - # Create a new branch for the formatting changes - BRANCH_NAME="format-terraform-$(date +%Y%m%d%H%M%S)" - git checkout -b $BRANCH_NAME - git push -u origin $BRANCH_NAME - - # Create a pull request using the GitHub CLI or API - gh pr create --title "chore: format terraform files" \ - --body "This PR contains automatic formatting changes from the CI workflow." \ - --head $BRANCH_NAME \ - --base main - elif [[ "${{ github.event_name }}" == "pull_request" && "${{ github.event.pull_request.head.repo.fork }}" == "false" ]]; then - # Only push to the PR branch if it's from the same repository (not a fork) - git push origin "HEAD:${{ github.event.pull_request.head.ref }}" - else - echo "Changes detected but not pushing to a fork PR. Please update your PR with these formatting changes." - fi - - - name: Terraform Init - id: init - run: terraform init -backend=false - - - name: Terraform Validate - id: validate - run: terraform validate - - - name: Run Terraform Tests - id: test - run: terraform test - - - name: Bump version and push tag - if: github.event_name == 'push' && github.ref == 'refs/heads/main' - uses: anothrNick/github-tag-action@1.67.0 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - DEFAULT_BUMP: patch - WITH_V: true + - name: Run Terraform Module Release Action + uses: HappyPathway/terraform-module-release@main + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + working-directory: '.' From d0d399799f6d15239b55b1d15d8ccb460fedbec8 Mon Sep 17 00:00:00 2001 From: David Arnold <10138997+djaboxx@users.noreply.github.com> Date: Tue, 25 Mar 2025 09:06:42 -0700 Subject: [PATCH 2/6] Major: Update terraform-test.yml (#15) From ebbcf27694e6fa43153eede8de174426c86fc1b1 Mon Sep 17 00:00:00 2001 From: David Arnold <10138997+djaboxx@users.noreply.github.com> Date: Tue, 25 Mar 2025 09:09:33 -0700 Subject: [PATCH 3/6] Major: Update terraform-test.yml (#16) --- .github/workflows/terraform-test.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/terraform-test.yml b/.github/workflows/terraform-test.yml index 7cbedd7..1686de2 100644 --- a/.github/workflows/terraform-test.yml +++ b/.github/workflows/terraform-test.yml @@ -24,5 +24,7 @@ jobs: - name: Run Terraform Module Release Action uses: HappyPathway/terraform-module-release@main with: - github-token: ${{ secrets.GITHUB_TOKEN }} + github-token: ${{ secrets.GH_TOKEN }} working-directory: '.' + env: + GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} From 89b0ddeec44fce0fe97bfb771719b360d817561e Mon Sep 17 00:00:00 2001 From: David Arnold <10138997+djaboxx@users.noreply.github.com> Date: Tue, 25 Mar 2025 09:11:32 -0700 Subject: [PATCH 4/6] Major: Update terraform-test.yml (#17) --- .github/workflows/terraform-test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/terraform-test.yml b/.github/workflows/terraform-test.yml index 1686de2..845fe0b 100644 --- a/.github/workflows/terraform-test.yml +++ b/.github/workflows/terraform-test.yml @@ -28,3 +28,4 @@ jobs: working-directory: '.' env: GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} + GITHUB_OWNER: ${{ vars.GH_ORG }} From 497ec3e75a656235470bfa7379c5d1fb63fc35e0 Mon Sep 17 00:00:00 2001 From: David Arnold <10138997+djaboxx@users.noreply.github.com> Date: Tue, 25 Mar 2025 09:28:57 -0700 Subject: [PATCH 5/6] Update terraform-test.yml (#18) From e3373b571455276d98fc951dc7533aa8c194f1bc Mon Sep 17 00:00:00 2001 From: David Arnold <10138997+djaboxx@users.noreply.github.com> Date: Tue, 25 Mar 2025 09:33:04 -0700 Subject: [PATCH 6/6] Major: Update data.tf (#19)