From a5edad7f176a65a0f5d58752caeb7c7d97beb2e7 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Fri, 8 Aug 2025 16:36:30 +0500 Subject: [PATCH] chore(examples): add MODULE_NAME.tftest.hcl to new module sample and make run.sh optional --- examples/modules/MODULE_NAME.tftest.hcl | 21 +++++++++++++++++++++ scripts/new_module.sh | 8 +++++--- 2 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 examples/modules/MODULE_NAME.tftest.hcl diff --git a/examples/modules/MODULE_NAME.tftest.hcl b/examples/modules/MODULE_NAME.tftest.hcl new file mode 100644 index 00000000..6f11666b --- /dev/null +++ b/examples/modules/MODULE_NAME.tftest.hcl @@ -0,0 +1,21 @@ +run "plan_with_required_vars" { + command = plan + + variables { + agent_id = "example-agent-id" + } +} + +run "app_url_uses_port" { + command = plan + + variables { + agent_id = "example-agent-id" + port = 19999 + } + + assert { + condition = resource.coder_app.MODULE_NAME.url == "http://localhost:19999" + error_message = "Expected MODULE_NAME app URL to include configured port" + } +} diff --git a/scripts/new_module.sh b/scripts/new_module.sh index bc98d9ee..df2cb834 100755 --- a/scripts/new_module.sh +++ b/scripts/new_module.sh @@ -31,7 +31,7 @@ if [ -d "registry/$NAMESPACE/modules/$MODULE_NAME" ]; then fi mkdir -p "registry/${NAMESPACE}/modules/${MODULE_NAME}" -# Copy required files from the example module +# Copy required files from the example module (includes Terraform tests) cp -r examples/modules/* "registry/${NAMESPACE}/modules/${MODULE_NAME}/" # Change to module directory @@ -48,5 +48,7 @@ else sed -i "s/MODULE_NAME/${MODULE_NAME}/g" README.md fi -# Make run.sh executable -chmod +x run.sh +# Make run.sh executable (if present) +if [ -f run.sh ]; then + chmod +x run.sh +fi