-
-
Notifications
You must be signed in to change notification settings - Fork 24
136 lines (114 loc) · 4.43 KB
/
terraform--ops-test.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
name: Terraform -- Linode-OPS-Test
on:
pull_request:
branches:
- main
paths:
- 'terraform/ops-test/**'
workflow_dispatch:
defaults:
run:
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
terraform-format:
if:
github.event_name == 'pull_request' || github.event_name ==
'workflow_dispatch'
runs-on: ubuntu-latest
name: Terraform Format
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4
# This is only for the GitHub Actions runner, not Terraform Cloud
- name: Setup Terraform
uses: hashicorp/setup-terraform@633666f66e0061ca3b725c73b2ec20cd13a8fdd1 # v2
- name: Terraform Format
run: make fmt
working-directory: terraform
terraform-upgrade-test:
if:
github.event_name == 'pull_request' || github.event_name ==
'workflow_dispatch'
runs-on: ubuntu-latest
name: Terraform Upgrade Test
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4
# This is only for the GitHub Actions runner, not Terraform Cloud
- name: Setup Terraform
uses: hashicorp/setup-terraform@633666f66e0061ca3b725c73b2ec20cd13a8fdd1 # v2
with:
cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}
- name: Terraform Upgrade Test
run: terraform init -upgrade && terraform plan
working-directory: terraform/ops-test
terraform-cloud-speculative-run:
if:
github.event_name == 'pull_request' || github.event_name ==
'workflow_dispatch'
runs-on: ubuntu-latest
name: Terraform Cloud Speculative Run
permissions:
contents: read
pull-requests: write
env:
TF_CLOUD_ORGANIZATION: freecodecamp
TF_API_TOKEN: ${{ secrets.TF_API_TOKEN }}
TF_WORKSPACE: tfws-ops-test
TF_LOG: ERROR
CONFIG_DIRECTORY: terraform/ops-test
steps:
- name: Checkout
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4
- name: Terraform Cloud Upload Configuration
uses: hashicorp/tfc-workflows-github/actions/upload-configuration@a9b5237abdfa0d0510ad3444906147fa424bbdd9 # v1.0.4
id: upload
with:
workspace: ${{ env.TF_WORKSPACE }}
directory: ${{ env.CONFIG_DIRECTORY }}
speculative: true
- name: Terraform Cloud Create Speculative Run
uses: hashicorp/tfc-workflows-github/actions/create-run@a9b5237abdfa0d0510ad3444906147fa424bbdd9 # v1.0.4
id: run
with:
workspace: ${{ env.TF_WORKSPACE }}
configuration_version:
${{ steps.upload.outputs.configuration_version_id }}
plan_only: true
message: 'Triggered From GitHub Actions CI ${{ github.sha }}'
- name: Terraform Cloud Plan Output
uses: hashicorp/tfc-workflows-github/actions/plan-output@a9b5237abdfa0d0510ad3444906147fa424bbdd9 # v1.0.4
id: plan-output
with:
plan: ${{ steps.run.outputs.plan_id }}
- name: Find Comment
if: github.event_name == 'pull_request'
uses: peter-evans/find-comment@a54c31d7fa095754bfef525c0c8e5e5674c4b4b1 # v2
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: Run Details - ${{ env.TF_WORKSPACE }}
- name: Create or update comment
if: github.event_name == 'pull_request'
uses: peter-evans/create-or-update-comment@c6c9a1a66007646a28c153e2a8580a5bad27bcfa # v3
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
edit-mode: replace
body: |
Run Details - ${{ env.TF_WORKSPACE }}
**Terraform Cloud Plan Output**
```
Plan: ${{ steps.plan-output.outputs.add }} to add, ${{ steps.plan-output.outputs.change }} to change, ${{ steps.plan-output.outputs.destroy }} to destroy.
```
**Details : <${{ steps.run.outputs.run_link }}>**
###### :yellow_circle: **Warning:** Merging these changes WILL NOT trigger any further Terraform Cloud runs, you will need to APPLY these changes from your local workspace or TFC Dashboard.