From 44c7a690ce3d92002ea40ba9784414aae89a5f3f Mon Sep 17 00:00:00 2001 From: yurikakan Date: Wed, 8 Oct 2025 11:53:03 -0400 Subject: [PATCH 1/9] test bug --- infrastructure/test/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/infrastructure/test/main.tf b/infrastructure/test/main.tf index a896f1d..d1faa7c 100644 --- a/infrastructure/test/main.tf +++ b/infrastructure/test/main.tf @@ -5,4 +5,4 @@ resource "aws_instance" "example" { tags = { Name = "HelloWorld" } -} \ No newline at end of file +} From 2f88539a8a82467cc5e035ef081ba8b39c073b78 Mon Sep 17 00:00:00 2001 From: yurikakan Date: Wed, 8 Oct 2025 11:56:18 -0400 Subject: [PATCH 2/9] actual bug --- infrastructure/test/main.tf | 2 ++ 1 file changed, 2 insertions(+) diff --git a/infrastructure/test/main.tf b/infrastructure/test/main.tf index d1faa7c..9171daf 100644 --- a/infrastructure/test/main.tf +++ b/infrastructure/test/main.tf @@ -6,3 +6,5 @@ resource "aws_instance" "example" { Name = "HelloWorld" } } + +bug bug bug \ No newline at end of file From 392d21a854eb2eee322851fb75a62731572f66b6 Mon Sep 17 00:00:00 2001 From: yurikakan Date: Wed, 8 Oct 2025 12:04:39 -0400 Subject: [PATCH 3/9] bug that should bug --- infrastructure/test/main.tf | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/infrastructure/test/main.tf b/infrastructure/test/main.tf index 9171daf..4f97645 100644 --- a/infrastructure/test/main.tf +++ b/infrastructure/test/main.tf @@ -7,4 +7,19 @@ resource "aws_instance" "example" { } } -bug bug bug \ No newline at end of file +# Intentionally cause plan to fail while keeping syntax valid: +# This data source queries a non-existent AMI ID, which will make +# terraform plan error out with a provider lookup failure. +data "aws_ami" "nonexistent" { + owners = ["self"] + most_recent = true + filter { + name = "image-id" + values = ["ami-00000000000000000"] + } +} + +output "nonexistent_ami_id" { + value = data.aws_ami.nonexistent.id +} + From 11dc316855144229cc3afbb45ec608c0d47f0c3d Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 8 Oct 2025 16:05:04 +0000 Subject: [PATCH 4/9] chore: auto-format terraform and update documentation - Auto-formatted .tf files with terraform fmt - Updated README.md with terraform-docs Co-authored-by: Yurika-Kan --- infrastructure/test/README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/infrastructure/test/README.md b/infrastructure/test/README.md index 6e19b1a..f0fd8e9 100644 --- a/infrastructure/test/README.md +++ b/infrastructure/test/README.md @@ -22,6 +22,7 @@ No modules. | Name | Type | |------|------| | [aws_instance.example](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/instance) | resource | +| [aws_ami.nonexistent](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ami) | data source | ## Inputs @@ -29,5 +30,7 @@ No inputs. ## Outputs -No outputs. +| Name | Description | +|------|-------------| +| [nonexistent\_ami\_id](#output\_nonexistent\_ami\_id) | n/a | From ca5be3cfa493544250ed48020c742654a65fcbb9 Mon Sep 17 00:00:00 2001 From: yurikakan Date: Wed, 8 Oct 2025 12:10:44 -0400 Subject: [PATCH 5/9] test fix --- infrastructure/test/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/infrastructure/test/main.tf b/infrastructure/test/main.tf index 4f97645..0c1a6c7 100644 --- a/infrastructure/test/main.tf +++ b/infrastructure/test/main.tf @@ -15,7 +15,7 @@ data "aws_ami" "nonexistent" { most_recent = true filter { name = "image-id" - values = ["ami-00000000000000000"] + values = ["ami-0000000000000000"] } } From 388e7384b90a954116fcdd5038fdc16571c428c2 Mon Sep 17 00:00:00 2001 From: yurikakan Date: Wed, 8 Oct 2025 12:12:43 -0400 Subject: [PATCH 6/9] test fix --- .github/workflows/terraform-plan.yml | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/.github/workflows/terraform-plan.yml b/.github/workflows/terraform-plan.yml index 1114e8c..c03038a 100644 --- a/.github/workflows/terraform-plan.yml +++ b/.github/workflows/terraform-plan.yml @@ -211,6 +211,18 @@ jobs: TF_VAR_infisical_client_id: ${{ secrets.INFISICAL_CLIENT_ID }} TF_VAR_infisical_client_secret: ${{ secrets.INFISICAL_CLIENT_SECRET }} + - name: Show Terraform Plan Output in Workflow + if: always() + run: | + echo "=== Terraform Plan Output (${{ matrix.directory }}) ===" + if [ -f plan_output.txt ]; then + cat plan_output.txt + else + echo "No plan output file found" + fi + echo "=== End Terraform Plan Output ===" + working-directory: ${{ matrix.directory }} + - name: Delete old plan comments uses: actions/github-script@v7 if: github.event_name == 'pull_request' @@ -273,6 +285,8 @@ jobs: - name: Comment PR - Failure uses: actions/github-script@v7 if: github.event_name == 'pull_request' && steps.plan.outcome == 'failure' + env: + PLAN: ${{ steps.plan.outputs.stdout }} with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | @@ -280,9 +294,15 @@ jobs: #### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\` #### Terraform Validation 🤖\`${{ steps.validate.outcome }}\` - *Pushed by: @${{ github.actor }}, Action: \`${{ github.event_name }}\`* +
Show Error Details - Check the workflow logs for more details.`; + \`\`\`terraform + ${process.env.PLAN || 'No plan output captured'} + \`\`\` + +
+ + *Pushed by: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`; github.rest.issues.createComment({ issue_number: context.issue.number, From 9b3ff1df8b4cdad90987968dfbc4711a57828d8b Mon Sep 17 00:00:00 2001 From: yurikakan Date: Wed, 8 Oct 2025 12:21:08 -0400 Subject: [PATCH 7/9] test output.txt --- .github/workflows/terraform-plan.yml | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/.github/workflows/terraform-plan.yml b/.github/workflows/terraform-plan.yml index c03038a..31317af 100644 --- a/.github/workflows/terraform-plan.yml +++ b/.github/workflows/terraform-plan.yml @@ -198,12 +198,28 @@ jobs: - name: Terraform Plan id: plan run: | + # Run terraform plan and capture both stdout and stderr terraform plan -no-color -input=false -out=tfplan > plan_output.txt 2>&1 PLAN_EXIT_CODE=$? - PLAN_OUTPUT=$(cat plan_output.txt) + + # Robust output capture with error handling + if [ -f plan_output.txt ] && [ -s plan_output.txt ]; then + # File exists and has content + PLAN_OUTPUT=$(cat plan_output.txt) + echo "Plan output captured successfully (${#PLAN_OUTPUT} characters)" + else + # File doesn't exist or is empty + PLAN_OUTPUT="No terraform plan output was generated" + echo "Warning: plan_output.txt is missing or empty" + fi + + # Set step outputs echo "stdout<> $GITHUB_OUTPUT echo "$PLAN_OUTPUT" >> $GITHUB_OUTPUT echo "EOF" >> $GITHUB_OUTPUT + echo "exit_code=$PLAN_EXIT_CODE" >> $GITHUB_OUTPUT + + # Exit with original code exit $PLAN_EXIT_CODE working-directory: ${{ matrix.directory }} continue-on-error: true From d70ab148f36a09ffc66b56cfc12f68e1e3a2499c Mon Sep 17 00:00:00 2001 From: Dennis Wang <66754085+denniwang@users.noreply.github.com> Date: Wed, 8 Oct 2025 12:28:34 -0400 Subject: [PATCH 8/9] saving logs to text file --- .github/workflows/terraform-plan.yml | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/.github/workflows/terraform-plan.yml b/.github/workflows/terraform-plan.yml index c03038a..03fc31f 100644 --- a/.github/workflows/terraform-plan.yml +++ b/.github/workflows/terraform-plan.yml @@ -204,6 +204,8 @@ jobs: echo "stdout<> $GITHUB_OUTPUT echo "$PLAN_OUTPUT" >> $GITHUB_OUTPUT echo "EOF" >> $GITHUB_OUTPUT + # Also write to a file for the failure step to read + echo "$PLAN_OUTPUT" > plan_output_for_failure.txt exit $PLAN_EXIT_CODE working-directory: ${{ matrix.directory }} continue-on-error: true @@ -285,11 +287,22 @@ jobs: - name: Comment PR - Failure uses: actions/github-script@v7 if: github.event_name == 'pull_request' && steps.plan.outcome == 'failure' - env: - PLAN: ${{ steps.plan.outputs.stdout }} with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | + const fs = require('fs'); + const path = require('path'); + + let planOutput = 'No plan output captured'; + try { + const planFile = path.join('${{ matrix.directory }}', 'plan_output_for_failure.txt'); + if (fs.existsSync(planFile)) { + planOutput = fs.readFileSync(planFile, 'utf8'); + } + } catch (error) { + console.log('Error reading plan output file:', error.message); + } + const output = `#### Terraform Plan Failed ❌ \`${{ matrix.directory }}\` #### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\` #### Terraform Validation 🤖\`${{ steps.validate.outcome }}\` @@ -297,12 +310,12 @@ jobs:
Show Error Details \`\`\`terraform - ${process.env.PLAN || 'No plan output captured'} + ${planOutput} \`\`\`
- *Pushed by: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`; + *Pushed by: @${{ github.event.pull_request.user.login }}, Action: \`${{ github.event_name }}\`*`; github.rest.issues.createComment({ issue_number: context.issue.number, From 46c8b8b8540971acf2dd4cace95a56d387f3eeb5 Mon Sep 17 00:00:00 2001 From: yurikakan Date: Wed, 8 Oct 2025 12:37:02 -0400 Subject: [PATCH 9/9] test directory access change --- .github/workflows/terraform-plan.yml | 30 ++++++++++++++-------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/.github/workflows/terraform-plan.yml b/.github/workflows/terraform-plan.yml index 8457baf..863d4ad 100644 --- a/.github/workflows/terraform-plan.yml +++ b/.github/workflows/terraform-plan.yml @@ -203,14 +203,20 @@ jobs: PLAN_EXIT_CODE=$? # Robust output capture with error handling + echo "Checking for plan output file..." if [ -f plan_output.txt ] && [ -s plan_output.txt ]; then - # File exists and has content + # File exists and has content - capture the actual output + echo "plan_output.txt exists and has content, capturing..." PLAN_OUTPUT=$(cat plan_output.txt) echo "Plan output captured successfully (${#PLAN_OUTPUT} characters)" + echo "First 200 chars of captured output:" + echo "${PLAN_OUTPUT:0:200}..." else # File doesn't exist or is empty PLAN_OUTPUT="No terraform plan output was generated" echo "Warning: plan_output.txt is missing or empty" + echo "File exists: $([ -f plan_output.txt ] && echo 'YES' || echo 'NO')" + echo "File size: $(wc -c < plan_output.txt 2>/dev/null || echo '0')" fi # Set step outputs @@ -233,13 +239,16 @@ jobs: if: always() run: | echo "=== Terraform Plan Output (${{ matrix.directory }}) ===" + cd "${{ matrix.directory }}" if [ -f plan_output.txt ]; then + echo "File exists, showing content:" cat plan_output.txt else - echo "No plan output file found" + echo "No plan output file found in $(pwd)" + echo "Files in directory:" + ls -la fi echo "=== End Terraform Plan Output ===" - working-directory: ${{ matrix.directory }} - name: Delete old plan comments uses: actions/github-script@v7 @@ -306,19 +315,10 @@ jobs: with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | - const fs = require('fs'); - const path = require('path'); - - let planOutput = 'No plan output captured'; - try { - const planFile = path.join('${{ matrix.directory }}', 'plan_output_for_failure.txt'); - if (fs.existsSync(planFile)) { - planOutput = fs.readFileSync(planFile, 'utf8'); - } - } catch (error) { - console.log('Error reading plan output file:', error.message); - } + console.log('Debug: PLAN env var length:', process.env.PLAN ? process.env.PLAN.length : 'undefined'); + console.log('Debug: PLAN env var preview:', process.env.PLAN ? process.env.PLAN.substring(0, 100) + '...' : 'undefined'); + const planOutput = process.env.PLAN || 'No plan output captured'; const output = `#### Terraform Plan Failed ❌ \`${{ matrix.directory }}\` #### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\` #### Terraform Validation 🤖\`${{ steps.validate.outcome }}\`