-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaction.yml
48 lines (48 loc) · 1.53 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
name: 'Terraform CI'
description: 'Validate and runs a terraform plan'
inputs:
terraform_version:
description: 'Terraform version to use'
required: true
default: '0.14.x'
runs:
using: composite
steps:
- uses: actions/checkout@v2
- uses: hashicorp/setup-terraform@v1
with:
terraform_version: 0.14.x
terraform_wrapper: true
- name: terraform init
shell: bash
run: |
terraform init -input=false \
-backend-config=container_name=$TERRAFORM_BACKEND_TFSTATE_CONTAINER_NAME \
-backend-config=key=$TERRAFORM_BACKEND_TFSTATE_NAME \
-backend-config=storage_account_name=$TERRAFORM_BACKEND_TFSTATE_STA_NAME \
-backend-config=resource_group_name=$TERRAFORM_BACKEND_TFSTATE_RG_NAME
- name: terraform plan
shell: bash
run: |
terraform plan -input=false -out tfplan
- name: capture terraform plan
id: tfplan_plain
shell: bash
run: |
# Adds the plan in plain text to a env var called TFPLAN. Used to write the comment in the PR
terraform show -no-color tfplan
- uses: actions/github-script@v5
name: Add plan to PR comment
env:
PR_COMMENT_BODY: |
```hcl
${{ steps.tfplan_plain.outputs.stdout }}
```
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: process.env.PR_COMMENT_BODY
})