Skip to content

Commit 3dd2262

Browse files
authored
Adding docs and examples (#2)
- Added new variables - Updated AMIs - Added pipeline.yml to test the Terraform
1 parent 9379ba4 commit 3dd2262

49 files changed

Lines changed: 1766 additions & 38 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.buildkite/pipeline.yml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
steps:
2+
- group: ":terraform: Root Module"
3+
steps:
4+
- label: ":terraform: Format Check"
5+
command: ".buildkite/scripts/format-check.sh"
6+
if_changed: "**.tf"
7+
plugins:
8+
- docker#v5.11.0:
9+
image: "hashicorp/terraform:1.13"
10+
workdir: "/workdir"
11+
entrypoint: "/bin/sh"
12+
13+
- label: ":terraform: Validate"
14+
command: ".buildkite/scripts/validate.sh"
15+
if_changed:
16+
- "*.tf"
17+
- "*.tfvars"
18+
- "scripts/*"
19+
plugins:
20+
- docker#v5.11.0:
21+
image: "hashicorp/terraform:1.13"
22+
workdir: "/workdir"
23+
entrypoint: "/bin/sh"
24+
25+
- label: ":lint-roller: TFLint"
26+
command: ".buildkite/scripts/tflint.sh"
27+
if_changed:
28+
- "*.tf"
29+
- ".tflint.hcl"
30+
plugins:
31+
- docker#v5.11.0:
32+
image: "ghcr.io/terraform-linters/tflint:latest"
33+
workdir: "/workdir"
34+
entrypoint: "/bin/sh"
35+
36+
- label: ":shield: Security Scan"
37+
command: ".buildkite/scripts/tfsec.sh"
38+
if_changed: "*.tf"
39+
plugins:
40+
- docker#v5.11.0:
41+
image: "aquasec/tfsec:latest"
42+
workdir: "/workdir"
43+
entrypoint: "/bin/sh"
44+
45+
- label: ":page_facing_up: Documentation Check"
46+
command: ".buildkite/scripts/docs-check.sh"
47+
if_changed:
48+
- "*.tf"
49+
- "README.md"
50+
plugins:
51+
- docker#v5.11.0:
52+
image: "quay.io/terraform-docs/terraform-docs:latest"
53+
workdir: "/workdir"
54+
entrypoint: "/bin/sh"
55+
56+
- group: ":terraform: Examples"
57+
steps:
58+
- label: ":terraform: Format Check Examples"
59+
command: ".buildkite/scripts/examples-format-check.sh"
60+
if_changed: "examples/**"
61+
plugins:
62+
- docker#v5.11.0:
63+
image: "hashicorp/terraform:1.13"
64+
workdir: "/workdir"
65+
entrypoint: "/bin/sh"
66+
67+
- label: ":terraform: Validate Examples"
68+
command: ".buildkite/scripts/examples-validate.sh"
69+
if_changed: "examples/**"
70+
plugins:
71+
- docker#v5.11.0:
72+
image: "hashicorp/terraform:1.13"
73+
workdir: "/workdir"
74+
entrypoint: "/bin/sh"
75+
76+
- label: ":lint-roller: TFLint Examples"
77+
command: ".buildkite/scripts/examples-tflint.sh"
78+
if_changed: "examples/**"
79+
plugins:
80+
- docker#v5.11.0:
81+
image: "ghcr.io/terraform-linters/tflint:latest"
82+
workdir: "/workdir"
83+
entrypoint: "/bin/sh"

.buildkite/scripts/docs-check.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
# Install git if not present (needed for git diff)
5+
if ! command -v git &> /dev/null; then
6+
apk add --no-cache git
7+
fi
8+
9+
echo "Generating documentation..."
10+
echo "Current commit: $(git rev-parse HEAD 2>/dev/null || echo 'not a git repo')"
11+
echo "README.md before generation:"
12+
md5sum README.md || true
13+
14+
# Create a backup to compare
15+
cp README.md README.md.bak
16+
17+
terraform-docs markdown table . --output-file README.md --output-mode inject
18+
19+
echo "README.md after generation:"
20+
md5sum README.md || true
21+
22+
echo "Checking for documentation changes..."
23+
if ! diff -q README.md.bak README.md > /dev/null 2>&1; then
24+
echo "❌ Documentation is out of date."
25+
echo "Run: terraform-docs markdown table . --output-file README.md --output-mode inject"
26+
echo ""
27+
echo "Differences found:"
28+
diff -u README.md.bak README.md | head -100 || true
29+
rm README.md.bak
30+
exit 1
31+
fi
32+
33+
rm README.md.bak
34+
echo "✅ Documentation is up to date"
35+
exit 0
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/sh
2+
set -euo pipefail
3+
4+
EXAMPLE_DIR="$1"
5+
6+
echo "Checking Terraform formatting for example: ${EXAMPLE_DIR}"
7+
8+
cd "examples/${EXAMPLE_DIR}"
9+
10+
if ! terraform fmt -check -recursive; then
11+
echo "❌ Terraform files in ${EXAMPLE_DIR} are not formatted."
12+
echo "Run: cd examples/${EXAMPLE_DIR} && terraform fmt -recursive"
13+
exit 1
14+
fi
15+
16+
echo "✅ Example ${EXAMPLE_DIR} is properly formatted"
17+
exit 0
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/sh
2+
set -euo pipefail
3+
4+
EXAMPLE_DIR="$1"
5+
6+
echo "Running TFLint for example: ${EXAMPLE_DIR}"
7+
8+
cd "examples/${EXAMPLE_DIR}"
9+
10+
echo "Initializing TFLint..."
11+
tflint --init
12+
13+
echo "Running TFLint..."
14+
tflint
15+
16+
echo "✅ TFLint checks passed for ${EXAMPLE_DIR}"
17+
exit 0
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/sh
2+
set -euo pipefail
3+
4+
EXAMPLE_DIR="$1"
5+
6+
echo "Validating example: ${EXAMPLE_DIR}"
7+
8+
cd "examples/${EXAMPLE_DIR}"
9+
10+
echo "Initializing Terraform..."
11+
terraform init -backend=false
12+
13+
echo "Validating configuration..."
14+
terraform validate
15+
16+
echo "✅ Example ${EXAMPLE_DIR} validated successfully"
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/sh
2+
set -euo pipefail
3+
4+
echo "--- Running terraform fmt check on all examples"
5+
6+
EXAMPLES="basic complete existing-vpc scheduled-scaling spot-instances"
7+
EXIT_CODE=0
8+
9+
for example in $EXAMPLES; do
10+
echo "+++ Checking example: ${example}"
11+
cd "examples/${example}"
12+
13+
if ! terraform fmt -check -recursive; then
14+
echo "^^^ +++"
15+
echo "❌ Terraform files in ${example} are not formatted."
16+
echo "Run: cd examples/${example} && terraform fmt -recursive"
17+
EXIT_CODE=1
18+
else
19+
echo "✅ Example ${example} is properly formatted"
20+
fi
21+
22+
cd ../..
23+
done
24+
25+
if [ $EXIT_CODE -ne 0 ]; then
26+
echo "--- :x: One or more examples failed format check"
27+
exit 1
28+
fi
29+
30+
echo "--- :white_check_mark: All examples passed format check"
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/sh
2+
set -euo pipefail
3+
4+
echo "--- Running tflint on all examples"
5+
6+
EXAMPLES="basic complete existing-vpc scheduled-scaling spot-instances"
7+
EXIT_CODE=0
8+
9+
for example in $EXAMPLES; do
10+
echo "+++ Running tflint on example: ${example}"
11+
cd "examples/${example}"
12+
13+
echo "Initializing tflint..."
14+
if ! tflint --init; then
15+
echo "^^^ +++"
16+
echo "❌ tflint init failed for ${example}"
17+
EXIT_CODE=1
18+
cd ../..
19+
continue
20+
fi
21+
22+
echo "Running tflint..."
23+
if ! tflint; then
24+
echo "^^^ +++"
25+
echo "❌ tflint failed for ${example}"
26+
EXIT_CODE=1
27+
else
28+
echo "✅ Example ${example} passed tflint"
29+
fi
30+
31+
cd ../..
32+
done
33+
34+
if [ $EXIT_CODE -ne 0 ]; then
35+
echo "--- :x: One or more examples failed tflint"
36+
exit 1
37+
fi
38+
39+
echo "--- :white_check_mark: All examples passed tflint"
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/sh
2+
set -euo pipefail
3+
4+
echo "--- Running terraform validate on all examples"
5+
6+
EXAMPLES="basic complete existing-vpc scheduled-scaling spot-instances"
7+
EXIT_CODE=0
8+
9+
for example in $EXAMPLES; do
10+
echo "+++ Validating example: ${example}"
11+
cd "examples/${example}"
12+
13+
echo "Running terraform init..."
14+
if ! terraform init -backend=false; then
15+
echo "^^^ +++"
16+
echo "❌ Terraform init failed for ${example}"
17+
EXIT_CODE=1
18+
cd ../..
19+
continue
20+
fi
21+
22+
echo "Running terraform validate..."
23+
if ! terraform validate; then
24+
echo "^^^ +++"
25+
echo "❌ Terraform validation failed for ${example}"
26+
EXIT_CODE=1
27+
else
28+
echo "✅ Example ${example} validated successfully"
29+
fi
30+
31+
cd ../..
32+
done
33+
34+
if [ $EXIT_CODE -ne 0 ]; then
35+
echo "--- :x: One or more examples failed validation"
36+
exit 1
37+
fi
38+
39+
echo "--- :white_check_mark: All examples passed validation"

.buildkite/scripts/format-check.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
echo "Checking Terraform formatting..."
5+
6+
if ! terraform fmt -check -recursive; then
7+
echo "❌ Terraform files are not formatted."
8+
echo "Run: terraform fmt -recursive"
9+
exit 1
10+
fi
11+
12+
echo "✅ All Terraform files are properly formatted"
13+
exit 0

.buildkite/scripts/tflint.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh
2+
3+
echo "Initializing TFLint..."
4+
tflint --init
5+
6+
echo "Running TFLint..."
7+
tflint
8+
9+
echo "✅ TFLint checks passed"
10+
exit 0

0 commit comments

Comments
 (0)