79
79
env :
80
80
IMAGE_TAGS : ${{ steps.meta.outputs.tags }}
81
81
run : |
82
+ set -euo pipefail
82
83
IMAGE_TAG=$(echo "$IMAGE_TAGS" | head -n1)
83
84
echo "Testing tools image: $IMAGE_TAG"
84
85
@@ -87,17 +88,71 @@ jobs:
87
88
docker run --rm "$IMAGE_TAG" terraform-docs --version
88
89
docker run --rm "$IMAGE_TAG" tflint --version
89
90
90
- # Functional tests
91
- echo "Testing basic functionality..."
91
+ # Optional extra versions (quick smoke)
92
+ docker run --rm "$IMAGE_TAG" checkov --version || true
93
+ docker run --rm "$IMAGE_TAG" trivy --version || true
94
+
95
+ # Create a minimal, self-contained Terraform module for functional tests
96
+ TMP_DIR="$(mktemp -d)"
97
+ trap 'rm -rf "$TMP_DIR"' EXIT
98
+ cat > "$TMP_DIR/main.tf" << 'EOF'
99
+ terraform {
100
+ required_version = ">= 1.3.0"
101
+ }
102
+ variable "example_var" {
103
+ description = "An example variable"
104
+ type = string
105
+ default = "test"
106
+ }
107
+ output "example_output" {
108
+ description = "An example output"
109
+ value = var.example_var
110
+ }
111
+ EOF
112
+ echo "# Test Module" > "$TMP_DIR/README.md"
113
+
114
+ echo "Testing terraform fmt..."
115
+
116
+ docker run --rm \
117
+ -v "$TMP_DIR:/workspace" \
118
+ -w /workspace \
119
+ "$IMAGE_TAG" \
120
+ terraform fmt -check -diff
121
+
122
+ echo "Testing terraform init/validate..."
123
+
124
+ docker run --rm \
125
+ -v "$TMP_DIR:/workspace" \
126
+ -w /workspace \
127
+ "$IMAGE_TAG" \
128
+ terraform init -backend=false
129
+
92
130
docker run --rm \
93
- -v "$(pwd)/tests :/workspace" \
131
+ -v "$TMP_DIR :/workspace" \
94
132
-w /workspace \
95
133
"$IMAGE_TAG" \
96
- terraform init -backend=false \
97
- || echo "terraform init test passed"
134
+ terraform validate
135
+
136
+ echo "Testing terraform-docs..."
137
+
138
+ docker run --rm \
139
+ -v "$TMP_DIR:/workspace" \
140
+ -w /workspace \
141
+ "$IMAGE_TAG" \
142
+ terraform-docs markdown table . --output-file README.md
143
+
144
+ echo "Testing tflint..."
145
+
146
+ docker run --rm \
147
+ -v "$TMP_DIR:/workspace" \
148
+ -w /workspace \
149
+ "$IMAGE_TAG" \
150
+ tflint --init
151
+
98
152
docker run --rm \
99
- -v "$(pwd) :/workspace" \
153
+ -v "$TMP_DIR :/workspace" \
100
154
-w /workspace \
101
155
"$IMAGE_TAG" \
102
- terraform fmt -check -diff \
103
- || echo "terraform fmt test completed"
156
+ tflint
157
+
158
+ echo "All functional tests passed!"
0 commit comments