Skip to content

Commit 9776bf6

Browse files
committed
writing plan to comment
1 parent cdf8ce8 commit 9776bf6

1 file changed

Lines changed: 42 additions & 30 deletions

File tree

.github/workflows/terraform-plan.yaml

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,52 @@ name: Deploy IAM Resources to AWS with Terraform
33
on:
44
pull_request:
55
branches:
6-
- main # or any other branch you want to trigger the deployment
6+
- main
77

88
jobs:
99
terraform:
1010
name: Terraform
1111
runs-on: ubuntu-latest
12-
env:
13-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1412

1513
steps:
16-
- name: Checkout code
17-
uses: actions/checkout@v3
18-
19-
- name: Set up Terraform
20-
uses: hashicorp/setup-terraform@v1
21-
with:
22-
terraform_version: 1.0.0 # Specify the Terraform version
23-
24-
- name: Configure AWS Credentials
25-
uses: aws-actions/configure-aws-credentials@v1
26-
with:
27-
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
28-
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
29-
aws-region: us-west-2 # Change to your AWS region
30-
31-
- name: Terraform Init
32-
run: terraform init
33-
34-
- name: Terraform Plan
35-
run: terraform plan
36-
37-
# - name: Terraform Plan
38-
# uses: dflook/terraform-plan@v1
39-
# with:
40-
# path: terraform
41-
42-
14+
- name: Checkout code
15+
uses: actions/checkout@v3
16+
17+
- name: Set up Terraform
18+
uses: hashicorp/setup-terraform@v3
19+
with:
20+
terraform_version: 1.7.3
21+
22+
- name: Configure AWS Credentials
23+
uses: aws-actions/configure-aws-credentials@4
24+
with:
25+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
26+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
27+
aws-region: us-west-2
28+
29+
- name: Terraform Init
30+
run: terraform init
31+
working-directory: ./terraform
32+
33+
- name: Terraform Plan
34+
id: plan
35+
run: |
36+
terraform plan -no-color > plan-output.txt
37+
cat plan-output.txt
38+
working-directory: ./terraform
39+
continue-on-error: true
40+
41+
- name: Comment Plan Output on PR
42+
uses: actions/github-script@v7
43+
if: github.event_name == 'pull_request'
44+
with:
45+
github-token: ${{ secrets.GITHUB_TOKEN }}
46+
script: |
47+
const fs = require('fs');
48+
const planOutput = fs.readFileSync('${{ github.workspace }}/terraform/plan-output.txt', 'utf8');
49+
github.rest.issues.createComment({
50+
issue_number: context.issue.number,
51+
owner: context.repo.owner,
52+
repo: context.repo.name,
53+
body: '### Terraform Plan Output\n' + '```\n' + planOutput + '\n```',
54+
});

0 commit comments

Comments
 (0)