Skip to content

ci: add Terraform mock unit tests for all templates for #71 (Phase 2)#102

Merged
rfay merged 1 commit intomainfrom
20260430_rfay_ci-phase2-mock-tests
Apr 30, 2026
Merged

ci: add Terraform mock unit tests for all templates for #71 (Phase 2)#102
rfay merged 1 commit intomainfrom
20260430_rfay_ci-phase2-mock-tests

Conversation

@rfay
Copy link
Copy Markdown
Member

@rfay rfay commented Apr 30, 2026

The Issue

Part of #71 (automated testing). Phase 2: Terraform mock unit tests that run with no live infrastructure.

How This PR Solves The Issue

Adds a tests/validate.tftest.hcl file to each of the three templates using Terraform 1.7+ mock providers. The tests run entirely locally — no Coder server, no Docker, no credentials needed.

Tests per template:

Test user-defined-web drupal-core freeform
Plan succeeds with defaults
docker_container created when start_count=1
cpu below minimum (0) rejected
cpu above maximum (33) rejected
memory below minimum (1 GB) rejected
memory above maximum (129 GB) rejected
enable_adminer off by default
enable_adminer creates coder_app

One non-obvious mock requirement: vscode_extensions.value is passed through jsondecode() in locals across all three templates, so the coder_parameter mock overrides the default random string with "[]" (a valid empty JSON array).

drupal-core requires cache_path in every run block since it has no default (tracked in #99 for removal).

Also adds terraform test step to the existing validate workflow matrix job and make test-templates for local use.

Manual Testing Instructions

# Run all template tests locally (requires terraform in PATH)
make test-templates

# Or per-template
cd user-defined-web && terraform test
cd drupal-core && terraform test
cd freeform && terraform test

Automated Testing Overview

This PR extends the workflow added in #100. The terraform test step runs after terraform validate in the same matrix job for each template. CI will run these 20 tests on every push and PR.

Release/Deployment Notes

No impact on deployed templates or workspaces. CI-only change.

Adds tests/ directory to each template with validate.tftest.hcl using
Terraform 1.7+ mock providers. Tests cover: plan succeeds with defaults,
docker_container created when start_count=1, cpu/memory validation bounds.
freeform also tests enable_adminer toggle. drupal-core supplies the
required cache_path variable in each run block.

Adds terraform test step to the validate workflow (runs after validate in
the same matrix job) and make test-templates for local use.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@rfay rfay merged commit 6b0f23e into main Apr 30, 2026
4 checks passed
@rfay rfay deleted the 20260430_rfay_ci-phase2-mock-tests branch April 30, 2026 19:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant