Skip to content

Commit cef45f7

Browse files
chore(actions): Add workflow that runs Terraform configuration validation (#2887)
* chore: clean up labeler configuration by removing changed-files based labeling * chore(actions): enhance CI workflow and add test secrets configuration * Fix CodeQL concerns * Fix indentation * Fix folder for test stacks Signed-off-by: Viacheslav Kudinov <viacheslav@kudinov.tech> --------- Signed-off-by: Viacheslav Kudinov <viacheslav@kudinov.tech>
1 parent 66b1d20 commit cef45f7

File tree

3 files changed

+156
-14
lines changed

3 files changed

+156
-14
lines changed

.github/labeler.yml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
# Configuration for labeler - https://github.com/actions/labeler
22
"Type: Breaking change":
3-
- head-branch:
3+
- head-branch:
44
- '^breaking/'
55
- '^breaking-'
66

77
"Type: Feature":
8-
- head-branch:
8+
- head-branch:
99
- '^feat/'
1010
- '^feat-'
1111
- '^feature/'
1212
- '^feature-'
1313

1414
"Type: Bug":
15-
- head-branch:
15+
- head-branch:
1616
- '^fix/'
1717
- '^fix-'
1818
- '^bugfix/'
@@ -28,7 +28,7 @@
2828
- '^deprecation-'
2929

3030
"Type: Maintenance":
31-
- head-branch:
31+
- head-branch:
3232
- '^chore/'
3333
- '^chore-'
3434
- '^maintenance/'
@@ -39,18 +39,18 @@
3939
- '^deps-'
4040
- '^dependencies/'
4141
- '^dependencies-'
42-
- changed-files:
43-
- any-glob-to-any-file:
44-
- .github/workflows/**
45-
- .github/labeler.yml
46-
- .github/dependabot.yml
47-
- .github/release.yml
42+
# - changed-files:
43+
# - any-glob-to-any-file:
44+
# - .github/workflows/**
45+
# - .github/labeler.yml
46+
# - .github/dependabot.yml
47+
# - .github/release.yml
4848

4949
"Type: Documentation":
5050
- head-branch:
5151
- '^docs/'
5252
- '^docs-'
5353
- '^doc/'
5454
- '^doc-'
55-
- changed-files:
56-
- any-glob-to-any-file: 'website/**'
55+
# - changed-files:
56+
# - any-glob-to-any-file: 'website/**'

.github/workflows/ci.yml

Lines changed: 117 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,134 @@ on:
55
branches: [main]
66
pull_request: {}
77

8+
permissions:
9+
contents: read # for actions/checkout
10+
11+
env:
12+
test_stacks_directory: test_tf_stacks
13+
814
jobs:
915
ci:
16+
name: Continuous Integration
1017
runs-on: ubuntu-latest
1118
env:
12-
GITHUB_TEST_ORGANIZATION: 'kfcampbell-terraform-provider'
19+
GITHUB_TEST_ORGANIZATION: kfcampbell-terraform-provider
1320
steps:
1421
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
1522
- uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0
1623
with:
17-
go-version-file: 'go.mod'
24+
go-version-file: go.mod
1825
cache: true
1926
- run: make tools
2027
- run: make lint
2128
- run: make website-lint
2229
- run: make build
2330
- run: make test
31+
32+
generate-matrix:
33+
name: Generate matrix for test stacks
34+
runs-on: ubuntu-latest
35+
outputs:
36+
matrix: ${{ steps.set-matrix.outputs.matrix }}
37+
has-tests: ${{ steps.set-matrix.outputs.has-tests }}
38+
steps:
39+
- name: Checkout
40+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
41+
42+
- name: Generate matrix
43+
id: set-matrix
44+
run: |
45+
if [ -d "${{ env.test_stacks_directory }}" ]; then
46+
# find all directories and validate their names
47+
VALID_TESTS=()
48+
INVALID_TESTS=()
49+
50+
while IFS= read -r dir; do
51+
dirname=$(basename "$dir")
52+
# validate that directory name only contains alphanumeric, hyphens, underscores, and dots
53+
if [[ "$dirname" =~ ^[a-zA-Z0-9_.-]+$ ]]; then
54+
VALID_TESTS+=("$dirname")
55+
else
56+
INVALID_TESTS+=("$dirname")
57+
fi
58+
done < <(find ${{ env.test_stacks_directory }} -mindepth 1 -maxdepth 1 -type d)
59+
60+
# report invalid directory names if any
61+
if [ ${#INVALID_TESTS[@]} -gt 0 ]; then
62+
echo "::warning::Invalid test directory names found (must contain only alphanumeric, hyphens, underscores, and dots):"
63+
printf ' - %s (will be skipped)\n' "${INVALID_TESTS[@]}"
64+
fi
65+
66+
# create JSON array from valid tests
67+
if [ ${#VALID_TESTS[@]} -gt 0 ]; then
68+
TESTS=$(printf '%s\n' "${VALID_TESTS[@]}" | jq -R -s -c 'split("\n")[:-1]')
69+
echo "matrix=${TESTS}" >> $GITHUB_OUTPUT
70+
echo "has-tests=true" >> $GITHUB_OUTPUT
71+
echo "Found valid test directories: ${TESTS}"
72+
else
73+
echo "matrix=[]" >> $GITHUB_OUTPUT
74+
echo "has-tests=false" >> $GITHUB_OUTPUT
75+
echo "No valid test directories found"
76+
fi
77+
else
78+
echo "Test directory ${{ env.test_stacks_directory }} does not exist"
79+
echo "matrix=[]" >> $GITHUB_OUTPUT
80+
echo "has-tests=false" >> $GITHUB_OUTPUT
81+
fi
82+
83+
tests:
84+
name: Run tests for Terraform test stacks
85+
needs: [ci, generate-matrix]
86+
if: ${{ needs.generate-matrix.outputs.has-tests == 'true' }} # only run if there are some test stacks
87+
runs-on: ubuntu-latest
88+
89+
strategy:
90+
fail-fast: false
91+
matrix:
92+
tests: ${{ fromJson(needs.generate-matrix.outputs.matrix) }}
93+
94+
steps:
95+
- name: Checkout
96+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
97+
98+
- name: Setup Go
99+
uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0
100+
with:
101+
go-version-file: go.mod
102+
cache: true
103+
104+
- name: Build provider
105+
run: go build -o terraform-provider-github
106+
107+
- name: Setup dev overrides
108+
run: |
109+
ROOT_DIR=$(pwd)
110+
cat > ~/.terraformrc << EOF
111+
provider_installation {
112+
dev_overrides {
113+
"integrations/github" = "${ROOT_DIR}"
114+
}
115+
direct {}
116+
}
117+
EOF
118+
119+
- name: Verify dev overrides setup
120+
run: cat ~/.terraformrc
121+
122+
- name: Setup Terraform
123+
uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3.1.2
124+
with:
125+
terraform_version: 1.x
126+
127+
- name: Check Terraform version
128+
run: terraform version
129+
130+
- name: Terraform init
131+
continue-on-error: true # continue even if init fails
132+
run: terraform -chdir=./${{ env.test_stacks_directory }}/${{ matrix.tests }} init
133+
134+
- name: Terraform validate
135+
run: terraform -chdir=./${{ env.test_stacks_directory }}/${{ matrix.tests }} validate
136+
137+
- name: Clean up
138+
run: rm -f ~/.terraformrc terraform-provider-github
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
terraform {
2+
required_providers {
3+
github = {
4+
source = "integrations/github"
5+
}
6+
}
7+
}
8+
9+
provider "github" {
10+
token = "fake_token_for_validation"
11+
}
12+
13+
# Test both resources with different configurations
14+
resource "github_actions_secret" "test" {
15+
repository = "test_repo"
16+
secret_name = "test_secret"
17+
plaintext_value = "test_value"
18+
destroy_on_drift = true
19+
}
20+
21+
resource "github_actions_organization_secret" "test" {
22+
secret_name = "org_secret"
23+
encrypted_value = "dGVzdA=="
24+
visibility = "private"
25+
destroy_on_drift = false
26+
}
27+

0 commit comments

Comments
 (0)