From d6b56e8086697212f073fd099c21912dad80823a Mon Sep 17 00:00:00 2001 From: Jun-te Kim Date: Sat, 6 Dec 2025 15:05:29 +0000 Subject: [PATCH 01/22] plan work? --- .github/workflows/terraform-plan.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/terraform-plan.yml b/.github/workflows/terraform-plan.yml index 924c1c9..2d5fe35 100644 --- a/.github/workflows/terraform-plan.yml +++ b/.github/workflows/terraform-plan.yml @@ -81,3 +81,4 @@ jobs: - name: Print TF_VAR_public_ip run: 'echo "📡 Public IP used by Terraform: $TF_VAR_public_ip"' + From 6bfe24d05455346f1c2f237d5e5894946d8190ac Mon Sep 17 00:00:00 2001 From: Jun-te Kim Date: Sat, 6 Dec 2025 15:07:00 +0000 Subject: [PATCH 02/22] plan work? --- .github/workflows/terraform-apply.yml | 2 +- .github/workflows/terraform-plan.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/terraform-apply.yml b/.github/workflows/terraform-apply.yml index ff2a792..6da5d5a 100644 --- a/.github/workflows/terraform-apply.yml +++ b/.github/workflows/terraform-apply.yml @@ -16,7 +16,7 @@ jobs: terraform: if: github.repository != 'hashicorp-education/learn-terraform-github-actions' name: "Terraform Apply" - runs-on: ubuntu-latest + runs-on: mealcraft-runners permissions: contents: read steps: diff --git a/.github/workflows/terraform-plan.yml b/.github/workflows/terraform-plan.yml index 2d5fe35..089d930 100644 --- a/.github/workflows/terraform-plan.yml +++ b/.github/workflows/terraform-plan.yml @@ -14,7 +14,7 @@ jobs: terraform: if: github.repository != 'hashicorp-education/learn-terraform-github-actions' name: "Terraform Plan" - runs-on: ubuntu-latest + runs-on: mealcraft-runners permissions: contents: read pull-requests: write From 6b7d2b5215415c51bd0d1e670004c2253cee86ba Mon Sep 17 00:00:00 2001 From: Jun-te Kim Date: Sat, 6 Dec 2025 16:02:15 +0000 Subject: [PATCH 03/22] save current --- .devcontainer/Dockerfile | 2 ++ github_runner/install/install_arc.sh | 36 +++++++++++++++------------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index d156577..7a0c0ed 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,4 +1,6 @@ FROM library/python:3.12-bullseye +# Personal access token 'mist _runner' +ENV GITHUB_PAT=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 ARG USER=vscode ARG DEBIAN_FRONTEND=noninteractive diff --git a/github_runner/install/install_arc.sh b/github_runner/install/install_arc.sh index e95c1c7..07c499b 100644 --- a/github_runner/install/install_arc.sh +++ b/github_runner/install/install_arc.sh @@ -1,29 +1,33 @@ -#!/bin/bash -set -e +# # !/bin/bash +# set -ex -echo "=== Enable MicroK8s features ===" -sudo microk8s enable dns rbac hostpath-storage host-access -sudo microk8s enable metrics-server +# echo "=== Enable MicroK8s features ===" +# sudo microk8s enable dns rbac hostpath-storage host-access +# sudo microk8s enable metrics-server -echo "=== Configure kubectl for MicroK8s ===" -microk8s kubectl config view --raw > ~/.kube/config -chmod 600 ~/.kube/config -sudo usermod -aG microk8s $USER -sudo chown -f -R $USER ~/.kube -newgrp microk8s +# echo "=== Configure kubectl for MicroK8s ===" +# microk8s kubectl config view --raw > ~/.kube/config +# chmod 600 ~/.kube/config +# sudo usermod -aG microk8s $USER +# sudo chown -f -R $USER ~/.kube -echo "=== Install Scale Set ARC Controller ===" -helm install arc \ - --namespace arc-systems \ - --create-namespace \ - oci://ghcr.io/actions/actions-runner-controller-charts/gha-runner-scale-set-controller +# echo "=== Install Scale Set ARC Controller ===" +# helm install arc \ +# --namespace arc-systems \ +# --create-namespace \ +# oci://ghcr.io/actions/actions-runner-controller-charts/gha-runner-scale-set-controller echo "=== Install MealCraft Runner Scale Set ===" helm install mealcraft-runners \ --namespace arc-systems \ + --set containerMode.type=kubernetes \ + --set containerMode.kubernetesModeWorkVolumeClaim.accessModes[0]=ReadWriteOnce \ + --set containerMode.kubernetesModeWorkVolumeClaim.storageClassName=microk8s-hostpath \ + --set containerMode.kubernetesModeWorkVolumeClaim.resources.requests.storage=1Gi \ --set githubConfigUrl=https://github.com/MealCraft \ --set githubConfigSecret.github_token=$GITHUB_PAT \ oci://ghcr.io/actions/actions-runner-controller-charts/gha-runner-scale-set + echo "=== ARC installation complete ===" From b92a0d2993fa44be4ab779f36d012bbbaeb54dee Mon Sep 17 00:00:00 2001 From: Jun-te Kim Date: Sat, 6 Dec 2025 16:05:25 +0000 Subject: [PATCH 04/22] added container" --- .github/workflows/test-autoscaling.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/test-autoscaling.yml b/.github/workflows/test-autoscaling.yml index 138f6cb..ceb23d3 100644 --- a/.github/workflows/test-autoscaling.yml +++ b/.github/workflows/test-autoscaling.yml @@ -6,6 +6,8 @@ on: jobs: load-test: runs-on: mealcraft-runners + container: + image: ubuntu:22.04 strategy: matrix: job_id: [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20] From f382a90709ec96d8e18733b612b55d2d0202aa12 Mon Sep 17 00:00:00 2001 From: Jun-te Kim Date: Sat, 6 Dec 2025 16:18:27 +0000 Subject: [PATCH 05/22] save install arch --- github_runner/install/install_arc.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/github_runner/install/install_arc.sh b/github_runner/install/install_arc.sh index 07c499b..676b8b8 100644 --- a/github_runner/install/install_arc.sh +++ b/github_runner/install/install_arc.sh @@ -12,21 +12,21 @@ # sudo usermod -aG microk8s $USER # sudo chown -f -R $USER ~/.kube -# echo "=== Install Scale Set ARC Controller ===" -# helm install arc \ -# --namespace arc-systems \ -# --create-namespace \ -# oci://ghcr.io/actions/actions-runner-controller-charts/gha-runner-scale-set-controller +echo "=== Install Scale Set ARC Controller ===" +helm install arc \ + --namespace arc-systems \ + --create-namespace \ + oci://ghcr.io/actions/actions-runner-controller-charts/gha-runner-scale-set-controller echo "=== Install MealCraft Runner Scale Set ===" helm install mealcraft-runners \ --namespace arc-systems \ - --set containerMode.type=kubernetes \ --set containerMode.kubernetesModeWorkVolumeClaim.accessModes[0]=ReadWriteOnce \ --set containerMode.kubernetesModeWorkVolumeClaim.storageClassName=microk8s-hostpath \ --set containerMode.kubernetesModeWorkVolumeClaim.resources.requests.storage=1Gi \ --set githubConfigUrl=https://github.com/MealCraft \ --set githubConfigSecret.github_token=$GITHUB_PAT \ + --set containerMode.type=dind \ oci://ghcr.io/actions/actions-runner-controller-charts/gha-runner-scale-set From af7ddf9661593ae597b0af325a1070cd26545a89 Mon Sep 17 00:00:00 2001 From: Jun-te Kim Date: Sat, 6 Dec 2025 16:31:27 +0000 Subject: [PATCH 06/22] it just works --- github_runner/install/install_arc.sh | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/github_runner/install/install_arc.sh b/github_runner/install/install_arc.sh index 676b8b8..851167b 100644 --- a/github_runner/install/install_arc.sh +++ b/github_runner/install/install_arc.sh @@ -12,21 +12,29 @@ # sudo usermod -aG microk8s $USER # sudo chown -f -R $USER ~/.kube + +# if you need to uninstall first +helm uninstall arc -n arc-systems echo "=== Install Scale Set ARC Controller ===" helm install arc \ --namespace arc-systems \ --create-namespace \ oci://ghcr.io/actions/actions-runner-controller-charts/gha-runner-scale-set-controller +helm uninstall mealcraft-runners -n arc-systems + echo "=== Install MealCraft Runner Scale Set ===" helm install mealcraft-runners \ --namespace arc-systems \ + --set runnerScaleSetName=mealcraft-runners \ + --set runnerLabels[0]=mealcraft-runners \ + --set githubConfigUrl=https://github.com/MealCraft \ + --set githubConfigSecret.github_token=$GITHUB_PAT \ + --set githubConfigSecret.name=github-secret \ + --set containerMode.type=kubernetes \ --set containerMode.kubernetesModeWorkVolumeClaim.accessModes[0]=ReadWriteOnce \ --set containerMode.kubernetesModeWorkVolumeClaim.storageClassName=microk8s-hostpath \ --set containerMode.kubernetesModeWorkVolumeClaim.resources.requests.storage=1Gi \ - --set githubConfigUrl=https://github.com/MealCraft \ - --set githubConfigSecret.github_token=$GITHUB_PAT \ - --set containerMode.type=dind \ oci://ghcr.io/actions/actions-runner-controller-charts/gha-runner-scale-set From 19575092253c0124154d20c18017041a180e6a68 Mon Sep 17 00:00:00 2001 From: Jun-te Kim Date: Sat, 6 Dec 2025 16:35:38 +0000 Subject: [PATCH 07/22] it just works --- github_runner/install/install_arc.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/github_runner/install/install_arc.sh b/github_runner/install/install_arc.sh index 851167b..fe0ee9f 100644 --- a/github_runner/install/install_arc.sh +++ b/github_runner/install/install_arc.sh @@ -35,6 +35,7 @@ helm install mealcraft-runners \ --set containerMode.kubernetesModeWorkVolumeClaim.accessModes[0]=ReadWriteOnce \ --set containerMode.kubernetesModeWorkVolumeClaim.storageClassName=microk8s-hostpath \ --set containerMode.kubernetesModeWorkVolumeClaim.resources.requests.storage=1Gi \ + --set defaultContainer.image=ubuntu:22.04 \ oci://ghcr.io/actions/actions-runner-controller-charts/gha-runner-scale-set From 11b8018de93270a026afb1a1d68c2579909b6795 Mon Sep 17 00:00:00 2001 From: Jun-te Kim Date: Sat, 6 Dec 2025 16:43:12 +0000 Subject: [PATCH 08/22] it just works --- .github/workflows/test-autoscaling.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/test-autoscaling.yml b/.github/workflows/test-autoscaling.yml index ceb23d3..138f6cb 100644 --- a/.github/workflows/test-autoscaling.yml +++ b/.github/workflows/test-autoscaling.yml @@ -6,8 +6,6 @@ on: jobs: load-test: runs-on: mealcraft-runners - container: - image: ubuntu:22.04 strategy: matrix: job_id: [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20] From 911a35b079fd7a2086d9d9c8294557132b4bedf7 Mon Sep 17 00:00:00 2001 From: Jun-te Kim Date: Sat, 6 Dec 2025 16:49:41 +0000 Subject: [PATCH 09/22] it just works --- .github/workflows/terraform-apply.yml | 1 + .github/workflows/terraform-plan.yml | 1 + .github/workflows/test-autoscaling.yml | 1 + github_runner/install/install_arc.sh | 7 +++---- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/terraform-apply.yml b/.github/workflows/terraform-apply.yml index 6da5d5a..b1686f5 100644 --- a/.github/workflows/terraform-apply.yml +++ b/.github/workflows/terraform-apply.yml @@ -17,6 +17,7 @@ jobs: if: github.repository != 'hashicorp-education/learn-terraform-github-actions' name: "Terraform Apply" runs-on: mealcraft-runners + container: ubuntu:22.04 permissions: contents: read steps: diff --git a/.github/workflows/terraform-plan.yml b/.github/workflows/terraform-plan.yml index 089d930..186010c 100644 --- a/.github/workflows/terraform-plan.yml +++ b/.github/workflows/terraform-plan.yml @@ -15,6 +15,7 @@ jobs: if: github.repository != 'hashicorp-education/learn-terraform-github-actions' name: "Terraform Plan" runs-on: mealcraft-runners + container: ubuntu:22.04 permissions: contents: read pull-requests: write diff --git a/.github/workflows/test-autoscaling.yml b/.github/workflows/test-autoscaling.yml index 138f6cb..ef7867d 100644 --- a/.github/workflows/test-autoscaling.yml +++ b/.github/workflows/test-autoscaling.yml @@ -6,6 +6,7 @@ on: jobs: load-test: runs-on: mealcraft-runners + container: ubuntu:22.04 strategy: matrix: job_id: [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20] diff --git a/github_runner/install/install_arc.sh b/github_runner/install/install_arc.sh index fe0ee9f..dea1f70 100644 --- a/github_runner/install/install_arc.sh +++ b/github_runner/install/install_arc.sh @@ -22,8 +22,6 @@ helm install arc \ oci://ghcr.io/actions/actions-runner-controller-charts/gha-runner-scale-set-controller helm uninstall mealcraft-runners -n arc-systems - -echo "=== Install MealCraft Runner Scale Set ===" helm install mealcraft-runners \ --namespace arc-systems \ --set runnerScaleSetName=mealcraft-runners \ @@ -31,12 +29,13 @@ helm install mealcraft-runners \ --set githubConfigUrl=https://github.com/MealCraft \ --set githubConfigSecret.github_token=$GITHUB_PAT \ --set githubConfigSecret.name=github-secret \ + \ --set containerMode.type=kubernetes \ + --set containerMode.kubernetesModeDefaultContainer.image=ubuntu:22.04 \ --set containerMode.kubernetesModeWorkVolumeClaim.accessModes[0]=ReadWriteOnce \ --set containerMode.kubernetesModeWorkVolumeClaim.storageClassName=microk8s-hostpath \ --set containerMode.kubernetesModeWorkVolumeClaim.resources.requests.storage=1Gi \ - --set defaultContainer.image=ubuntu:22.04 \ + \ oci://ghcr.io/actions/actions-runner-controller-charts/gha-runner-scale-set - echo "=== ARC installation complete ===" From 505aa2cc559dd6f91dfb6a5f67b538b0cb052e6b Mon Sep 17 00:00:00 2001 From: Jun-te Kim Date: Sat, 6 Dec 2025 17:07:52 +0000 Subject: [PATCH 10/22] terraform plan --- github_runner/install/install_arc.sh | 42 +++++++++++++--------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/github_runner/install/install_arc.sh b/github_runner/install/install_arc.sh index dea1f70..0f74b20 100644 --- a/github_runner/install/install_arc.sh +++ b/github_runner/install/install_arc.sh @@ -1,41 +1,37 @@ -# # !/bin/bash -# set -ex +#!/bin/bash +set -ex -# echo "=== Enable MicroK8s features ===" +# OPTIONAL: Enable MicroK8s features first # sudo microk8s enable dns rbac hostpath-storage host-access # sudo microk8s enable metrics-server - -# echo "=== Configure kubectl for MicroK8s ===" +# OPTIONAL: Configure kubectl # microk8s kubectl config view --raw > ~/.kube/config # chmod 600 ~/.kube/config # sudo usermod -aG microk8s $USER # sudo chown -f -R $USER ~/.kube +helm uninstall arc -n arc-systems || true -# if you need to uninstall first -helm uninstall arc -n arc-systems -echo "=== Install Scale Set ARC Controller ===" +echo "=== Install ARC Scale Set Controller ===" helm install arc \ --namespace arc-systems \ --create-namespace \ oci://ghcr.io/actions/actions-runner-controller-charts/gha-runner-scale-set-controller -helm uninstall mealcraft-runners -n arc-systems +helm uninstall mealcraft-runners -n arc-systems || true + helm install mealcraft-runners \ --namespace arc-systems \ - --set runnerScaleSetName=mealcraft-runners \ - --set runnerLabels[0]=mealcraft-runners \ - --set githubConfigUrl=https://github.com/MealCraft \ - --set githubConfigSecret.github_token=$GITHUB_PAT \ - --set githubConfigSecret.name=github-secret \ - \ - --set containerMode.type=kubernetes \ - --set containerMode.kubernetesModeDefaultContainer.image=ubuntu:22.04 \ - --set containerMode.kubernetesModeWorkVolumeClaim.accessModes[0]=ReadWriteOnce \ - --set containerMode.kubernetesModeWorkVolumeClaim.storageClassName=microk8s-hostpath \ - --set containerMode.kubernetesModeWorkVolumeClaim.resources.requests.storage=1Gi \ - \ + --create-namespace \ + --set runnerScaleSetName="mealcraft-runners" \ + --set githubConfigUrl="https://github.com/MealCraft" \ + --set githubConfigSecret.name="github-secret" \ + --set githubConfigSecret.github_token="$GITHUB_PAT" \ + --set containerMode.type="kubernetes" \ + --set containerMode.kubernetesModeDefaultContainer.image="ubuntu:22.04" \ + --set containerMode.kubernetesModeWorkVolumeClaim.accessModes[0]="ReadWriteOnce" \ + --set containerMode.kubernetesModeWorkVolumeClaim.storageClassName="microk8s-hostpath" \ + --set containerMode.kubernetesModeWorkVolumeClaim.resources.requests.storage="1Gi" \ + --set runnerLabels[0]="mealcraft" \ oci://ghcr.io/actions/actions-runner-controller-charts/gha-runner-scale-set - -echo "=== ARC installation complete ===" From 5e7153204f66d3e08d19ca149be345fe15ee7950 Mon Sep 17 00:00:00 2001 From: Jun-te Kim Date: Sat, 6 Dec 2025 17:12:02 +0000 Subject: [PATCH 11/22] terraform plan --- .github/workflows/terraform-plan.yml | 42 ++++++++++++++++++---------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/.github/workflows/terraform-plan.yml b/.github/workflows/terraform-plan.yml index 186010c..2e557fa 100644 --- a/.github/workflows/terraform-plan.yml +++ b/.github/workflows/terraform-plan.yml @@ -7,7 +7,7 @@ env: TF_CLOUD_ORGANIZATION: "MealCraft" TF_API_TOKEN: "${{ secrets.TF_API_TOKEN }}" TF_WORKSPACE: "production" - CONFIG_DIRECTORY: "./" + CONFIG_DIRECTORY: ${{ github.workspace }} TF_VAR_public_ip: "${{ secrets.PUBLIC_IP }}" jobs: @@ -19,7 +19,13 @@ jobs: permissions: contents: read pull-requests: write + steps: + - name: Install dependencies + run: | + apt-get update + apt-get install -y curl unzip jq ca-certificates + - name: Checkout uses: actions/checkout@v3 @@ -51,35 +57,43 @@ jobs: with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | - // 1. Retrieve existing bot comments for the PR const { data: comments } = await github.rest.issues.listComments({ owner: context.repo.owner, repo: context.repo.repo, issue_number: context.issue.number, }); + const botComment = comments.find(comment => { - return comment.user.type === 'Bot' && comment.body.includes('Terraform Cloud Plan Output') + return comment.user.type === 'Bot' && comment.body.includes('Terraform Cloud Plan Output'); }); + const output = `#### Terraform Cloud Plan Output - \`\`\` - Plan: ${{ steps.plan-output.outputs.add }} to add, ${{ steps.plan-output.outputs.change }} to change, ${{ steps.plan-output.outputs.destroy }} to destroy. - \`\`\` - [Terraform Cloud Plan](${{ steps.plan-run.outputs.run_link }}) - `; +\`\`\` +Plan: ${{ + steps.plan-output.outputs.add +}} to add, ${{ + steps.plan-output.outputs.change +}} to change, ${{ + steps.plan-output.outputs.destroy +}} to destroy. +\`\`\` +[Terraform Cloud Plan](${{ steps.plan-run.outputs.run_link }}) +`; + if (botComment) { - github.rest.issues.deleteComment({ + await github.rest.issues.deleteComment({ owner: context.repo.owner, repo: context.repo.repo, comment_id: botComment.id, }); } - github.rest.issues.createComment({ + + await github.rest.issues.createComment({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, - body: output - }) + body: output, + }); - name: Print TF_VAR_public_ip - run: 'echo "📡 Public IP used by Terraform: $TF_VAR_public_ip"' - + run: echo "📡 Public IP used by Terraform: $TF_VAR_public_ip" From c0b1a541562d935140368f95c1d71bd349ec6a8c Mon Sep 17 00:00:00 2001 From: Jun-te Kim Date: Sat, 6 Dec 2025 17:13:59 +0000 Subject: [PATCH 12/22] terraform plan --- .github/workflows/terraform-plan.yml | 38 +++++++++++++++------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/.github/workflows/terraform-plan.yml b/.github/workflows/terraform-plan.yml index 2e557fa..c44ef2a 100644 --- a/.github/workflows/terraform-plan.yml +++ b/.github/workflows/terraform-plan.yml @@ -1,4 +1,4 @@ -name: "Terraform Plan" +dname: "Terraform Plan" on: pull_request: @@ -57,28 +57,30 @@ jobs: with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | + const add = "${{ steps.plan-output.outputs.add }}"; + const change = "${{ steps.plan-output.outputs.change }}"; + const destroy = "${{ steps.plan-output.outputs.destroy }}"; + const runLink = "${{ steps.plan-run.outputs.run_link }}"; + + const output = ` +#### Terraform Cloud Plan Output + +\`\`\` +Plan: ${add} to add, ${change} to change, ${destroy} to destroy. +\`\`\` + +[Terraform Cloud Plan](${runLink}) +`; + const { data: comments } = await github.rest.issues.listComments({ owner: context.repo.owner, repo: context.repo.repo, issue_number: context.issue.number, }); - const botComment = comments.find(comment => { - return comment.user.type === 'Bot' && comment.body.includes('Terraform Cloud Plan Output'); - }); - - const output = `#### Terraform Cloud Plan Output -\`\`\` -Plan: ${{ - steps.plan-output.outputs.add -}} to add, ${{ - steps.plan-output.outputs.change -}} to change, ${{ - steps.plan-output.outputs.destroy -}} to destroy. -\`\`\` -[Terraform Cloud Plan](${{ steps.plan-run.outputs.run_link }}) -`; + const botComment = comments.find(c => + c.user.type === "Bot" && c.body.includes("Terraform Cloud Plan Output") + ); if (botComment) { await github.rest.issues.deleteComment({ @@ -89,9 +91,9 @@ Plan: ${{ } await github.rest.issues.createComment({ - issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, + issue_number: context.issue.number, body: output, }); From 8022f78666a237f8e0471ecbeb32e440cca8fb53 Mon Sep 17 00:00:00 2001 From: Jun-te Kim Date: Sat, 6 Dec 2025 17:15:03 +0000 Subject: [PATCH 13/22] terraform plan --- .github/workflows/terraform-plan.yml | 57 ++++++++++------------------ 1 file changed, 21 insertions(+), 36 deletions(-) diff --git a/.github/workflows/terraform-plan.yml b/.github/workflows/terraform-plan.yml index c44ef2a..fa0b645 100644 --- a/.github/workflows/terraform-plan.yml +++ b/.github/workflows/terraform-plan.yml @@ -1,4 +1,4 @@ -dname: "Terraform Plan" +name: "Terraform Plan" on: pull_request: @@ -7,7 +7,7 @@ env: TF_CLOUD_ORGANIZATION: "MealCraft" TF_API_TOKEN: "${{ secrets.TF_API_TOKEN }}" TF_WORKSPACE: "production" - CONFIG_DIRECTORY: ${{ github.workspace }} + CONFIG_DIRECTORY: "./" TF_VAR_public_ip: "${{ secrets.PUBLIC_IP }}" jobs: @@ -15,17 +15,12 @@ jobs: if: github.repository != 'hashicorp-education/learn-terraform-github-actions' name: "Terraform Plan" runs-on: mealcraft-runners - container: ubuntu:22.04 + containers: + image: ghcr.io/catthehacker/ubuntu:runner-22.04 permissions: contents: read pull-requests: write - steps: - - name: Install dependencies - run: | - apt-get update - apt-get install -y curl unzip jq ca-certificates - - name: Checkout uses: actions/checkout@v3 @@ -57,45 +52,35 @@ jobs: with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | - const add = "${{ steps.plan-output.outputs.add }}"; - const change = "${{ steps.plan-output.outputs.change }}"; - const destroy = "${{ steps.plan-output.outputs.destroy }}"; - const runLink = "${{ steps.plan-run.outputs.run_link }}"; - - const output = ` -#### Terraform Cloud Plan Output - -\`\`\` -Plan: ${add} to add, ${change} to change, ${destroy} to destroy. -\`\`\` - -[Terraform Cloud Plan](${runLink}) -`; - + // 1. Retrieve existing bot comments for the PR const { data: comments } = await github.rest.issues.listComments({ owner: context.repo.owner, repo: context.repo.repo, issue_number: context.issue.number, }); - - const botComment = comments.find(c => - c.user.type === "Bot" && c.body.includes("Terraform Cloud Plan Output") - ); - + const botComment = comments.find(comment => { + return comment.user.type === 'Bot' && comment.body.includes('Terraform Cloud Plan Output') + }); + const output = `#### Terraform Cloud Plan Output + \`\`\` + Plan: ${{ steps.plan-output.outputs.add }} to add, ${{ steps.plan-output.outputs.change }} to change, ${{ steps.plan-output.outputs.destroy }} to destroy. + \`\`\` + [Terraform Cloud Plan](${{ steps.plan-run.outputs.run_link }}) + `; if (botComment) { - await github.rest.issues.deleteComment({ + github.rest.issues.deleteComment({ owner: context.repo.owner, repo: context.repo.repo, comment_id: botComment.id, }); } - - await github.rest.issues.createComment({ + github.rest.issues.createComment({ + issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, - issue_number: context.issue.number, - body: output, - }); + body: output + }) - name: Print TF_VAR_public_ip - run: echo "📡 Public IP used by Terraform: $TF_VAR_public_ip" + run: 'echo "📡 Public IP used by Terraform: $TF_VAR_public_ip"' + From 5f16787e5861ac5c2011fc834d3d98a513236bd4 Mon Sep 17 00:00:00 2001 From: Jun-te Kim Date: Sat, 6 Dec 2025 17:16:28 +0000 Subject: [PATCH 14/22] terraform plan --- .github/workflows/terraform-plan.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/terraform-plan.yml b/.github/workflows/terraform-plan.yml index fa0b645..7c5b5fc 100644 --- a/.github/workflows/terraform-plan.yml +++ b/.github/workflows/terraform-plan.yml @@ -15,8 +15,7 @@ jobs: if: github.repository != 'hashicorp-education/learn-terraform-github-actions' name: "Terraform Plan" runs-on: mealcraft-runners - containers: - image: ghcr.io/catthehacker/ubuntu:runner-22.04 + containers: ghcr.io/catthehacker/ubuntu:runner-22.04 permissions: contents: read pull-requests: write From 5e3e3808b2360b3cc14c5015a4fda4f4088b0219 Mon Sep 17 00:00:00 2001 From: Jun-te Kim Date: Sat, 6 Dec 2025 17:16:47 +0000 Subject: [PATCH 15/22] terraform plan --- .github/workflows/terraform-plan.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/terraform-plan.yml b/.github/workflows/terraform-plan.yml index 7c5b5fc..066d18a 100644 --- a/.github/workflows/terraform-plan.yml +++ b/.github/workflows/terraform-plan.yml @@ -15,7 +15,8 @@ jobs: if: github.repository != 'hashicorp-education/learn-terraform-github-actions' name: "Terraform Plan" runs-on: mealcraft-runners - containers: ghcr.io/catthehacker/ubuntu:runner-22.04 + container: + image: ghcr.io/catthehacker/ubuntu:runner-22.04 permissions: contents: read pull-requests: write From 91fd24aae5f5edddd91773b2a8d17bb01443c9f6 Mon Sep 17 00:00:00 2001 From: Jun-te Kim Date: Sat, 6 Dec 2025 17:22:04 +0000 Subject: [PATCH 16/22] terraform plan --- .github/workflows/terraform-plan.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/terraform-plan.yml b/.github/workflows/terraform-plan.yml index 066d18a..128a877 100644 --- a/.github/workflows/terraform-plan.yml +++ b/.github/workflows/terraform-plan.yml @@ -7,7 +7,7 @@ env: TF_CLOUD_ORGANIZATION: "MealCraft" TF_API_TOKEN: "${{ secrets.TF_API_TOKEN }}" TF_WORKSPACE: "production" - CONFIG_DIRECTORY: "./" + CONFIG_DIRECTORY: ${{ github.workspace }} TF_VAR_public_ip: "${{ secrets.PUBLIC_IP }}" jobs: From 2da67a8faeb8a039d893a5f20d7ec12a5ad81594 Mon Sep 17 00:00:00 2001 From: Jun-te Kim Date: Sat, 6 Dec 2025 17:24:39 +0000 Subject: [PATCH 17/22] terraform plan --- .github/workflows/terraform-plan.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/terraform-plan.yml b/.github/workflows/terraform-plan.yml index 128a877..098c41a 100644 --- a/.github/workflows/terraform-plan.yml +++ b/.github/workflows/terraform-plan.yml @@ -7,7 +7,7 @@ env: TF_CLOUD_ORGANIZATION: "MealCraft" TF_API_TOKEN: "${{ secrets.TF_API_TOKEN }}" TF_WORKSPACE: "production" - CONFIG_DIRECTORY: ${{ github.workspace }} + CONFIG_DIRECTORY: ${{ github.workspace }}/aws_environment TF_VAR_public_ip: "${{ secrets.PUBLIC_IP }}" jobs: From 812ebf24b017730f3ab5bf2f97fa8f0d56d6fd4a Mon Sep 17 00:00:00 2001 From: Jun-te Kim Date: Sat, 6 Dec 2025 17:29:08 +0000 Subject: [PATCH 18/22] terraform plan --- .github/workflows/terraform-plan.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/terraform-plan.yml b/.github/workflows/terraform-plan.yml index 098c41a..6317db4 100644 --- a/.github/workflows/terraform-plan.yml +++ b/.github/workflows/terraform-plan.yml @@ -7,7 +7,7 @@ env: TF_CLOUD_ORGANIZATION: "MealCraft" TF_API_TOKEN: "${{ secrets.TF_API_TOKEN }}" TF_WORKSPACE: "production" - CONFIG_DIRECTORY: ${{ github.workspace }}/aws_environment + CONFIG_DIRECTORY: aws_environment TF_VAR_public_ip: "${{ secrets.PUBLIC_IP }}" jobs: From eddd627a4ad327e5315b940a68e3f88a5fca6828 Mon Sep 17 00:00:00 2001 From: Jun-te Kim Date: Sat, 6 Dec 2025 17:29:39 +0000 Subject: [PATCH 19/22] terraform plan --- .github/workflows/terraform-plan.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/terraform-plan.yml b/.github/workflows/terraform-plan.yml index 6317db4..b3c5a85 100644 --- a/.github/workflows/terraform-plan.yml +++ b/.github/workflows/terraform-plan.yml @@ -23,7 +23,12 @@ jobs: steps: - name: Checkout uses: actions/checkout@v3 - + - name: Debug Paths + run: | + echo "Workspace: $GITHUB_WORKSPACE" + ls -R . + echo "CONFIG_DIRECTORY: $CONFIG_DIRECTORY" + ls -R "$CONFIG_DIRECTORY" - name: Upload Configuration uses: hashicorp/tfc-workflows-github/actions/upload-configuration@v1.0.0 id: plan-upload From 957b79060ae9aae5e445edbb732490fa6dea8305 Mon Sep 17 00:00:00 2001 From: Jun-te Kim Date: Sat, 6 Dec 2025 17:36:03 +0000 Subject: [PATCH 20/22] terraform plan --- aws_environment/terraform.tf | 1 + 1 file changed, 1 insertion(+) diff --git a/aws_environment/terraform.tf b/aws_environment/terraform.tf index 50e2f42..750314a 100644 --- a/aws_environment/terraform.tf +++ b/aws_environment/terraform.tf @@ -33,3 +33,4 @@ terraform { required_version = "~> 1.3" } + From e52dc5c298d611fd60baab84af99cf0226bc74cf Mon Sep 17 00:00:00 2001 From: Jun-te Kim Date: Sat, 6 Dec 2025 17:40:10 +0000 Subject: [PATCH 21/22] terraform plan --- aws_environment/terraform.tf | 1 + 1 file changed, 1 insertion(+) diff --git a/aws_environment/terraform.tf b/aws_environment/terraform.tf index 750314a..dbd2b15 100644 --- a/aws_environment/terraform.tf +++ b/aws_environment/terraform.tf @@ -34,3 +34,4 @@ terraform { } + From 92934e3b07ed2163fd7b2f28a86813044e1387cb Mon Sep 17 00:00:00 2001 From: Jun-te Kim Date: Sat, 6 Dec 2025 19:44:18 +0000 Subject: [PATCH 22/22] terraform apply --- .github/workflows/terraform-apply.yml | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/.github/workflows/terraform-apply.yml b/.github/workflows/terraform-apply.yml index b1686f5..cde27f5 100644 --- a/.github/workflows/terraform-apply.yml +++ b/.github/workflows/terraform-apply.yml @@ -9,7 +9,7 @@ env: TF_CLOUD_ORGANIZATION: "MealCraft" TF_API_TOKEN: "${{ secrets.TF_API_TOKEN }}" TF_WORKSPACE: "production" - CONFIG_DIRECTORY: "./" + CONFIG_DIRECTORY: aws_environment TF_VAR_public_ip: "${{ secrets.PUBLIC_IP }}" jobs: @@ -17,13 +17,22 @@ jobs: if: github.repository != 'hashicorp-education/learn-terraform-github-actions' name: "Terraform Apply" runs-on: mealcraft-runners - container: ubuntu:22.04 + container: + image: ghcr.io/catthehacker/ubuntu:runner-22.04 permissions: contents: read + steps: - name: Checkout uses: actions/checkout@v3 + - name: Debug Paths + run: | + echo "Workspace: $GITHUB_WORKSPACE" + ls -R . + echo "CONFIG_DIRECTORY: $CONFIG_DIRECTORY" + ls -R "$CONFIG_DIRECTORY" + - name: Upload Configuration uses: hashicorp/tfc-workflows-github/actions/upload-configuration@v1.0.0 id: apply-upload @@ -38,10 +47,14 @@ jobs: workspace: ${{ env.TF_WORKSPACE }} configuration_version: ${{ steps.apply-upload.outputs.configuration_version_id }} + # Terraform marks the run as "confirmable" using lowercase attribute - name: Apply + if: fromJSON(steps.apply-run.outputs.payload).data.attributes.actions.is_confirmable uses: hashicorp/tfc-workflows-github/actions/apply-run@v1.0.0 - if: fromJSON(steps.apply-run.outputs.payload).data.attributes.actions.IsConfirmable id: apply with: - comment: "Apply Run from GitHub Actions CI ${{ github.sha }}" + comment: "Apply from GitHub Actions CI ${{ github.sha }}" run: ${{ steps.apply-run.outputs.run_id }} + + - name: Print TF_VAR_public_ip + run: 'echo "📡 Public IP used by Terraform: $TF_VAR_public_ip"'