Skip to content

Commit 7d81ede

Browse files
committed
feat: initial terraform configuration for GitHub org management
1 parent a5503c3 commit 7d81ede

20 files changed

+1342
-0
lines changed

.checkov.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
block-list-secret-scan: []
2+
compact: true
3+
directory:
4+
- .
5+
download-external-modules: false
6+
evaluate-variables: true
7+
framework:
8+
- all
9+
output:
10+
- cli
11+
quiet: true
12+
soft-fail: true
13+
summary-position: top

.github/workflows/opentofu.yml

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
name: OpenTofu Tests, Plan & Apply
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
push:
8+
branches:
9+
- main
10+
11+
env:
12+
SOPS_AGE_KEY: ${{ secrets.SOPS_AGE_KEY }}
13+
14+
jobs:
15+
test:
16+
name: Pre-commit Tests
17+
runs-on: ubuntu-latest
18+
container:
19+
image: ghcr.io/makeitworkcloud/runner:latest
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v4
23+
with:
24+
fetch-depth: 0
25+
26+
- name: Initialize OpenTofu
27+
run: tofu init -backend=false
28+
29+
- name: Run tests
30+
run: make test
31+
32+
- name: Show README.md changes after pre-commit
33+
run: |
34+
echo "=== Git status after pre-commit ==="
35+
git status --porcelain
36+
echo "=== Git diff after pre-commit ==="
37+
git diff HEAD
38+
echo "=== README.md content after pre-commit ==="
39+
cat README.md | head -50
40+
41+
plan:
42+
name: OpenTofu Plan
43+
runs-on: ubuntu-latest
44+
container:
45+
image: ghcr.io/makeitworkcloud/runner:latest
46+
if: github.event_name == 'pull_request'
47+
needs: [test]
48+
steps:
49+
- name: Checkout
50+
uses: actions/checkout@v4
51+
52+
- name: OpenTofu Plan
53+
id: plan
54+
run: |
55+
# Run make plan - Makefile will handle writing plan to file
56+
make plan || true
57+
58+
# Extract only the plan summary - what will actually change
59+
# Start from "OpenTofu will perform" and take everything after
60+
sed -n '/OpenTofu will perform the following actions:/,$p' plan-output.txt > plan-filtered.txt
61+
62+
# If no changes, look for "No changes" message
63+
if [ ! -s plan-filtered.txt ]; then
64+
grep -A 2 "No changes" plan-output.txt > plan-filtered.txt || echo "No plan output found" > plan-filtered.txt
65+
fi
66+
67+
# Limit output to last 1000 lines to prevent "Argument list too long" error
68+
# The plan summary with actual changes is at the end, that's what matters
69+
tail -n 1000 plan-filtered.txt > plan-filtered-truncated.txt
70+
mv plan-filtered-truncated.txt plan-filtered.txt
71+
72+
- name: Comment PR with Plan
73+
uses: actions/github-script@v7
74+
if: github.event_name == 'pull_request'
75+
with:
76+
github-token: ${{ secrets.GITHUB_TOKEN }}
77+
script: |
78+
const fs = require('fs');
79+
const planOutput = fs.readFileSync('plan-filtered.txt', 'utf8');
80+
81+
const output = `#### OpenTofu Plan 📋
82+
\`\`\`
83+
${planOutput}
84+
\`\`\`
85+
`;
86+
github.rest.issues.createComment({
87+
issue_number: context.issue.number,
88+
owner: context.repo.owner,
89+
repo: context.repo.repo,
90+
body: output
91+
});
92+
93+
apply:
94+
name: OpenTofu Apply
95+
runs-on: ubuntu-latest
96+
container:
97+
image: ghcr.io/makeitworkcloud/runner:latest
98+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
99+
needs: [test]
100+
environment: production
101+
steps:
102+
- name: Checkout
103+
uses: actions/checkout@v4
104+
105+
- name: OpenTofu Apply
106+
run: make apply

.gitignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# vim swap files
2+
**/*.sw[po]
3+
4+
# don't commit terraform state or lock. the repo code is the only state we care about.
5+
# the provider state cache is auto-upgraded by default to ensure compatibility with upstream cloud provider APIs
6+
**/.terraform.lock.hcl
7+
**/.terraform
8+
9+
# IDE Folders
10+
**/.vscode
11+
12+
# Mac Finder cache
13+
**/.DS_Store
14+
15+
# Plan output
16+
plan-output.txt

.pre-commit-config.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v6.0.0
4+
hooks:
5+
- id: check-case-conflict
6+
- id: check-merge-conflict
7+
- id: check-symlinks
8+
- id: check-vcs-permalinks
9+
- id: destroyed-symlinks
10+
- id: detect-private-key
11+
- id: mixed-line-ending
12+
- id: trailing-whitespace
13+
- repo: https://github.com/antonbabenko/pre-commit-terraform
14+
rev: v1.100.0
15+
hooks:
16+
- id: terraform_validate
17+
args:
18+
- --hook-config=--retry-once-with-cleanup=true
19+
- --args=-no-color
20+
- --tf-init-args=-reconfigure
21+
- --tf-init-args=-upgrade
22+
- id: terraform_tflint
23+
args:
24+
- --args=--minimum-failure-severity=error
25+
- --args=--config=__GIT_WORKING_DIR__/.tflint.hcl
26+
- id: terraform_checkov
27+
args:
28+
- --args=--config-file __GIT_WORKING_DIR__/.checkov.yml
29+
- id: terraform_fmt
30+
args:
31+
- --args=-no-color
32+
- --args=-diff
33+
- --args=-recursive
34+
- id: terraform_docs
35+
args:
36+
- --args=--config=.terraform-docs.yml

.sops.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
creation_rules:
3+
- age: age152ek83tm4fj5u70r3fecytn4kg7c5xca24erjchxexx4pfqg6das7q763l

.terraform-docs.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
formatter: "markdown"
2+
3+
output:
4+
file: "README.md"
5+
mode: replace
6+
7+
settings:
8+
color: false
9+
lockfile: false
10+
11+
sort:
12+
enabled: true
13+
by: name
14+
15+
# recursive can't be enabled until this bug is fixed:
16+
# https://github.com/terraform-docs/terraform-docs/issues/654
17+
recursive:
18+
enabled: false

.tflint.hcl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
plugin "terraform" {
2+
enabled = true
3+
preset = "recommended"
4+
}
5+
6+
rule "terraform_required_providers" {
7+
enabled = false
8+
}
9+
10+
rule "terraform_required_version" {
11+
enabled = false
12+
}

.tfsec.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
min_required_version: 1.28.1
3+
minimum_severity: LOW
4+
severity_overrides: {}
5+
exclude: []

0 commit comments

Comments
 (0)