diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7734905..ec66eda 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,6 +30,13 @@ jobs: directory: ${{ env.CONFIG_DIRECTORY }} speculative: true + - name: Initialize Terraform Backend + run: terraform init -reconfigure + env: + TF_CLOUD_ORGANIZATION: ${{ env.TF_CLOUD_ORGANIZATION }} + TF_API_TOKEN: ${{ env.TF_API_TOKEN }} + TF_WORKSPACE: ${{ env.TF_WORKSPACE }} + - name: Create Plan Run uses: hashicorp/tfc-workflows-github/actions/create-run@v1.0.0 id: plan-run @@ -59,14 +66,22 @@ jobs: *Pushed by: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`; if (context.payload.pull_request) { - await github.rest.issues.createComment({ - issue_number: context.payload.pull_request.number, + await github.rest.issues.updateComment({ + comment_id: context.payload.pull_request.issue_url.split('/').pop(), owner: context.repo.owner, repo: context.repo.repo, body: output }); } else { - console.log('No pull request context found.'); + const response = await github.rest.pulls.create({ + owner: context.repo.owner, + repo: context.repo.repo, + title: 'Automated Pull Request', + head: '${{ github.actor }}:main', + base: 'main', + body: output + }); + console.log('Pull request created:', response.data.html_url); } - name: Terraform Plan Status