terragrunt-action
terragrunt-action copied to clipboard
Plan output not properly formatted
Describe the bug Capturing the terragrunt plan output to use it into a comment is not properly formatted. The plan output is on a single line.
To Reproduce Steps to reproduce the behavior, code snippets and examples which can be used to reproduce the issue.
- name: Check terragrunt HCL
uses: gruntwork-io/terragrunt-action@v1
id: fmt
with:
tf_version: ${{ inputs.tf_version }}
tg_version: ${{ inputs.tg_version }}
tg_dir: ${{ inputs.workdir }}
tg_command: 'hclfmt --terragrunt-check --terragrunt-diff'
- name: Plan
id: plan
uses: gruntwork-io/terragrunt-action@v1
with:
tg_comment: 1
tf_version: ${{ inputs.tf_version }}
tg_version: ${{ inputs.tg_version }}
tg_dir: ${{ inputs.workdir }}
tg_command: 'plan'
- uses: actions/github-script@v6
if: github.event_name == 'pull_request'
env:
PLAN: "terraform\n${{ steps.plan.outputs.tg_action_output }}"
with:
github-token: ${{ inputs.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('Terragrunt Format and Style')
})
// 2. Prepare format of the comment
const output = `#### Terragrunt Format and Style 🖌\`${{ steps.fmt.outcome }}\`
#### Terragrunt Plan 📖\`${{ steps.plan.outcome }}\`
<details><summary>Show Plan</summary>
\`\`\`\n
${{ steps.plan.outputs.tg_action_output }}
\`\`\`
</details>
*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`, Workflow: \`${{ github.workflow }}\`*`;
// 3. If we have a comment, update it, otherwise create a new one
if (botComment) {
github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: output
})
} else {
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})
}
Expected behavior Should output the plan formatted as shown in the action log:
Nice to have
- [X] Terminal output
- [X] Screenshots
Versions
- Terragrunt Action version: v1
- Environment details (Terragrunt version, Terraform version, etc.):
- tg version: 0.46.3
- tf version: 1.5.6
Additional context I've tried a few things to output in the proper format but no luck so far.