From 82d06f95216aaa8eb13bf5212e0fae9b1923ca9e Mon Sep 17 00:00:00 2001 From: DevelopmentCats Date: Mon, 25 Aug 2025 15:44:35 +0000 Subject: [PATCH 01/10] docs: update contribution guidelines for both module testing procedures --- CONTRIBUTING.md | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 97a33d9f7..6ecd2c4d5 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -124,18 +124,27 @@ This script generates: - Accurate description and usage examples - Correct icon path (usually `../../../../.icons/your-icon.svg`) - Proper tags that describe your module -3. **Create at least one `.tftest.hcl`** to test your module with `terraform test` +3. **Create tests for your module:** + - **New modules**: Create `.tftest.hcl` files and test with `terraform test` + - **Existing modules**: Keep `main.test.ts` files and test with `bun test` + - **Both approaches** are supported 4. **Add any scripts** or additional files your module needs ### 4. Test and Submit ```bash -# Test your module (from the module directory) +# Test your module +# For new modules with .tftest.hcl: +cd registry/[namespace]/modules/[module-name] terraform init -upgrade terraform test -verbose -# Or run all tests in the repo -./scripts/terraform_test_all.sh +# For existing modules with main.test.ts: +bun test registry/[namespace]/modules/[module-name] + +# Run all tests in the repo +bun test # All TypeScript tests +./scripts/terraform_test_all.sh # All Terraform tests # Format code bun run fmt @@ -393,7 +402,9 @@ Example: `https://github.com/coder/registry/compare/main...your-branch?template= ### Every Module Must Have - `main.tf` - Terraform code -- One or more `.tftest.hcl` files - Working tests with `terraform test` +- **Tests** (choose one): + - `.tftest.hcl` files with `terraform test` (preferred for new modules) + - `main.test.ts` file with `bun test` (existing modules) - `README.md` - Documentation with frontmatter ### Every Template Must Have @@ -493,6 +504,6 @@ When reporting bugs, include: 2. **No tests** or broken tests 3. **Hardcoded values** instead of variables 4. **Breaking changes** without defaults -5. **Not running** formatting (`bun run fmt`) and tests (`terraform test`) before submitting +5. **Not running** formatting (`bun run fmt`) and tests (`bun test` or `terraform test`) before submitting Happy contributing! 🚀 From 7469a6ee7c32d4d9c5676c359871428b0d2e1f7b Mon Sep 17 00:00:00 2001 From: DevelopmentCats Date: Mon, 25 Aug 2025 15:44:49 +0000 Subject: [PATCH 02/10] ci: add Terraform tests to CI workflow --- .github/workflows/ci.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 53b912bff..597f8ccf1 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -28,6 +28,8 @@ jobs: run: bun install - name: Run TypeScript tests run: bun test + - name: Run Terraform tests + run: ./scripts/terraform_test_all.sh - name: Run Terraform Validate run: bun terraform-validate validate-style: From a7bad95258a0ea008800f37c183434ce958a7f88 Mon Sep 17 00:00:00 2001 From: DevelopmentCats Date: Mon, 25 Aug 2025 15:46:13 +0000 Subject: [PATCH 03/10] chore: bun run fmt --- CONTRIBUTING.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6ecd2c4d5..f61b1c527 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -143,8 +143,8 @@ terraform test -verbose bun test registry/[namespace]/modules/[module-name] # Run all tests in the repo -bun test # All TypeScript tests -./scripts/terraform_test_all.sh # All Terraform tests +bun test # All TypeScript tests +./scripts/terraform_test_all.sh # All Terraform tests # Format code bun run fmt From 37cde4548a344f6c6b6430d53474e46ddd833864 Mon Sep 17 00:00:00 2001 From: DevelopmentCats Date: Mon, 25 Aug 2025 16:09:51 +0000 Subject: [PATCH 04/10] chore: clarify module requirements --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f61b1c527..c04cf98ef 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -402,7 +402,7 @@ Example: `https://github.com/coder/registry/compare/main...your-branch?template= ### Every Module Must Have - `main.tf` - Terraform code -- **Tests** (choose one): +- **Tests**: - `.tftest.hcl` files with `terraform test` (preferred for new modules) - `main.test.ts` file with `bun test` (existing modules) - `README.md` - Documentation with frontmatter From 2a78dc8ef098e9a40d8d3dc5269156d1d14d35a4 Mon Sep 17 00:00:00 2001 From: DevCats Date: Mon, 25 Aug 2025 13:43:43 -0500 Subject: [PATCH 05/10] chore: add wildcard to tftest.hcl Co-authored-by: Atif Ali --- CONTRIBUTING.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c04cf98ef..c764e492e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -403,8 +403,8 @@ Example: `https://github.com/coder/registry/compare/main...your-branch?template= - `main.tf` - Terraform code - **Tests**: - - `.tftest.hcl` files with `terraform test` (preferred for new modules) - - `main.test.ts` file with `bun test` (existing modules) + - `*.tftest.hcl` files with `terraform test` (to test terraform specific logoc) + - `main.test.ts` file with `bun test` (to test business logic, i.e., `coder_script` to install a package.) - `README.md` - Documentation with frontmatter ### Every Template Must Have From 6a98f831c31df7cd8abba110f5e66cc9c9dd7f09 Mon Sep 17 00:00:00 2001 From: DevelopmentCats Date: Mon, 25 Aug 2025 20:18:09 +0000 Subject: [PATCH 06/10] docs(contributing): clarify testing procedures and requirements --- CONTRIBUTING.md | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c764e492e..d2a8b6a36 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -125,8 +125,8 @@ This script generates: - Correct icon path (usually `../../../../.icons/your-icon.svg`) - Proper tags that describe your module 3. **Create tests for your module:** - - **New modules**: Create `.tftest.hcl` files and test with `terraform test` - - **Existing modules**: Keep `main.test.ts` files and test with `bun test` + - **New modules**: Create `*.tftest.hcl` files and test with `terraform test` + - **TypeScript tests**: Create `main.test.ts` files if your module runs scripts or has business logic that Terraform tests can't cover - **Both approaches** are supported 4. **Add any scripts** or additional files your module needs @@ -134,17 +134,14 @@ This script generates: ```bash # Test your module -# For new modules with .tftest.hcl: cd registry/[namespace]/modules/[module-name] + +# Required: Test Terraform functionality terraform init -upgrade terraform test -verbose -# For existing modules with main.test.ts: -bun test registry/[namespace]/modules/[module-name] - -# Run all tests in the repo -bun test # All TypeScript tests -./scripts/terraform_test_all.sh # All Terraform tests +# Optional: Test TypeScript files if you have main.test.ts +bun test main.test.ts # Format code bun run fmt @@ -352,8 +349,8 @@ coder templates push test-[template-name] -d . terraform init -upgrade terraform test -verbose -# Test all modules -./scripts/terraform_test_all.sh +# Optional: If you have TypeScript tests +bun test main.test.ts ``` ### 3. Maintain Backward Compatibility @@ -403,7 +400,7 @@ Example: `https://github.com/coder/registry/compare/main...your-branch?template= - `main.tf` - Terraform code - **Tests**: - - `*.tftest.hcl` files with `terraform test` (to test terraform specific logoc) + - `*.tftest.hcl` files with `terraform test` (to test terraform specific logic) - `main.test.ts` file with `bun test` (to test business logic, i.e., `coder_script` to install a package.) - `README.md` - Documentation with frontmatter @@ -504,6 +501,6 @@ When reporting bugs, include: 2. **No tests** or broken tests 3. **Hardcoded values** instead of variables 4. **Breaking changes** without defaults -5. **Not running** formatting (`bun run fmt`) and tests (`bun test` or `terraform test`) before submitting +5. **Not running** formatting (`bun run fmt`) and tests (`terraform test`, and `bun test main.test.ts` if applicable) before submitting Happy contributing! 🚀 From 7cd49699e92597554a4c97d3d0e344544683219b Mon Sep 17 00:00:00 2001 From: Atif Ali Date: Tue, 26 Aug 2025 12:46:16 +0500 Subject: [PATCH 07/10] Apply suggestion from @matifali --- CONTRIBUTING.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d2a8b6a36..71c256bc8 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -125,9 +125,8 @@ This script generates: - Correct icon path (usually `../../../../.icons/your-icon.svg`) - Proper tags that describe your module 3. **Create tests for your module:** - - **New modules**: Create `*.tftest.hcl` files and test with `terraform test` - - **TypeScript tests**: Create `main.test.ts` files if your module runs scripts or has business logic that Terraform tests can't cover - - **Both approaches** are supported + - **Terraform tests**: Create a `*.tftest.hcl` file and test with `terraform test` + - **TypeScript tests**: Create `main.test.ts` file if your module runs scripts or has business logic that Terraform tests can't cover 4. **Add any scripts** or additional files your module needs ### 4. Test and Submit From 39207090cd7509d6df9182b0bdcc006d09f3aea2 Mon Sep 17 00:00:00 2001 From: DevelopmentCats Date: Wed, 1 Oct 2025 16:20:08 -0500 Subject: [PATCH 08/10] fix(examples): standardize module naming from MODULE_NAME to module_name for tf tests --- examples/modules/MODULE_NAME.tftest.hcl | 4 ++-- examples/modules/main.tf | 24 ++++++++++++------------ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/examples/modules/MODULE_NAME.tftest.hcl b/examples/modules/MODULE_NAME.tftest.hcl index 6f11666b5..a6ccc5240 100644 --- a/examples/modules/MODULE_NAME.tftest.hcl +++ b/examples/modules/MODULE_NAME.tftest.hcl @@ -15,7 +15,7 @@ run "app_url_uses_port" { } assert { - condition = resource.coder_app.MODULE_NAME.url == "http://localhost:19999" - error_message = "Expected MODULE_NAME app URL to include configured port" + condition = resource.coder_app.module_name.url == "http://localhost:19999" + error_message = "Expected module-name app URL to include configured port" } } diff --git a/examples/modules/main.tf b/examples/modules/main.tf index 628eb1da5..d4d257813 100644 --- a/examples/modules/main.tf +++ b/examples/modules/main.tf @@ -35,13 +35,13 @@ variable "agent_id" { variable "log_path" { type = string - description = "The path to log MODULE_NAME to." - default = "/tmp/MODULE_NAME.log" + description = "The path to log module-name to." + default = "/tmp/module-name.log" } variable "port" { type = number - description = "The port to run MODULE_NAME on." + description = "The port to run module-name on." default = 19999 } @@ -59,9 +59,9 @@ variable "order" { # Add other variables here -resource "coder_script" "MODULE_NAME" { +resource "coder_script" "module_name" { agent_id = var.agent_id - display_name = "MODULE_NAME" + display_name = "Module Name" icon = local.icon_url script = templatefile("${path.module}/run.sh", { LOG_PATH : var.log_path, @@ -70,10 +70,10 @@ resource "coder_script" "MODULE_NAME" { run_on_stop = false } -resource "coder_app" "MODULE_NAME" { +resource "coder_app" "module_name" { agent_id = var.agent_id - slug = "MODULE_NAME" - display_name = "MODULE_NAME" + slug = "module-name" + display_name = "Module Name" url = "http://localhost:${var.port}" icon = local.icon_url subdomain = false @@ -88,10 +88,10 @@ resource "coder_app" "MODULE_NAME" { } } -data "coder_parameter" "MODULE_NAME" { - type = "list(string)" - name = "MODULE_NAME" - display_name = "MODULE_NAME" +data "coder_parameter" "module_name" { + type = "string" + name = "module_name" + display_name = "Module Name" icon = local.icon_url mutable = var.mutable default = local.options["Option 1"]["value"] From 7cefd5859dd9d00a7c7292cdefcdf970ba8314b8 Mon Sep 17 00:00:00 2001 From: DevelopmentCats Date: Wed, 1 Oct 2025 16:33:51 -0500 Subject: [PATCH 09/10] chore: resolve index issue with claude-code tf test --- registry/coder/modules/claude-code/main.tftest.hcl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/registry/coder/modules/claude-code/main.tftest.hcl b/registry/coder/modules/claude-code/main.tftest.hcl index 7931cca81..c48923cf3 100644 --- a/registry/coder/modules/claude-code/main.tftest.hcl +++ b/registry/coder/modules/claude-code/main.tftest.hcl @@ -42,7 +42,7 @@ run "test_claude_code_with_api_key" { } assert { - condition = coder_env.claude_api_key.value == "test-api-key-123" + condition = coder_env.claude_api_key[0].value == "test-api-key-123" error_message = "Claude API key value should match the input" } } From 2f8552fbc54a526caf5f3875a4d322c83fcb3463 Mon Sep 17 00:00:00 2001 From: DevelopmentCats Date: Wed, 8 Oct 2025 14:18:30 -0500 Subject: [PATCH 10/10] fix: update log_path variable description and default value in main.tf for consistency --- examples/modules/main.tf | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/modules/main.tf b/examples/modules/main.tf index d4d257813..c0acfbc35 100644 --- a/examples/modules/main.tf +++ b/examples/modules/main.tf @@ -35,13 +35,13 @@ variable "agent_id" { variable "log_path" { type = string - description = "The path to log module-name to." - default = "/tmp/module-name.log" + description = "The path to the module log file." + default = "/tmp/module_name.log" } variable "port" { type = number - description = "The port to run module-name on." + description = "The port to run the application on." default = 19999 }