{"id":17978431,"url":"https://github.com/mloskot/terraform-github-pr-commenter","last_synced_at":"2025-04-04T00:24:28.961Z","repository":{"id":66812288,"uuid":"603401165","full_name":"mloskot/terraform-github-pr-commenter","owner":"mloskot","description":"Renders Terraform fmt,plan,validate output in Markdown, so any CI/CD can post as opinionated GitHub PR comment","archived":false,"fork":false,"pushed_at":"2023-02-25T00:19:21.000Z","size":318,"stargazers_count":0,"open_issues_count":3,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-09T12:20:44.169Z","etag":null,"topics":["azure-devops","azure-pipelines","bash-script","devops-automation","devops-tools","github-actions","terraform"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mloskot.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-02-18T11:56:01.000Z","updated_at":"2023-02-19T19:24:04.000Z","dependencies_parsed_at":"2023-04-08T19:12:44.191Z","dependency_job_id":null,"html_url":"https://github.com/mloskot/terraform-github-pr-commenter","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mloskot%2Fterraform-github-pr-commenter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mloskot%2Fterraform-github-pr-commenter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mloskot%2Fterraform-github-pr-commenter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mloskot%2Fterraform-github-pr-commenter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mloskot","download_url":"https://codeload.github.com/mloskot/terraform-github-pr-commenter/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247099611,"owners_count":20883431,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["azure-devops","azure-pipelines","bash-script","devops-automation","devops-tools","github-actions","terraform"],"created_at":"2024-10-29T17:33:41.801Z","updated_at":"2025-04-04T00:24:28.943Z","avatar_url":"https://github.com/mloskot.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# terraform-github-pr-commenter\n\nBash script to render Terraform command output as GitHub Pull Request comment\nready to be posted from any CI/CD agent that can be authenticated with GitHub,\nfor example, Azure Pipelines or GitHub Actions.\n\n![fmt](screenshot/fmt.png)\n\nSee [screenshot/README.md](screenshot/README.md) for more visual samples of posted GitHub comments.\n\n## Requirements\n\n- Bash\n- `iconv` or `konwert` to convert the Terraform fancy outputs to plain and easily escapable ASCII.\n    The conversion especially helps to avoid Azure Pipelines [task.setvariable](https://learn.microsoft.com/en-us/azure/devops/pipelines/process/set-variables-scripts)\n    tripping over fancy Unicode characters (e.g. box drawing).\n- Terraform command output saved in `\u003c00N\u003e_\u003ctitle\u003e.\u003ccommand\u003e.{log,txt}` files (see [description](#description) below).\n\n## Usage: CLI\n\n```console\nUsage: ./terraform-pr-comment.sh [arguments]\n  -v,--verbose                Advertise detailed steps and actions (pass first for arguments logging)\n  -c,--command \u003cname\u003e         Terraform command: fmt, plan, validate\n  -p,--logs-path \u003cpath\u003e       Location where to look for log files with Terraform command output\n  -b,--build-number \u003cnumber\u003e  Build number or identifier provided by CI/CD service\n  -u,--build-url \u003curl\u003e        Build results URL provided by CI/CD service\n  -d,--disable-outer-details  Disable outer HTML \u003cdetails\u003e section\n  -h,--help                   Displays this message\n```\n\nRunning the script from command line is useful for testing only.\nThe script on its own does not post any comments to GitHub.\n\n## Usage: CI/CD\n\n- for Azure Pipelines example see [.azure-pipelines.yml](.azure-pipelines.yml)\n\n## Description\n\nThe script collects Terraform command outputs from log files in given location,\ncombines them and renders in Markdown as content for GitHub Pull Request comment,\nand returns via exported environment variable.\n\nThe script renders single comment titled with given build number and command.\n\nThe script can read multiple log files from number of runs of the same Terraform\ncommand - one run per component of layer of user's infrastructure\nEach run is rendered as separate section with its own sub-title.\n\nThe rendered content can be posted by Azure Pipeline using\n[GitHubComment@0](https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/reference/github-comment-v0)\ntask or by GitHub Actions using GitHub Script method\n[github.issues.createComment](https://github.com/actions/github-script).\n\nLog file name format is `\u003c00N\u003e_\u003ctitle\u003e.\u003ccommand\u003e.{log,txt}` where\n\n- `\u003c00N\u003e` part controls order in which files are read\n- `\u003ctitle\u003e` part is used as heading of section for given log\n- `\u003ccommand\u003e` used in the comment title together with given build number\n\nNotice, that unlike other solutions like\n[terraform-pr-commenter](https://github.com/robburger/terraform-pr-commenter),\nthis script does not search and delete any previous comment it posted.\nThis script always posts a new comment for new build result.\nIt is a very simple script.\n\n## Preparing Logs\n\n*TODO:* Explain how to prepare log files as valid input for this script.\n\n## Credits\n\n- [@sbulav](https://github.com/sbulav) for [Terraform processing with `jq`](https://sbulav.github.io/terraform/terraform-vs-github-actions/)\n   and showing how to use [github.issues.createComment](https://github.com/actions/github-script)\n- [@nbellocam](https://github.com/nbellocam) for [Azure Pipelines task `GitHubComment@0` show case](https://medium.com/southworks/continuous-integration-for-smart-contracts-4a8b78d387c)\n- [@robertwbradford](https://github.com/robertwbradford) for [solving multi-line comment with `GitHubComment@0`](https://stackoverflow.com/a/72277737/151641)\n- [@robburger](https://github.com/robburger) for [terraform-pr-commenter scripted in Bash](https://github.com/robburger/terraform-pr-commenter/blob/10779c60059f0f099ef676a9dde158d646555473/entrypoint.sh)\n- [@ahmadnassri](https://github.com/ahmadnassri) for [inspiring Terraform reports](https://github.com/ahmadnassri/action-terraform-report)\n- [@gunkow](https://github.com/gunkow) for another example of [inspiring Terraform reports](https://github.com/gunkow/terraform-pr-commenter)\n\nThank you all! ~Mateusz Łoskot\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmloskot%2Fterraform-github-pr-commenter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmloskot%2Fterraform-github-pr-commenter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmloskot%2Fterraform-github-pr-commenter/lists"}