Skip to content

Commit c45780b

Browse files
gAmUssAclaude
andcommitted
Add comprehensive Terraform CI workflow
- Includes format, init, validate, and plan steps - No automatic apply for safety - Comments plan results on pull requests - Uses same Terraform commands as Makefile 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 11d2716 commit c45780b

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed

.github/workflows/terraform-ci.yml

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
name: "Terraform CI"
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- 'terraform/**'
7+
- '.github/workflows/terraform-ci.yml'
8+
push:
9+
branches:
10+
- main
11+
paths:
12+
- 'terraform/**'
13+
- '.github/workflows/terraform-ci.yml'
14+
15+
env:
16+
TF_VERSION: "1.7.5"
17+
18+
jobs:
19+
terraform-ci:
20+
name: "Terraform CI"
21+
runs-on: ubuntu-latest
22+
defaults:
23+
run:
24+
working-directory: ./terraform
25+
26+
# These permissions are needed to interact with GitHub's OIDC Token endpoint
27+
permissions:
28+
contents: read
29+
pull-requests: write
30+
31+
steps:
32+
- name: Checkout
33+
uses: actions/checkout@v4
34+
35+
- name: Setup Terraform
36+
uses: hashicorp/setup-terraform@v3
37+
with:
38+
terraform_version: ${{ env.TF_VERSION }}
39+
40+
- name: Terraform Format
41+
id: fmt
42+
run: terraform fmt -check
43+
continue-on-error: true
44+
45+
- name: Terraform Init
46+
id: init
47+
run: terraform init
48+
env:
49+
CONFLUENT_CLOUD_API_KEY: ${{ secrets.CONFLUENT_CLOUD_API_KEY }}
50+
CONFLUENT_CLOUD_API_SECRET: ${{ secrets.CONFLUENT_CLOUD_API_SECRET }}
51+
TF_VAR_org_id: ${{ secrets.TF_VAR_ORG_ID }}
52+
53+
- name: Terraform Validate
54+
id: validate
55+
run: terraform validate
56+
57+
- name: Terraform Plan
58+
id: plan
59+
run: terraform plan -out=tfplan
60+
env:
61+
CONFLUENT_CLOUD_API_KEY: ${{ secrets.CONFLUENT_CLOUD_API_KEY }}
62+
CONFLUENT_CLOUD_API_SECRET: ${{ secrets.CONFLUENT_CLOUD_API_SECRET }}
63+
TF_VAR_org_id: ${{ secrets.TF_VAR_ORG_ID }}
64+
continue-on-error: true
65+
66+
- name: Update Pull Request
67+
uses: actions/github-script@v7
68+
if: github.event_name == 'pull_request'
69+
with:
70+
github-token: ${{ secrets.GITHUB_TOKEN }}
71+
script: |
72+
const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\`
73+
#### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\`
74+
#### Terraform Validation 🤖\`${{ steps.validate.outcome }}\`
75+
#### Terraform Plan 📖\`${{ steps.plan.outcome }}\`
76+
77+
<details><summary>Show Plan</summary>
78+
79+
\`\`\`terraform
80+
${{ steps.plan.outputs.stdout }}
81+
\`\`\`
82+
83+
</details>
84+
85+
*Pushed by: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`;
86+
87+
github.rest.issues.createComment({
88+
issue_number: context.issue.number,
89+
owner: context.repo.owner,
90+
repo: context.repo.repo,
91+
body: output
92+
})

0 commit comments

Comments
 (0)