Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Github Actions Terraform output with github-script has symbols / ascii characters #207

Open
jku-sr opened this issue May 25, 2022 · 5 comments

Comments

@jku-sr
Copy link

jku-sr commented May 25, 2022

Following the example setup where the outputs of Terraform Plan is added to the Pull Request as a comment. However there's all these ? type symbols that gets added in the comments.

versions:
hashicorp/setup-terraform@v2
actions/github-script@v6

my Github Actions YML File

# Generates an execution plan for Terraform
      - name: Terraform Plan
        id: plan
        run: terraform plan -input=false
      - uses: actions/github-script@v6
        if: github.event_name == 'pull_request'
        env:
          PLAN: "terraform\n${{ steps.plan.outputs.stdout }}"
        with:
          script: |
            const output = `#### Terraform Plan 📖\`${{ steps.plan.outcome }}\`
        
            <details><summary>Show Plan</summary>

            \`\`\`\n
            ${process.env.PLAN}
            \`\`\`

            </details>

            *Pushed by: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`;

            github.rest.issues.createComment({
              issue_number: context.issue.number,
              owner: context.repo.owner,
              repo: context.repo.repo,
              body: output
            })`




My condensed Output:

terraform
eastus2/providers/Microsoft.Compute/virtualMachines/vm-1]�[0m
�[0m�[1mazurerm_virtual_machine_extension.ext[0]: Refreshing state... [id=/subscriptions/redacted/resourceGroups/rg-eastus2/providers/Microsoft.Compute/virtualMachines/vm-1/extensions/customscript]�[0m


�[0m�[1m�[32mNo changes.�[0m�[1m Your infrastructure matches the configuration.�[0m
�[0mTerraform has compared your real infrastructure against your configuration
and found no differences, so no changes are needed.

`

Where do these question mark symbols come from. If I set my terraform plan to -no-color it'll remove the symbols. Is there any other work around?

@rajeshkbathula
Copy link

any update, facing similar issue!

@megamorf
Copy link

That's why they tell you to run terraform with -no-color.

@david-mk-lawrence
Copy link

I used something like terraform plan -out tfplan so that I get colorized output in the logs, but then I added a second step to do terraform show -no-color tfplan. Then use the show step's stdout/stderr outputs for use in the comment.

For example

- run: terraform plan -out tfplan
  id: plan

- run: terraform show -no-color tfplan
  id: show

- uses: actions/github-script@v6
  env:
    PLAN: ${{ steps.show.outputs.stdout }} # <-- reference the "show" step
  with:
    script: |
      const output = `#### Terraform Plan 📖\`${{ steps.plan.outcome }}\`
        
      <details><summary>Show Plan</summary>

      \`\`\`\n
      ${process.env.PLAN}
      \`\`\`

      </details>

      *Pushed by: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`;

      github.rest.issues.createComment({
        issue_number: context.issue.number,
        owner: context.repo.owner,
        repo: context.repo.repo,
        body: output
      })`

@jku-sr jku-sr closed this as completed Nov 7, 2022
@jku-sr jku-sr reopened this Nov 7, 2022
@jku-sr
Copy link
Author

jku-sr commented Nov 7, 2022

I used something like terraform plan -out tfplan so that I get colorized output in the logs, but then I added a second step to do terraform show -no-color tfplan. Then use the show step's stdout/stderr outputs for use in the comment.

For example

- run: terraform plan -out tfplan
  id: plan

- run: terraform show -no-color tfplan
  id: show

- uses: actions/github-script@v6
  env:
    PLAN: ${{ steps.show.outputs.stdout }} # <-- reference the "show" step
  with:
    script: |
      const output = `#### Terraform Plan 📖\`${{ steps.plan.outcome }}\`
        
      <details><summary>Show Plan</summary>

      \`\`\`\n
      ${process.env.PLAN}
      \`\`\`

      </details>

      *Pushed by: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`;

      github.rest.issues.createComment({
        issue_number: context.issue.number,
        owner: context.repo.owner,
        repo: context.repo.repo,
        body: output
      })`

this is a great work around. I am going to do something similar. Thank You!

@Adarsh-Suvarna
Copy link

terraform plan -out tfplan

If i give terraform plan -out tfplan, it will save the Plan in the Self-Hosted runner and same Plan wont display in the Terraform Cloud/Enterprise plan logs. Is there any workaround to display the Plan outputs in the Terraform enterprise as well ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants