From 8610af5ff6129f401f7c7655600d546be9cd57a8 Mon Sep 17 00:00:00 2001 From: j4y <36337+j4y@users.noreply.github.com> Date: Mon, 3 Nov 2025 22:48:42 -0500 Subject: [PATCH] chore: update to use gruntwork-io/terragrunt-action to run terraform --- .github/workflows/deploy.yml | 75 +++++++++++++++++++++--------------- mise.toml | 2 + 2 files changed, 46 insertions(+), 31 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 7fae2f7..d781c3c 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -2,64 +2,77 @@ name: Deploy on: push: - branches: [ main, master ] + branches: + - main + # branches that match deploy-* will deploy as well + - deploy-* workflow_dispatch: env: AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} AWS_DEFAULT_REGION: us-east-1 - TG_WORKING_DIR: terragrunt/live/website + working_dir: terragrunt/live/website concurrency: group: ${{ github.workflow }} jobs: - build: + deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v5 - - name: Set up Ruby - uses: ruby/setup-ruby@v1 + - name: Update Terraform State and Providers + uses: gruntwork-io/terragrunt-action@v3 + # env: + # TF_LOG: DEBUG + # INPUT_PRE_EXEC_1: | + # echo "Current directory: $(pwd)" + # ls -la + # git status with: - bundler-cache: true + tg_dir: ${{ env.working_dir }} + tg_command: init --upgrade - - name: Setup Terraform - uses: hashicorp/setup-terraform@v3.1.2 + - name: Terragrunt Plan + uses: gruntwork-io/terragrunt-action@v3 with: - terraform_version: 1.13.4 - terraform_wrapper: true + tg_dir: ${{ env.working_dir }} + tg_command: plan - - name: Setup Terragrunt - uses: autero1/action-terragrunt@v3.0.2 + - name: Terragrunt Apply + uses: gruntwork-io/terragrunt-action@v3 with: - terragrunt-version: 0.86.0 - token: ${{ secrets.GITHUB_TOKEN }} + tg_dir: ${{ env.working_dir }} + tg_command: apply - - name: Update Terraform State and Providers - run: | - cd "$TG_WORKING_DIR" - terragrunt init --upgrade + # - name: Terragrunt Output + # uses: gruntwork-io/terragrunt-action@v3 + # env: + # TG_TF_FORWARD_STDOUT: 1 + # TG_NO_COLOR: 1 + # with: + # tg_dir: ${{ env.working_dir }} + # tg_command: output - - name: Terragrunt Plan - run: terragrunt plan --chdir $TG_WORKING_DIR - - - name: Terragrunt Apply - run: terragrunt apply -auto-approve --chdir $TG_WORKING_DIR - - - name: Terragrunt Output - id: terraform + - name: Read Values + id: terragrunt_output run: | - printf "distribution_id=%s\n" $(terragrunt output --chdir $TG_WORKING_DIR distribution_id) >> "$GITHUB_OUTPUT" - printf "bucket_name=%s\n" $(terragrunt output --chdir $TG_WORKING_DIR bucket_name) >> "$GITHUB_OUTPUT" + cd terragrunt/live/website + printf "distribution_id=%s\n" $(terragrunt output distribution_id) >> "$GITHUB_OUTPUT" + printf "bucket_name=%s\n" $(terragrunt output bucket_name) >> "$GITHUB_OUTPUT" - name: Build Jekyll project - run: bundle exec rake build + run: | + bundle install + bundle exec rake build + + # TODO: fail workflow if bucket name or distribution_id is not found - name: Copy output to S3 - run: aws s3 sync ./_site/ s3://${{ steps.terraform.outputs.bucket_name }} --acl public-read --delete --cache-control max-age=604800 + run: aws s3 sync ./_site/ s3://${{ steps.terragrunt_output.outputs.bucket_name }} --acl public-read --delete --cache-control max-age=604800 - name: Invalidate Cloudfront - run: aws cloudfront create-invalidation --distribution-id ${{ steps.terraform.outputs.distribution_id }} --paths "/*" + run: aws cloudfront create-invalidation --distribution-id ${{ steps.terragrunt_output.outputs.distribution_id }} --paths "/*" diff --git a/mise.toml b/mise.toml index 0a61537..573def9 100644 --- a/mise.toml +++ b/mise.toml @@ -1,2 +1,4 @@ [tools] ruby = '3.3.9' +terragrunt = '0.86.0' +opentofu = '1.6.2'