Skip to content

Commit 2063b9f

Browse files
committed
ci: add Terraform integration test with trap-based cleanup
Extend CI to run a real Terraform integration flow against Ona using the examples configuration. Changes: - set up Terraform in CI - build local provider binary and wire it via Terraform dev_overrides - run terraform init/apply in examples - use EXIT trap to always run terraform destroy and preserve failure status Why: - verify provider behavior against real API in CI - ensure test runner resources are cleaned up reliably
1 parent ffd2422 commit 2063b9f

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,54 @@ jobs:
3232

3333
- name: Build
3434
run: go build ./...
35+
36+
- name: Set up Terraform
37+
uses: hashicorp/setup-terraform@v4.0.0
38+
with:
39+
terraform_wrapper: false
40+
41+
- name: Terraform Integration (apply/destroy runner)
42+
env:
43+
GITPOD_API_KEY: ${{ secrets.GITPOD_API_KEY }}
44+
run: |
45+
set -euo pipefail
46+
47+
mkdir -p dist
48+
go build -o dist/terraform-provider-ona .
49+
50+
cat > "${RUNNER_TEMP}/terraformrc" <<EOF
51+
provider_installation {
52+
dev_overrides {
53+
"combor/ona" = "${GITHUB_WORKSPACE}/dist"
54+
}
55+
direct {}
56+
}
57+
EOF
58+
export TF_CLI_CONFIG_FILE="${RUNNER_TEMP}/terraformrc"
59+
60+
RUNNER_NAME="ci-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}"
61+
tf_initialized=0
62+
63+
cleanup() {
64+
status=$?
65+
trap - EXIT
66+
set +e
67+
68+
if [ "${tf_initialized}" -eq 1 ]; then
69+
terraform -chdir=examples destroy -auto-approve -input=false \
70+
-var "runner_name=${RUNNER_NAME}"
71+
destroy_status=$?
72+
if [ "${status}" -eq 0 ] && [ "${destroy_status}" -ne 0 ]; then
73+
status="${destroy_status}"
74+
fi
75+
fi
76+
77+
exit "${status}"
78+
}
79+
trap cleanup EXIT
80+
81+
terraform -chdir=examples init -input=false
82+
tf_initialized=1
83+
84+
terraform -chdir=examples apply -auto-approve -input=false \
85+
-var "runner_name=${RUNNER_NAME}"

0 commit comments

Comments
 (0)