{"id":30144040,"url":"https://github.com/sblack4/learning-terraform-github-actions","last_synced_at":"2025-08-11T07:36:40.972Z","repository":{"id":54511461,"uuid":"338687340","full_name":"sblack4/learning-terraform-github-actions","owner":"sblack4","description":"A POC to do ChatOps for Terraform in GitHub Actions","archived":false,"fork":false,"pushed_at":"2021-02-14T21:17:34.000Z","size":31,"stargazers_count":2,"open_issues_count":2,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2023-08-08T18:33:11.553Z","etag":null,"topics":["chatops","devops","github-actions","poc","terraform"],"latest_commit_sha":null,"homepage":"","language":"HCL","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/sblack4.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}},"created_at":"2021-02-13T23:00:35.000Z","updated_at":"2023-08-08T18:33:11.554Z","dependencies_parsed_at":"2022-08-13T18:10:57.271Z","dependency_job_id":null,"html_url":"https://github.com/sblack4/learning-terraform-github-actions","commit_stats":null,"previous_names":[],"tags_count":0,"template":null,"template_full_name":null,"purl":"pkg:github/sblack4/learning-terraform-github-actions","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sblack4%2Flearning-terraform-github-actions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sblack4%2Flearning-terraform-github-actions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sblack4%2Flearning-terraform-github-actions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sblack4%2Flearning-terraform-github-actions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sblack4","download_url":"https://codeload.github.com/sblack4/learning-terraform-github-actions/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sblack4%2Flearning-terraform-github-actions/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269849489,"owners_count":24485153,"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","status":"online","status_checked_at":"2025-08-11T02:00:10.019Z","response_time":75,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["chatops","devops","github-actions","poc","terraform"],"created_at":"2025-08-11T07:36:39.065Z","updated_at":"2025-08-11T07:36:40.879Z","avatar_url":"https://github.com/sblack4.png","language":"HCL","readme":"# learning-terraform-github-actions\nA POC to do ChatOps for Terraform in GitHub Actions\n\n## User Story\nAs a DevOps engineer I want to see the terraform plan and apply in the pull request. \nI would like automation to run this so that developers (like me) never have access to the secrets. \nThe terraform apply should run the plan outfile. \n\n## Demonstration\nThis is merely a POC but see this PR [#8](https://github.com/sblack4/learning-terraform-github-actions/pull/8)\n\n## Artifact\nThe output of this is the [terraform workflow file](https://github.com/sblack4/learning-terraform-github-actions/blob/main/.github/workflows/terraform.yaml). Some of it was cropped from work done by hashicorp, which is plainly obvious if you've seen their work. Unfortunately their work did not fulfill the last acceptance criteria. \n\nHere's the relevant piece of that file:\n\n```yaml\n\n---\non:\n  issue_comment:\n  pull_request:\n  pull_request_review_comment:\n  \njobs:\n  plan_or_apply:\n    runs-on: ubuntu-latest\n    name: Terraform Plan or Apply\n    steps:\n\n      - uses: actions/checkout@v2\n\n      # I know this is like so 2000 and late\n      # but you can use the version you want\n      - uses: hashicorp/setup-terraform@v1\n        with:\n          terraform_version: 0.12.25\n      \n      - name: Terraform fmt\n        id: fmt\n        run: terraform fmt -check\n        continue-on-error: true\n      \n      - name: Terraform Init\n        id: init\n        run: terraform init\n      \n      - name: Terraform Validate\n        id: validate\n        run: terraform validate -no-color\n      \n      - name: Terraform Plan\n        continue-on-error: true\n        if: github.event_name == 'issue_comment' \u0026\u0026 contains(github.event.comment.body, 'terraform plan')\n        id: plan\n        run: terraform plan -no-color -out plan.out\n\n      - name: 'Upload Artifact'\n        continue-on-error: true\n        if: github.event_name == 'issue_comment' \u0026\u0026 contains(github.event.comment.body, 'terraform plan')\n        uses: actions/upload-artifact@v2\n        with:\n          name: terraform-plan-artifact\n          path: plan.out\n          retention-days: 5\n\n      - uses: actions/github-script@0.9.0\n        if: github.event_name == 'issue_comment' \u0026\u0026 contains(github.event.comment.body, 'terraform plan')\n        env:\n          PLAN: \"terraform\\n${{ steps.plan.outputs.stdout }}\"\n        with:\n          github-token: ${{ secrets.GITHUB_TOKEN }}\n          script: |\n            const output = `#### Terraform Format and Style 🖌\\`${{ steps.fmt.outcome }}\\`\n            #### Terraform Initialization ⚙️\\`${{ steps.init.outcome }}\\`\n            #### Terraform Validation 🤖${{ steps.validate.outputs.stdout }}\n            #### Terraform Plan 📖\\`${{ steps.plan.outcome }}\\`\n            \u003cdetails\u003e\u003csummary\u003eShow Plan\u003c/summary\u003e\n            \\`\\`\\`${process.env.PLAN}\\`\\`\\`\n            \u003c/details\u003e\n            *Pusher: @${{ github.actor }}, Action: \\`${{ github.event_name }}\\`, Workflow: \\`${{ github.workflow }}\\`*`;\n            github.issues.createComment({\n              issue_number: context.issue.number,\n              owner: context.repo.owner,\n              repo: context.repo.repo,\n              body: output\n            })\n            \n      # why this action?\n      # see https://github.com/actions/toolkit/issues/501\n      - name: Download a single artifact\n        if: github.event_name == 'issue_comment' \u0026\u0026 contains(github.event.comment.body, 'terraform apply')\n        uses: dawidd6/action-download-artifact@v2\n        with:\n          name: terraform-plan-artifact\n          github_token: ${{secrets.GITHUB_TOKEN}}\n          workflow: terraform.yaml\n          workflow_conclusion: success\n      \n      - name: Terraform Apply\n        id: apply\n        if: github.event_name == 'issue_comment' \u0026\u0026 contains(github.event.comment.body, 'terraform apply')\n        run: terraform apply -no-color \"plan.out\" \n\n      - uses: actions/github-script@0.9.0\n        if: github.event_name == 'issue_comment' \u0026\u0026 contains(github.event.comment.body, 'terraform apply')\n        env:\n          apply: \"terraform\\n${{ steps.apply.outputs.stdout }}\"\n        with:\n          github-token: ${{ secrets.GITHUB_TOKEN }}\n          script: |\n            const output = `#### Terraform Format and Style 🖌\\`${{ steps.fmt.outcome }}\\`\n            #### Terraform Initialization ⚙️\\`${{ steps.init.outcome }}\\`\n            #### Terraform Validation 🤖${{ steps.validate.outputs.stdout }}\n            #### Terraform apply 📖\\`${{ steps.apply.outcome }}\\`\n            \u003cdetails\u003e\u003csummary\u003eShow apply\u003c/summary\u003e\n            \\`\\`\\`${process.env.apply}\\`\\`\\`\n            \u003c/details\u003e\n            *Pusher: @${{ github.actor }}, Action: \\`${{ github.event_name }}\\`, Workflow: \\`${{ github.workflow }}\\`*`;\n            github.issues.createComment({\n              issue_number: context.issue.number,\n              owner: context.repo.owner,\n              repo: context.repo.repo,\n              body: output\n            })\n```\n\n## References\n- https://github.com/hashicorp/setup-terraform\n- https://docs.github.com/en/actions/guides/storing-workflow-data-as-artifacts\n- https://docs.github.com/en/actions/reference/events-that-trigger-workflows#issue_comment\n- https://github.com/actions/toolkit/issues/501\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsblack4%2Flearning-terraform-github-actions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsblack4%2Flearning-terraform-github-actions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsblack4%2Flearning-terraform-github-actions/lists"}