-
Notifications
You must be signed in to change notification settings - Fork 0
103 lines (82 loc) · 2.65 KB
/
terraform-dev.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
name: "Terraform Development"
on:
push:
branches-ignore:
- 'main'
env:
name: dev
TF_CLOUD_ORGANIZATION: "${{ vars.TF_CLOUD_ORGANIZATION }}"
TF_API_TOKEN: "${{ secrets.TF_API_TOKEN }}"
TF_WORKSPACE: "${{ vars.TF_WORKSPACE }}"
defaults:
run:
working-directory: ./terraform
shell: bash
jobs:
terraform:
name: "Terraform Apply (Development)"
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./terraform
shell: bash
permissions:
contents: read
pull-requests: write
environment: dev
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Terraform
id: tfc-setup
uses: hashicorp/setup-terraform@v3
with:
cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}
- name: Terraform fmt
id: fmt
run: terraform fmt -check
continue-on-error: true
- name: Terraform Init
id: init
run: terraform init
- name: Terraform Validate
id: validate
run: terraform validate -no-color
- name: Terraform Apply
id: apply
run: terraform apply -no-color -input=false -auto-approve
continue-on-error: true
- name: truncate terraform apply result
run: |
apply=$(cat <<'EOF'
${{ format('{0}{1}', steps.apply.outputs.stdout, steps.apply.outputs.stderr) }}
EOF
)
echo "APPLY<<EOF" >> $GITHUB_ENV
echo "${apply:0:65536}" | grep >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: Create commit comment
uses: peter-evans/commit-comment@v3
id: cc
env:
APPLY: "terraform\n${{ steps.apply.outputs.stdout }}"
with:
body: |
#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\`
#### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\`
#### Terraform Validation 🤖\`${{ steps.validate.outcome }}\`
<details><summary>Validation Output</summary>
\`\`\`\n
${{ steps.validate.outputs.stdout }}
\`\`\`
</details>
#### Terraform Apply 📖\`${{ steps.apply.outcome }}\`
<details><summary>Show Apply</summary>
\`\`\`\n
${process.env.APPLY}
\`\`\`
</details>
*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`, Working Directory: \`${{ env.tf_actions_working_dir }}\`, Workflow: \`${{ github.workflow }}\`*`;
- name: Check outputs
run: |
echo "Comment ID - ${{ steps.cc.outputs.comment-id }}"