Compare commits

..

3 Commits

Author SHA1 Message Date
blink-so[bot] 4ce3cd189a fix: remove extra blank line to pass terraform fmt check
Terraform fmt requires consistent spacing in resource blocks.
2025-09-05 05:44:46 +00:00
blink-so[bot] 41cf2c6fab fix: format README.md to pass CI checks
Remove extra space before comment to match prettier formatting rules.
2025-09-05 05:42:44 +00:00
blink-so[bot] 73996b1c26 feat(agentapi): add enable_tasks variable to conditionally create coder_ai_task resource
This allows users to disable AI task creation when using the agentapi module
with count = 0, avoiding the validation requirement for 'AI Prompt' parameter.

When enable_tasks = false, the coder_ai_task resource will not be created,
allowing the module to be used without defining the required AI Prompt parameter.
2025-09-05 05:39:13 +00:00
98 changed files with 1253 additions and 6720 deletions
+3 -8
View File
@@ -1,3 +1,5 @@
Closes #
## Description
<!-- Briefly describe what this PR does and why -->
@@ -5,7 +7,6 @@
## Type of Change
- [ ] New module
- [ ] New template
- [ ] Bug fix
- [ ] Feature/enhancement
- [ ] Documentation
@@ -19,16 +20,10 @@
**New version:** `v1.0.0`
**Breaking change:** [ ] Yes [ ] No
## Template Information
<!-- Delete this section if not applicable -->
**Path:** `registry/[namespace]/templates/[template-name]`
## Testing & Validation
- [ ] Tests pass (`bun test`)
- [ ] Code formatted (`bun fmt`)
- [ ] Code formatted (`bun run fmt`)
- [ ] Changes tested locally
## Related Issues
+2 -4
View File
@@ -28,8 +28,6 @@ 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:
@@ -50,7 +48,7 @@ jobs:
- name: Validate formatting
run: bun fmt:ci
- name: Check for typos
uses: crate-ci/typos@v1.38.1
uses: crate-ci/typos@v1.35.5
with:
config: .github/typos.toml
validate-readme-files:
@@ -63,7 +61,7 @@ jobs:
- name: Check out code
uses: actions/checkout@v5
- name: Set up Go
uses: actions/setup-go@v6
uses: actions/setup-go@v5
with:
go-version: "1.23.2"
- name: Validate contributors
+2 -2
View File
@@ -30,12 +30,12 @@ jobs:
- name: Checkout code
uses: actions/checkout@v5
- name: Authenticate with Google Cloud
uses: google-github-actions/auth@7c6bc770dae815cd3e89ee6cdf493a5fab2cc093
uses: google-github-actions/auth@b7593ed2efd1c1617e1b0254da33b86225adb2a5
with:
workload_identity_provider: projects/309789351055/locations/global/workloadIdentityPools/github-actions/providers/github
service_account: registry-v2-github@coder-registry-1.iam.gserviceaccount.com
- name: Set up Google Cloud SDK
uses: google-github-actions/setup-gcloud@aa5489c8933f4cc7a4f7d45035b3b1440c9c10db
uses: google-github-actions/setup-gcloud@26f734c2779b00b7dda794207734c511110a4368
- name: Deploy to dev.registry.coder.com
run: gcloud builds triggers run 29818181-126d-4f8a-a937-f228b27d3d34 --branch main
- name: Deploy to registry.coder.com
+1 -1
View File
@@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: actions/setup-go@v6
- uses: actions/setup-go@v5
with:
go-version: stable
- name: golangci-lint
+1 -1
View File
@@ -95,7 +95,7 @@ jobs:
- name: Comment on PR - Failure
if: failure() && steps.version-check.outputs.versions_up_to_date == 'false'
uses: actions/github-script@v8
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
-4
View File
@@ -1,4 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="512pt" height="512pt" version="1.1" viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg">
<path d="m500.48 262.2-48.18 73.984c-0.73438 1.1367-2 1.8242-3.3555 1.8242-1.3516 0-2.6172-0.6875-3.3516-1.8242l-48.129-73.984c-0.78125-1.2227-0.83594-2.7773-0.14453-4.0547 0.69141-1.2734 2.0195-2.0742 3.4727-2.0898h24.781c-0.007813-29.523-7.7188-58.531-22.375-84.156-14.652-25.629-35.742-46.988-61.184-61.969-2.3711-1.3633-3.8633-3.8594-3.9453-6.5938-0.085937-2.7305 1.2539-5.3125 3.5352-6.8203l27.035-17.613c3.4766-2.3633 8.043-2.3633 11.52 0 28.473 19.934 51.723 46.441 67.773 77.27 16.051 30.828 24.434 65.074 24.438 99.832h24.781c1.4688 0 2.8203 0.80859 3.5156 2.1055 0.69531 1.293 0.62109 2.8633-0.1875 4.0898zm-85.043 79.359c-1.5078-2.2812-4.0898-3.6211-6.8203-3.5391-2.7344 0.085937-5.2305 1.5781-6.5938 3.9492-14.965 25.434-36.305 46.523-61.914 61.188-25.609 14.664-54.602 22.391-84.109 22.422v-24.781c-0.011719-1.4531-0.8125-2.7812-2.0898-3.4727-1.2773-0.69141-2.832-0.63672-4.0547 0.14453l-74.035 47.977c-1.1367 0.73438-1.8242 1.9961-1.8242 3.3516s0.6875 2.6172 1.8242 3.3555l73.984 48.18c1.2227 0.78125 2.7773 0.83594 4.0547 0.14453 1.2734-0.69141 2.0742-2.0234 2.0898-3.4727v-24.68c34.734-0.015624 68.957-8.3984 99.766-24.441 30.812-16.039 57.301-39.27 77.23-67.719 2.3672-3.4766 2.3672-8.043 0-11.52zm-245.45 60.52c-25.434-14.977-46.516-36.328-61.172-61.945-14.652-25.617-22.371-54.617-22.387-84.129h24.781c1.4531-0.011719 2.7812-0.8125 3.4727-2.0898 0.69141-1.2773 0.63672-2.832-0.14453-4.0547l-47.977-74.035c-0.73438-1.1367-1.9961-1.8242-3.3516-1.8242s-2.6172 0.6875-3.3555 1.8242l-48.332 73.984c-0.80859 1.2266-0.88281 2.7969-0.1875 4.0898 0.69531 1.2969 2.0469 2.1055 3.5156 2.1055h24.781c0.015625 34.734 8.3984 68.957 24.438 99.766 16.043 30.812 39.273 57.301 67.723 77.234 3.4766 2.3633 8.043 2.3633 11.52 0l27.086-17.664c2.2109-1.5195 3.4961-4.0625 3.4141-6.7422-0.082032-2.6836-1.5234-5.1406-3.8242-6.5195zm92.16-390.5c-1.2227-0.78125-2.7773-0.83594-4.0547-0.14453-1.2773 0.69141-2.0781 2.0195-2.0898 3.4727v24.73c-34.734 0.015625-68.957 8.3984-99.766 24.438-30.812 16.043-57.301 39.273-77.234 67.723-2.3633 3.4766-2.3633 8.043 0 11.52l17.664 27.086c1.5078 2.2812 4.0898 3.6211 6.8242 3.5352 2.7305-0.082032 5.2266-1.5742 6.5898-3.9453 14.965-25.41 36.289-46.48 61.879-61.133 25.59-14.652 54.555-22.383 84.043-22.426v24.781c0.011719 1.4531 0.8125 2.7812 2.0898 3.4727 1.2773 0.69141 2.832 0.63672 4.0547-0.14453l74.035-47.977c1.1367-0.73438 1.8242-1.9961 1.8242-3.3516s-0.6875-2.6172-1.8242-3.3555zm-6.1445 210.23c-9.0703 0-17.77 3.6055-24.184 10.02-6.4141 6.4141-10.02 15.113-10.02 24.184s3.6055 17.77 10.02 24.184c6.4141 6.4141 15.113 10.02 24.184 10.02s17.77-3.6055 24.184-10.02c6.4141-6.4141 10.02-15.113 10.02-24.184s-3.6055-17.77-10.02-24.184c-6.4141-6.4141-15.113-10.02-24.184-10.02zm90.727-26.828-10.344 14.953c4.0039 6.9414 7.0859 14.375 9.1641 22.117l17.973 2.9688c6.543 1.1445 11.316 6.8242 11.316 13.465v15.055c0 6.6406-4.7734 12.32-11.316 13.465l-17.766 3.125v-0.003907c-2.1562 7.6992-5.3086 15.082-9.3711 21.965l10.238 14.797h0.003906c3.8047 5.4375 3.1562 12.82-1.5352 17.512l-10.648 10.648h-0.003906c-4.6914 4.6953-12.074 5.3438-17.508 1.5391l-14.797-10.238v-0.003907c-6.9453 4.0039-14.379 7.0859-22.121 9.1641l-3.0195 18.023c-1.1445 6.543-6.8242 11.316-13.465 11.316h-15.055c-6.6406 0-12.32-4.7734-13.465-11.316l-3.125-17.766h0.003907c-7.7031-2.1758-15.086-5.3398-21.965-9.4219l-14.797 10.238v0.003907c-5.4375 3.8047-12.82 3.1562-17.512-1.5391l-10.648-10.648c-4.6953-4.6914-5.3438-12.074-1.5391-17.512l10.238-14.797h0.003907c-4.0039-6.9414-7.0859-14.375-9.1641-22.117l-18.023-2.9688c-6.543-1.1445-11.316-6.8242-11.316-13.465v-15.055c0-6.6406 4.7734-12.32 11.316-13.465l17.766-3.125v0.003907c2.1562-7.6992 5.3086-15.082 9.3711-21.965l-10.238-14.797h-0.003906c-3.8047-5.4375-3.1562-12.82 1.5352-17.512l10.648-10.648h0.003906c4.6914-4.6953 12.074-5.3438 17.508-1.5391l14.797 10.238v0.003907c6.9453-4.0039 14.379-7.0859 22.121-9.1641l3.0195-18.023c1.1445-6.543 6.8242-11.316 13.465-11.316h15.055c6.6406 0 12.32 4.7734 13.465 11.316l3.125 17.766h-0.003907c7.6992 2.1562 15.082 5.3086 21.965 9.3711l14.797-10.238v-0.003906c5.4375-3.8047 12.82-3.1562 17.512 1.5352l10.648 10.648v0.003906c4.6875 4.6367 5.3984 11.957 1.6914 17.406zm-36.047 61.031c0-14.504-5.7578-28.41-16.016-38.664-10.254-10.258-24.16-16.016-38.664-16.016s-28.41 5.7578-38.664 16.016c-10.258 10.254-16.016 24.16-16.016 38.664s5.7578 28.41 16.016 38.664c10.254 10.258 24.16 16.016 38.664 16.016 14.5-0.011719 28.398-5.7773 38.652-16.027 10.25-10.254 16.016-24.152 16.027-38.652z" fill="#fff"/>
</svg>

Before

Width:  |  Height:  |  Size: 4.5 KiB

-6
View File
@@ -1,6 +0,0 @@
<svg width="251" height="251" viewBox="0 0 251 251" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M0 47.0195C39.45 49.6394 71.06 81.3272 73.54 120.815H119.61C117.05 55.8589 64.93 3.64245 0 0.942627V47.0195Z" fill="#0DC09D"/>
<path d="M73.8 131.324C71.18 170.771 39.49 202.379 0 204.859V250.926C64.96 248.366 117.18 196.249 119.88 131.324H73.8Z" fill="#0DC09D"/>
<path d="M176.201 120.545C178.821 81.0972 210.511 49.4894 250.001 47.0095V0.942627C185.041 3.50245 132.821 55.619 130.121 120.545H176.201Z" fill="#0DC09D"/>
<path d="M250.001 204.849C210.551 202.229 178.941 170.542 176.461 131.054H130.391C132.951 196.01 185.071 248.226 250.001 250.926V204.849Z" fill="#0DC09D"/>
</svg>

Before

Width:  |  Height:  |  Size: 693 B

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 27 KiB

-5
View File
@@ -1,5 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg height="32" viewBox="0 0 375 375" width="32" xmlns="http://www.w3.org/2000/svg">
<rect fill="#0071ff" height="375.001088" rx="58.59392" stroke-width=".91553" width="375.001088" x=".0009759" y="-.0066962"/>
<path d="m150.428 322.264c-29.063-6.202-53.897-22.439-73.115-47.804-19.507-25.746-27.838-55.355-25.723-91.414 6.655-62.013 47.667-106.753 99.687-120.411 4.509-.989 8.353-3.462 12.55-1.322 3.22 1.64 6.028 4.467 7.206 7.251 1.25 2.955 1.877 21.54.99 29.331-1.076 9.46-3.877 12.418-14.566 15.388-29.723 10.195-48.105 34.07-53.697 61.017-4.8 29.668 2.951 59.729 21.528 78.727 8.966 8.993 17.92 14.24 30.869 18.086 8.646 2.57 13.393 5.758 15.036 10.102 1.085 2.867 1.63 22.984.779 28.772-1.33 9.046-1.702 9.796-5.792 11.667-5.029 2.3-7.404 2.392-15.752.61zm50.708.29c-3.092-1.402-5.673-4.83-6.73-8.94-.134-9.408-2.366-25.754 1.02-33.373 1.88-4.128 4.65-5.999 12.433-8.396 21.267-6.551 37.593-19.88 46.806-38.213 11.11-22.108 11.877-55.183 1.808-77.975-9.154-20.723-25.7-35.217-48.555-42.534-8.872-2.84-12.004-5.065-12.968-9.21-1.002-4.31-1.435-19.87-.785-28.218.682-8.766 1.249-9.99 6.162-13.318 3.701-2.505 5.482-2.446 17.223.575 36.718 10.077 65.97 33.597 83.026 66.68 18.495 37.034 19.191 86.11 1.742 122.655-17.233 36.09-50.591 62.511-88.622 70.194-8.172 1.65-9.07 1.656-12.56.073z" fill="#fff"/>
</svg>

Before

Width:  |  Height:  |  Size: 1.3 KiB

+8 -19
View File
@@ -124,23 +124,18 @@ This script generates:
- Accurate description and usage examples
- Correct icon path (usually `../../../../.icons/your-icon.svg`)
- Proper tags that describe your module
3. **Create tests for your module:**
- **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
3. **Create at least one `.tftest.hcl`** to test your module with `terraform test`
4. **Add any scripts** or additional files your module needs
### 4. Test and Submit
```bash
# Test your module
cd registry/[namespace]/modules/[module-name]
# Required: Test Terraform functionality
# Test your module (from the module directory)
terraform init -upgrade
terraform test -verbose
# Optional: Test TypeScript files if you have main.test.ts
bun test main.test.ts
# Or run all tests in the repo
./scripts/terraform_test_all.sh
# Format code
bun run fmt
@@ -348,8 +343,8 @@ coder templates push test-[template-name] -d .
terraform init -upgrade
terraform test -verbose
# Optional: If you have TypeScript tests
bun test main.test.ts
# Test all modules
./scripts/terraform_test_all.sh
```
### 3. Maintain Backward Compatibility
@@ -398,9 +393,7 @@ Example: `https://github.com/coder/registry/compare/main...your-branch?template=
### Every Module Must Have
- `main.tf` - Terraform code
- **Tests**:
- `*.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.)
- One or more `.tftest.hcl` files - Working tests with `terraform test`
- `README.md` - Documentation with frontmatter
### Every Template Must Have
@@ -500,10 +493,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`, and `bun test main.test.ts` if applicable) before submitting
## For Maintainers
Guidelines for reviewing PRs, managing releases, and maintaining the registry. [See the maintainer guide for detailed information.](./MAINTAINER.md)
5. **Not running** formatting (`bun run fmt`) and tests (`terraform test`) before submitting
Happy contributing! 🚀
+1 -3
View File
@@ -23,7 +23,6 @@ Check that PRs have:
- [ ] Working tests (`terraform test`)
- [ ] Formatted code (`bun run fmt`)
- [ ] Avatar image for new namespaces (`avatar.png` or `avatar.svg` in `.images/`)
- [ ] Version label: `version:patch`, `version:minor`, or `version:major`
### Version Guidelines
@@ -33,8 +32,7 @@ When reviewing PRs, ensure the version change follows semantic versioning:
- **Minor** (1.2.3 → 1.3.0): New features, adding inputs
- **Major** (1.2.3 → 2.0.0): Breaking changes (removing inputs, changing types)
PRs should clearly indicate the intended version change (e.g., `v1.2.3 → v1.2.4`) and include the appropriate label: `version:patch`, `version:minor`, or `version:major`.
The “Version Bump” CI uses this label to validate required updates (README version refs, etc.).
PRs should clearly indicate the version change (e.g., `v1.2.3 → v1.2.4`).
### Validate READMEs
-4
View File
@@ -48,7 +48,3 @@ Simply include that snippet inside your Coder template, defining any data depend
## Contributing
We are always accepting new contributions. [Please see our contributing guide for more information.](./CONTRIBUTING.md)
## For Maintainers
Guidelines for maintainers reviewing PRs and managing releases. [See the maintainer guide for more information.](./MAINTAINER.md)
+2 -2
View File
@@ -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"
}
}
+12 -12
View File
@@ -35,13 +35,13 @@ variable "agent_id" {
variable "log_path" {
type = string
description = "The path to the module log file."
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 the application 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 = "string"
name = "module_name"
display_name = "Module Name"
data "coder_parameter" "MODULE_NAME" {
type = "list(string)"
name = "MODULE_NAME"
display_name = "MODULE_NAME"
icon = local.icon_url
mutable = var.mutable
default = local.options["Option 1"]["value"]
Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

-14
View File
@@ -1,14 +0,0 @@
---
display_name: "Benraouane Soufiane"
bio: "Full stack developer creating awesome things."
avatar: "./.images/avatar.png"
github: "benraouanesoufiane"
linkedin: "https://www.linkedin.com/in/benraouane-soufiane" # Optional
website: "https://benraouanesoufiane.com" # Optional
support_email: "hello@benraouanesoufiane.com" # Optional
status: "community"
---
# Benraouane Soufiane
Full stack developer creating awesome things.
@@ -1,82 +0,0 @@
---
display_name: RustDesk
description: Run RustDesk in your workspace with virtual display
icon: ../../../../.icons/rustdesk.svg
verified: false
tags: [rustdesk, rdp, vm]
---
# RustDesk
Launches RustDesk within your workspace with a virtual display to provide remote desktop access. The module outputs the RustDesk ID and password needed to connect from external RustDesk clients.
```tf
module "rustdesk" {
count = data.coder_workspace.me.start_count
source = "registry.coder.com/BenraouaneSoufiane/rustdesk/coder"
version = "1.0.0"
agent_id = coder_agent.example.id
}
```
## Features
- Automatically sets up virtual display (Xvfb)
- Downloads and configures RustDesk
- Outputs RustDesk ID and password for easy connection
- Provides external app link to RustDesk web client for browser-based access
- Starts virtual display (Xvfb) with customizable resolution
- Customizable screen resolution and RustDesk version
## Requirements
- Coder v2.5 or higher
- Linux workspace with `apt`, `dnf`, or `yum` package manager
## Examples
### Custom configuration with specific version
```tf
module "rustdesk" {
count = data.coder_workspace.me.start_count
source = "registry.coder.com/BenraouaneSoufiane/rustdesk/coder"
version = "1.0.0"
agent_id = coder_agent.example.id
rustdesk_password = "mycustompass"
xvfb_resolution = "1920x1080x24"
rustdesk_version = "1.4.1"
}
```
### Docker container configuration
It requires coder' server to be run as root, when using with Docker, add the following to your `docker_container` resource:
```tf
resource "docker_container" "workspace" {
# ... other configuration ...
user = "root"
privileged = true
network_mode = "host"
ports {
internal = 21115
external = 21115
}
ports {
internal = 21116
external = 21116
}
ports {
internal = 21118
external = 21118
}
ports {
internal = 21119
external = 21119
}
}
```
@@ -1,75 +0,0 @@
terraform {
required_version = ">= 1.0"
required_providers {
coder = {
source = "coder/coder"
version = ">= 2.5"
}
}
}
variable "log_path" {
type = string
description = "The path to log rustdesk to."
default = "/tmp/rustdesk.log"
}
variable "agent_id" {
description = "Attach RustDesk setup to this agent"
type = string
}
variable "order" {
description = "Run order among scripts/apps"
type = number
default = 1
}
# Optional knobs passed as env (you can expose these as variables too)
variable "rustdesk_password" {
description = "If empty, the script will generate one"
type = string
default = ""
sensitive = true
}
variable "xvfb_resolution" {
description = "Xvfb screen size/depth"
type = string
default = "1024x768x16"
}
variable "rustdesk_version" {
description = "RustDesk version to install (use 'latest' for most recent release)"
type = string
default = "latest"
}
resource "coder_script" "rustdesk" {
agent_id = var.agent_id
display_name = "RustDesk"
run_on_start = true
# Prepend env as bash exports, then append the script file literally.
script = <<-EOT
# --- module-provided env knobs ---
export RUSTDESK_PASSWORD="${var.rustdesk_password}"
export XVFB_RESOLUTION="${var.xvfb_resolution}"
export RUSTDESK_VERSION="${var.rustdesk_version}"
# ---------------------------------
${file("${path.module}/run.sh")}
EOT
}
resource "coder_app" "rustdesk" {
agent_id = var.agent_id
slug = "rustdesk"
display_name = "Rustdesk"
url = "https://rustdesk.com/web"
icon = "/icon/rustdesk.svg"
order = var.order
external = true
}
@@ -1,117 +0,0 @@
#!/usr/bin/env bash
BOLD='\033[0;1m'
RESET='\033[0m'
printf "${BOLD}🖥️ Installing RustDesk Remote Desktop\n${RESET}"
# ---- configurable knobs (env overrides) ----
RUSTDESK_VERSION="${RUSTDESK_VERSION:-latest}"
LOG_PATH="${LOG_PATH:-/tmp/rustdesk.log}"
# ---- fetch latest version if needed ----
if [ "$RUSTDESK_VERSION" = "latest" ]; then
printf "🔍 Fetching latest RustDesk version...\n"
RUSTDESK_VERSION=$(curl -s https://api.github.com/repos/rustdesk/rustdesk/releases/latest | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/' || echo "1.4.1")
printf "📌 Fetched RustDesk version: ${RUSTDESK_VERSION}\n"
else
printf "📌 Using specified RustDesk version: ${RUSTDESK_VERSION}\n"
fi
XVFB_RESOLUTION="${XVFB_RESOLUTION:-1024x768x16}"
RUSTDESK_PASSWORD="${RUSTDESK_PASSWORD:-}"
# ---- detect package manager & arch ----
ARCH="$(uname -m)"
case "$ARCH" in
x86_64 | amd64) PKG_ARCH="x86_64" ;;
aarch64 | arm64) PKG_ARCH="aarch64" ;;
*)
echo "❌ Unsupported arch: $ARCH"
exit 1
;;
esac
if command -v apt-get > /dev/null 2>&1; then
PKG_SYS="deb"
PKG_NAME="rustdesk-${RUSTDESK_VERSION}-${PKG_ARCH}.deb"
INSTALL_DEPS='apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y wget libva2 libva-drm2 libva-x11-2 libgstreamer-plugins-base1.0-0 gstreamer1.0-pipewire xfce4 xfce4-goodies xvfb x11-xserver-utils dbus-x11 libegl1 libgl1 libglx0 libglu1-mesa mesa-utils libxrandr2 libxss1 libgtk-3-0t64 libgbm1 libdrm2 libxcomposite1 libxdamage1 libxfixes3'
INSTALL_CMD="apt-get install -y ./${PKG_NAME}"
CLEAN_CMD="rm -f \"${PKG_NAME}\""
elif command -v dnf > /dev/null 2>&1; then
PKG_SYS="rpm"
PKG_NAME="rustdesk-${RUSTDESK_VERSION}-${PKG_ARCH}.rpm"
INSTALL_DEPS='dnf install -y wget libva libva-intel-driver gstreamer1-plugins-base pipewire xfce4-session xfce4-panel xorg-x11-server-Xvfb xorg-x11-xauth dbus-x11 mesa-libEGL mesa-libGL mesa-libGLU mesa-dri-drivers libXrandr libXScrnSaver gtk3 mesa-libgbm libdrm libXcomposite libXdamage libXfixes'
INSTALL_CMD="dnf install -y ./${PKG_NAME}"
CLEAN_CMD="rm -f \"${PKG_NAME}\""
elif command -v yum > /dev/null 2>&1; then
PKG_SYS="rpm"
PKG_NAME="rustdesk-${RUSTDESK_VERSION}-${PKG_ARCH}.rpm"
INSTALL_DEPS='yum install -y wget libva libva-intel-driver gstreamer1-plugins-base pipewire xfce4-session xfce4-panel xorg-x11-server-Xvfb xorg-x11-xauth dbus-x11 mesa-libEGL mesa-libGL mesa-libGLU mesa-dri-drivers libXrandr libXScrnSaver gtk3 mesa-libgbm libdrm libXcomposite libXdamage libXfixes'
INSTALL_CMD="yum install -y ./${PKG_NAME}"
CLEAN_CMD="rm -f \"${PKG_NAME}\""
else
echo "❌ Unsupported distro: need apt, dnf, or yum."
exit 1
fi
# ---- install rustdesk if missing ----
if ! command -v rustdesk > /dev/null 2>&1; then
printf "📦 Installing dependencies...\n"
sudo bash -c "$INSTALL_DEPS" 2>&1 | tee -a "${LOG_PATH}"
printf "⬇️ Downloading RustDesk ${RUSTDESK_VERSION} (${PKG_SYS}, ${PKG_ARCH})...\n"
URL="https://github.com/rustdesk/rustdesk/releases/download/${RUSTDESK_VERSION}/${PKG_NAME}"
wget -q "$URL" 2>&1 | tee -a "${LOG_PATH}"
printf "🔧 Installing RustDesk...\n"
sudo bash -c "$INSTALL_CMD" 2>&1 | tee -a "${LOG_PATH}"
printf "🧹 Cleaning up...\n"
bash -c "$CLEAN_CMD" 2>&1 | tee -a "${LOG_PATH}"
else
printf "✅ RustDesk already installed\n"
fi
# ---- start virtual display ----
echo "Starting Xvfb with resolution ${XVFB_RESOLUTION}"
Xvfb :99 -screen 0 "${XVFB_RESOLUTION}" >> "${LOG_PATH}" 2>&1 &
export DISPLAY=:99
# Wait for X to be ready
for i in {1..10}; do
if xdpyinfo -display :99 > /dev/null 2>&1; then
echo "X display is ready"
break
fi
sleep 1
done
# ---- create (or accept) password and start rustdesk ----
if [[ -z "${RUSTDESK_PASSWORD}" ]]; then
RUSTDESK_PASSWORD="$(tr -dc 'a-zA-Z0-9@' < /dev/urandom | head -c 10)@97"
fi
echo "Starting XFCE desktop environment..."
xfce4-session >> "${LOG_PATH}" 2>&1 &
echo "Waiting for xfce4-session to initialize..."
sleep 5
printf "🔐 Setting RustDesk password and starting service...\n"
rustdesk >> "${LOG_PATH}" 2>&1 &
sleep 2
rustdesk --password "${RUSTDESK_PASSWORD}" >> "${LOG_PATH}" 2>&1 &
sleep 3
RID="$(rustdesk --get-id 2> /dev/null || echo 'ID_PENDING')"
printf "🥳 RustDesk setup complete!\n\n"
printf "${BOLD}📋 Connection Details:${RESET}\n"
printf " RustDesk ID: ${RID}\n"
printf " RustDesk Password: ${RUSTDESK_PASSWORD}\n"
printf " Display: ${DISPLAY} (${XVFB_RESOLUTION})\n"
printf "\n📝 Logs available at: ${LOG_PATH}\n\n"
echo "Setup script completed successfully. All services running in background."
exit 0
+3 -3
View File
@@ -13,7 +13,7 @@ Run Auggie CLI in your workspace to access Augment's AI coding assistant with ad
```tf
module "auggie" {
source = "registry.coder.com/coder-labs/auggie/coder"
version = "0.2.0"
version = "0.1.0"
agent_id = coder_agent.example.id
folder = "/home/coder/project"
}
@@ -47,7 +47,7 @@ module "coder-login" {
module "auggie" {
source = "registry.coder.com/coder-labs/auggie/coder"
version = "0.2.0"
version = "0.1.0"
agent_id = coder_agent.example.id
folder = "/home/coder/project"
@@ -103,7 +103,7 @@ EOF
```tf
module "auggie" {
source = "registry.coder.com/coder-labs/auggie/coder"
version = "0.2.0"
version = "0.1.0"
agent_id = coder_agent.example.id
folder = "/home/coder/project"
+2 -2
View File
@@ -66,7 +66,7 @@ variable "install_agentapi" {
variable "agentapi_version" {
type = string
description = "The version of AgentAPI to install."
default = "v0.10.0"
default = "v0.6.0"
validation {
condition = can(regex("^v[0-9]+\\.[0-9]+\\.[0-9]+", var.agentapi_version))
error_message = "agentapi_version must be a valid semantic version starting with 'v', like 'v0.3.3'."
@@ -178,7 +178,7 @@ locals {
module "agentapi" {
source = "registry.coder.com/coder/agentapi/coder"
version = "1.2.0"
version = "1.1.1"
agent_id = var.agent_id
web_app_slug = local.app_slug
+4 -4
View File
@@ -13,7 +13,7 @@ Run Codex CLI in your workspace to access OpenAI's models through the Codex inte
```tf
module "codex" {
source = "registry.coder.com/coder-labs/codex/coder"
version = "2.1.1"
version = "2.0.0"
agent_id = coder_agent.example.id
openai_api_key = var.openai_api_key
folder = "/home/coder/project"
@@ -33,7 +33,7 @@ module "codex" {
module "codex" {
count = data.coder_workspace.me.start_count
source = "registry.coder.com/coder-labs/codex/coder"
version = "2.1.1"
version = "2.0.0"
agent_id = coder_agent.example.id
openai_api_key = "..."
folder = "/home/coder/project"
@@ -60,7 +60,7 @@ module "coder-login" {
module "codex" {
source = "registry.coder.com/coder-labs/codex/coder"
version = "2.1.1"
version = "2.0.0"
agent_id = coder_agent.example.id
openai_api_key = "..."
ai_prompt = data.coder_parameter.ai_prompt.value
@@ -106,7 +106,7 @@ For custom Codex configuration, use `base_config_toml` and/or `additional_mcp_se
```tf
module "codex" {
source = "registry.coder.com/coder-labs/codex/coder"
version = "2.1.1"
version = "2.0.0"
# ... other variables ...
# Override default configuration
+2 -3
View File
@@ -80,7 +80,7 @@ variable "install_agentapi" {
variable "agentapi_version" {
type = string
description = "The version of AgentAPI to install."
default = "v0.10.0"
default = "v0.5.0"
}
variable "codex_model" {
@@ -128,10 +128,9 @@ locals {
module "agentapi" {
source = "registry.coder.com/coder/agentapi/coder"
version = "1.2.0"
version = "1.1.1"
agent_id = var.agent_id
folder = var.folder
web_app_slug = local.app_slug
web_app_order = var.order
web_app_group = var.group
@@ -1,210 +0,0 @@
---
display_name: Copilot CLI
description: GitHub Copilot CLI agent for AI-powered terminal assistance
icon: ../../../../.icons/github.svg
verified: false
tags: [agent, copilot, ai, github, tasks]
---
# Copilot
Run [GitHub Copilot CLI](https://docs.github.com/copilot/concepts/agents/about-copilot-cli) in your workspace for AI-powered coding assistance directly from the terminal. This module integrates with [AgentAPI](https://github.com/coder/agentapi) for task reporting in the Coder UI.
```tf
module "copilot" {
source = "registry.coder.com/coder-labs/copilot/coder"
version = "0.2.1"
agent_id = coder_agent.example.id
workdir = "/home/coder/projects"
}
```
> [!IMPORTANT]
> This example assumes you have [Coder external authentication](https://coder.com/docs/admin/external-auth) configured with `id = "github"`. If not, you can provide a direct token using the `github_token` variable or provide the correct external authentication id for GitHub by setting `external_auth_id = "my-github"`.
> [!NOTE]
> By default, this module is configured to run the embedded chat interface as a path-based application. In production, we recommend that you configure a [wildcard access URL](https://coder.com/docs/admin/setup#wildcard-access-url) and set `subdomain = true`. See [here](https://coder.com/docs/tutorials/best-practices/security-best-practices#disable-path-based-apps) for more details.
## Prerequisites
- **Node.js v22+** and **npm v10+**
- **[Active Copilot subscription](https://docs.github.com/en/copilot/about-github-copilot/subscription-plans-for-github-copilot)** (GitHub Copilot Pro, Pro+, Business, or Enterprise)
- **GitHub authentication** via one of:
- [Coder external authentication](https://coder.com/docs/admin/external-auth) (recommended)
- Direct token via `github_token` variable
- Interactive login in Copilot
## Examples
### Usage with Tasks
For development environments where you want Copilot to have full access to tools and automatically resume sessions:
```tf
data "coder_parameter" "ai_prompt" {
type = "string"
name = "AI Prompt"
default = ""
description = "Initial task prompt for Copilot."
mutable = true
}
module "copilot" {
source = "registry.coder.com/coder-labs/copilot/coder"
version = "0.2.1"
agent_id = coder_agent.example.id
workdir = "/home/coder/projects"
ai_prompt = data.coder_parameter.ai_prompt.value
copilot_model = "claude-sonnet-4.5"
allow_all_tools = true
resume_session = true
trusted_directories = ["/home/coder/projects", "/tmp"]
}
```
### Advanced Configuration
Customize tool permissions, MCP servers, and Copilot settings:
```tf
module "copilot" {
source = "registry.coder.com/coder-labs/copilot/coder"
version = "0.2.1"
agent_id = coder_agent.example.id
workdir = "/home/coder/projects"
# Version pinning (defaults to "0.0.334", use "latest" for newest version)
copilot_version = "latest"
# Tool permissions
allow_tools = ["shell(git)", "shell(npm)", "write"]
trusted_directories = ["/home/coder/projects", "/tmp"]
# Custom Copilot configuration
copilot_config = jsonencode({
banner = "never"
theme = "dark"
})
# MCP server configuration
mcp_config = jsonencode({
mcpServers = {
filesystem = {
command = "npx"
args = ["-y", "@modelcontextprotocol/server-filesystem", "/home/coder/projects"]
description = "Provides file system access to the workspace"
name = "Filesystem"
timeout = 3000
type = "local"
tools = ["*"]
trust = true
}
playwright = {
command = "npx"
args = ["-y", "@playwright/mcp@latest", "--headless", "--isolated"]
description = "Browser automation for testing and previewing changes"
name = "Playwright"
timeout = 5000
type = "local"
tools = ["*"]
trust = false
}
}
})
# Pre-install Node.js if needed
pre_install_script = <<-EOT
#!/bin/bash
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
sudo apt-get install -y nodejs
EOT
}
```
> [!NOTE]
> GitHub Copilot CLI does not automatically install MCP servers. You have two options:
>
> - Use `npx -y` in the MCP config (shown above) to auto-install on each run
> - Pre-install MCP servers in `pre_install_script` for faster startup (e.g., `npm install -g @modelcontextprotocol/server-filesystem`)
### Direct Token Authentication
Use this example when you want to provide a GitHub Personal Access Token instead of using Coder external auth:
```tf
variable "github_token" {
type = string
description = "GitHub Personal Access Token"
sensitive = true
}
module "copilot" {
source = "registry.coder.com/coder-labs/copilot/coder"
version = "0.2.1"
agent_id = coder_agent.example.id
workdir = "/home/coder/projects"
github_token = var.github_token
}
```
### Standalone Mode
Run Copilot as a command-line tool without task reporting or web interface. This installs and configures Copilot, making it available as a CLI app in the Coder agent bar that you can launch to interact with Copilot directly from your terminal. Set `report_tasks = false` to disable integration with Coder Tasks.
```tf
module "copilot" {
source = "registry.coder.com/coder-labs/copilot/coder"
version = "0.2.1"
agent_id = coder_agent.example.id
workdir = "/home/coder"
report_tasks = false
cli_app = true
}
```
## Authentication
The module supports multiple authentication methods (in priority order):
1. **[Coder External Auth](https://coder.com/docs/admin/external-auth) (Recommended)** - Automatic if GitHub external auth is configured in Coder
2. **Direct Token** - Pass `github_token` variable (OAuth or Personal Access Token)
3. **Interactive** - Copilot prompts for login via `/login` command if no auth found
> [!NOTE]
> OAuth tokens work best with Copilot. Personal Access Tokens may have limited functionality.
## Session Resumption
By default, the module resumes the latest Copilot session when the workspace restarts. Set `resume_session = false` to always start fresh sessions.
> [!NOTE]
> Session resumption requires persistent storage for the home directory or workspace volume. Without persistent storage, sessions will not resume across workspace restarts.
## Troubleshooting
If you encounter any issues, check the log files in the `~/.copilot-module` directory within your workspace for detailed information.
```bash
# Installation logs
cat ~/.copilot-module/install.log
# Startup logs
cat ~/.copilot-module/agentapi-start.log
# Pre/post install script logs
cat ~/.copilot-module/pre_install.log
cat ~/.copilot-module/post_install.log
```
> [!NOTE]
> To use tasks with Copilot, you must have an active GitHub Copilot subscription.
> The `workdir` variable is required and specifies the directory where Copilot will run.
## References
- [GitHub Copilot CLI Documentation](https://docs.github.com/en/copilot/concepts/agents/about-copilot-cli)
- [Installing GitHub Copilot CLI](https://docs.github.com/en/copilot/how-tos/set-up/install-copilot-cli)
- [AgentAPI Documentation](https://github.com/coder/agentapi)
- [Coder AI Agents Guide](https://coder.com/docs/tutorials/ai-agents)
@@ -1,236 +0,0 @@
run "defaults_are_correct" {
command = plan
variables {
agent_id = "test-agent"
workdir = "/home/coder"
}
assert {
condition = var.copilot_model == "claude-sonnet-4.5"
error_message = "Default model should be 'claude-sonnet-4.5'"
}
assert {
condition = var.report_tasks == true
error_message = "Task reporting should be enabled by default"
}
assert {
condition = var.resume_session == true
error_message = "Session resumption should be enabled by default"
}
assert {
condition = var.allow_all_tools == false
error_message = "allow_all_tools should be disabled by default"
}
assert {
condition = resource.coder_env.mcp_app_status_slug.name == "CODER_MCP_APP_STATUS_SLUG"
error_message = "Status slug env var should be created"
}
assert {
condition = resource.coder_env.mcp_app_status_slug.value == "copilot"
error_message = "Status slug value should be 'copilot'"
}
}
run "github_token_creates_env_var" {
command = plan
variables {
agent_id = "test-agent"
workdir = "/home/coder"
github_token = "test_github_token_abc123"
}
assert {
condition = length(resource.coder_env.github_token) == 1
error_message = "github_token env var should be created when token is provided"
}
assert {
condition = resource.coder_env.github_token[0].name == "GITHUB_TOKEN"
error_message = "github_token env var name should be 'GITHUB_TOKEN'"
}
assert {
condition = resource.coder_env.github_token[0].value == "test_github_token_abc123"
error_message = "github_token env var value should match input"
}
}
run "github_token_not_created_when_empty" {
command = plan
variables {
agent_id = "test-agent"
workdir = "/home/coder"
github_token = ""
}
assert {
condition = length(resource.coder_env.github_token) == 0
error_message = "github_token env var should not be created when empty"
}
}
run "copilot_model_env_var_for_non_default" {
command = plan
variables {
agent_id = "test-agent"
workdir = "/home/coder"
copilot_model = "claude-sonnet-4"
}
assert {
condition = length(resource.coder_env.copilot_model) == 1
error_message = "copilot_model env var should be created for non-default model"
}
assert {
condition = resource.coder_env.copilot_model[0].name == "COPILOT_MODEL"
error_message = "copilot_model env var name should be 'COPILOT_MODEL'"
}
assert {
condition = resource.coder_env.copilot_model[0].value == "claude-sonnet-4"
error_message = "copilot_model env var value should match input"
}
}
run "copilot_model_not_created_for_default" {
command = plan
variables {
agent_id = "test-agent"
workdir = "/home/coder"
copilot_model = "claude-sonnet-4.5"
}
assert {
condition = length(resource.coder_env.copilot_model) == 0
error_message = "copilot_model env var should not be created for default model"
}
}
run "model_validation_accepts_valid_models" {
command = plan
variables {
agent_id = "test-agent"
workdir = "/home/coder"
copilot_model = "gpt-5"
}
assert {
condition = contains(["claude-sonnet-4", "claude-sonnet-4.5", "gpt-5"], var.copilot_model)
error_message = "Model should be one of the valid options"
}
}
run "copilot_config_merges_with_trusted_directories" {
command = plan
variables {
agent_id = "test-agent"
workdir = "/home/coder/project"
trusted_directories = ["/workspace", "/data"]
}
assert {
condition = length(local.final_copilot_config) > 0
error_message = "final_copilot_config should be computed"
}
# Verify workdir is trimmed of trailing slash
assert {
condition = local.workdir == "/home/coder/project"
error_message = "workdir should be trimmed of trailing slash"
}
}
run "custom_copilot_config_overrides_default" {
command = plan
variables {
agent_id = "test-agent"
workdir = "/home/coder"
copilot_config = jsonencode({
banner = "always"
theme = "dark"
})
}
assert {
condition = var.copilot_config != ""
error_message = "Custom copilot config should be set"
}
assert {
condition = jsondecode(local.final_copilot_config).banner == "always"
error_message = "Custom banner setting should be applied"
}
assert {
condition = jsondecode(local.final_copilot_config).theme == "dark"
error_message = "Custom theme setting should be applied"
}
}
run "trusted_directories_merged_with_custom_config" {
command = plan
variables {
agent_id = "test-agent"
workdir = "/home/coder/project"
copilot_config = jsonencode({
banner = "always"
theme = "dark"
trusted_folders = ["/custom"]
})
trusted_directories = ["/workspace", "/data"]
}
assert {
condition = contains(jsondecode(local.final_copilot_config).trusted_folders, "/custom")
error_message = "Custom trusted folder should be included"
}
assert {
condition = contains(jsondecode(local.final_copilot_config).trusted_folders, "/home/coder/project")
error_message = "Workdir should be included in trusted folders"
}
assert {
condition = contains(jsondecode(local.final_copilot_config).trusted_folders, "/workspace")
error_message = "trusted_directories should be merged into config"
}
assert {
condition = contains(jsondecode(local.final_copilot_config).trusted_folders, "/data")
error_message = "All trusted_directories should be merged into config"
}
}
run "app_slug_is_consistent" {
command = plan
variables {
agent_id = "test-agent"
workdir = "/home/coder"
}
assert {
condition = local.app_slug == "copilot"
error_message = "app_slug should be 'copilot'"
}
assert {
condition = local.module_dir_name == ".copilot-module"
error_message = "module_dir_name should be '.copilot-module'"
}
}
@@ -1,136 +0,0 @@
import { describe, expect, it } from "bun:test";
import {
findResourceInstance,
runTerraformApply,
runTerraformInit,
testRequiredVariables,
} from "~test";
describe("copilot", async () => {
await runTerraformInit(import.meta.dir);
testRequiredVariables(import.meta.dir, {
agent_id: "test-agent",
workdir: "/home/coder",
});
it("creates mcp_app_status_slug env var", async () => {
const state = await runTerraformApply(import.meta.dir, {
agent_id: "test-agent",
workdir: "/home/coder",
});
const statusSlugEnv = findResourceInstance(
state,
"coder_env",
"mcp_app_status_slug",
);
expect(statusSlugEnv).toBeDefined();
expect(statusSlugEnv.name).toBe("CODER_MCP_APP_STATUS_SLUG");
expect(statusSlugEnv.value).toBe("copilot");
});
it("creates github_token env var with correct value", async () => {
const state = await runTerraformApply(import.meta.dir, {
agent_id: "test-agent",
workdir: "/home/coder",
github_token: "test_token_12345",
});
const githubTokenEnv = findResourceInstance(
state,
"coder_env",
"github_token",
);
expect(githubTokenEnv).toBeDefined();
expect(githubTokenEnv.name).toBe("GITHUB_TOKEN");
expect(githubTokenEnv.value).toBe("test_token_12345");
});
it("does not create github_token env var when empty", async () => {
const state = await runTerraformApply(import.meta.dir, {
agent_id: "test-agent",
workdir: "/home/coder",
github_token: "",
});
const githubTokenEnvs = state.resources.filter(
(r) => r.type === "coder_env" && r.name === "github_token",
);
expect(githubTokenEnvs.length).toBe(0);
});
it("creates copilot_model env var for non-default models", async () => {
const state = await runTerraformApply(import.meta.dir, {
agent_id: "test-agent",
workdir: "/home/coder",
copilot_model: "claude-sonnet-4",
});
const modelEnv = findResourceInstance(state, "coder_env", "copilot_model");
expect(modelEnv).toBeDefined();
expect(modelEnv.name).toBe("COPILOT_MODEL");
expect(modelEnv.value).toBe("claude-sonnet-4");
});
it("does not create copilot_model env var for default model", async () => {
const state = await runTerraformApply(import.meta.dir, {
agent_id: "test-agent",
workdir: "/home/coder",
copilot_model: "claude-sonnet-4.5",
});
const modelEnvs = state.resources.filter(
(r) => r.type === "coder_env" && r.name === "copilot_model",
);
expect(modelEnvs.length).toBe(0);
});
it("creates coder_script resources via agentapi module", async () => {
const state = await runTerraformApply(import.meta.dir, {
agent_id: "test-agent",
workdir: "/home/coder",
});
// The agentapi module should create coder_script resources for install and start
const scripts = state.resources.filter((r) => r.type === "coder_script");
expect(scripts.length).toBeGreaterThan(0);
});
it("validates copilot_model accepts valid values", async () => {
// Test valid models don't throw errors
await expect(
runTerraformApply(import.meta.dir, {
agent_id: "test-agent",
workdir: "/home/coder",
copilot_model: "gpt-5",
}),
).resolves.toBeDefined();
await expect(
runTerraformApply(import.meta.dir, {
agent_id: "test-agent",
workdir: "/home/coder",
copilot_model: "claude-sonnet-4.5",
}),
).resolves.toBeDefined();
});
it("merges trusted_directories with custom copilot_config", async () => {
const state = await runTerraformApply(import.meta.dir, {
agent_id: "test-agent",
workdir: "/home/coder/project",
trusted_directories: JSON.stringify(["/workspace", "/data"]),
copilot_config: JSON.stringify({
banner: "always",
theme: "dark",
trusted_folders: ["/custom"],
}),
});
// Verify that the state was created successfully with the merged config
// The actual merging logic is tested in the .tftest.hcl file
expect(state).toBeDefined();
expect(state.resources).toBeDefined();
});
});
-302
View File
@@ -1,302 +0,0 @@
terraform {
required_version = ">= 1.0"
required_providers {
coder = {
source = "coder/coder"
version = ">= 2.7"
}
}
}
variable "agent_id" {
type = string
description = "The ID of a Coder agent."
}
variable "workdir" {
type = string
description = "The folder to run Copilot in."
}
variable "external_auth_id" {
type = string
description = "ID of the GitHub external auth provider configured in Coder."
default = "github"
}
variable "github_token" {
type = string
description = "GitHub OAuth token or Personal Access Token. If provided, this will be used instead of auto-detecting authentication."
default = ""
sensitive = true
}
variable "copilot_model" {
type = string
description = "Model to use. Supported values: claude-sonnet-4, claude-sonnet-4.5 (default), gpt-5."
default = "claude-sonnet-4.5"
validation {
condition = contains(["claude-sonnet-4", "claude-sonnet-4.5", "gpt-5"], var.copilot_model)
error_message = "copilot_model must be one of: claude-sonnet-4, claude-sonnet-4.5, gpt-5."
}
}
variable "copilot_config" {
type = string
description = "Custom Copilot configuration as JSON string. Leave empty to use default configuration with banner disabled, theme set to auto, and workdir as trusted folder."
default = ""
}
variable "ai_prompt" {
type = string
description = "Initial task prompt for programmatic mode."
default = ""
}
variable "system_prompt" {
type = string
description = "The system prompt to use for the Copilot server. Task reporting instructions are automatically added when report_tasks is enabled."
default = "You are a helpful coding assistant that helps developers write, debug, and understand code. Provide clear explanations, follow best practices, and help solve coding problems efficiently."
}
variable "trusted_directories" {
type = list(string)
description = "Additional directories to trust for Copilot operations."
default = []
}
variable "allow_all_tools" {
type = bool
description = "Allow all tools without prompting (equivalent to --allow-all-tools)."
default = false
}
variable "allow_tools" {
type = list(string)
description = "Specific tools to allow: shell(command), write, or MCP_SERVER_NAME."
default = []
}
variable "deny_tools" {
type = list(string)
description = "Specific tools to deny: shell(command), write, or MCP_SERVER_NAME."
default = []
}
variable "mcp_config" {
type = string
description = "Custom MCP server configuration as JSON string."
default = ""
}
variable "install_agentapi" {
type = bool
description = "Whether to install AgentAPI."
default = true
}
variable "agentapi_version" {
type = string
description = "The version of AgentAPI to install."
default = "v0.10.0"
}
variable "copilot_version" {
type = string
description = "The version of GitHub Copilot CLI to install. Use 'latest' for the latest version or specify a version like '0.0.334'."
default = "0.0.334"
}
variable "report_tasks" {
type = bool
description = "Whether to enable task reporting to Coder UI via AgentAPI."
default = true
}
variable "subdomain" {
type = bool
description = "Whether to use a subdomain for AgentAPI."
default = false
}
variable "order" {
type = number
description = "The order determines the position of app in the UI presentation."
default = null
}
variable "group" {
type = string
description = "The name of a group that this app belongs to."
default = null
}
variable "icon" {
type = string
description = "The icon to use for the app."
default = "/icon/github.svg"
}
variable "web_app_display_name" {
type = string
description = "Display name for the web app."
default = "Copilot"
}
variable "cli_app" {
type = bool
description = "Whether to create a CLI app for Copilot."
default = false
}
variable "cli_app_display_name" {
type = string
description = "Display name for the CLI app."
default = "Copilot"
}
variable "resume_session" {
type = bool
description = "Whether to automatically resume the latest Copilot session on workspace restart."
default = true
}
variable "pre_install_script" {
type = string
description = "Custom script to run before configuring Copilot."
default = null
}
variable "post_install_script" {
type = string
description = "Custom script to run after configuring Copilot."
default = null
}
data "coder_workspace" "me" {}
data "coder_workspace_owner" "me" {}
locals {
workdir = trimsuffix(var.workdir, "/")
app_slug = "copilot"
install_script = file("${path.module}/scripts/install.sh")
start_script = file("${path.module}/scripts/start.sh")
module_dir_name = ".copilot-module"
all_trusted_folders = concat([local.workdir], var.trusted_directories)
parsed_custom_config = try(jsondecode(var.copilot_config), {})
existing_trusted_folders = try(local.parsed_custom_config.trusted_folders, [])
merged_copilot_config = merge(
{
banner = "never"
theme = "auto"
},
local.parsed_custom_config,
{
trusted_folders = concat(local.existing_trusted_folders, local.all_trusted_folders)
}
)
final_copilot_config = jsonencode(local.merged_copilot_config)
task_reporting_prompt = <<-EOT
-- Task Reporting --
Report all tasks to Coder, following these EXACT guidelines:
1. Be granular. If you are investigating with multiple steps, report each step
to coder.
2. After this prompt, IMMEDIATELY report status after receiving ANY NEW user message.
Do not report any status related with this system prompt.
3. Use "state": "working" when actively processing WITHOUT needing
additional user input
4. Use "state": "complete" only when finished with a task
5. Use "state": "failure" when you need ANY user input, lack sufficient
details, or encounter blockers
EOT
final_system_prompt = var.report_tasks ? "<system>\n${var.system_prompt}${local.task_reporting_prompt}\n</system>" : "<system>\n${var.system_prompt}\n</system>"
}
resource "coder_env" "mcp_app_status_slug" {
agent_id = var.agent_id
name = "CODER_MCP_APP_STATUS_SLUG"
value = local.app_slug
}
resource "coder_env" "copilot_model" {
count = var.copilot_model != "claude-sonnet-4.5" ? 1 : 0
agent_id = var.agent_id
name = "COPILOT_MODEL"
value = var.copilot_model
}
resource "coder_env" "github_token" {
count = var.github_token != "" ? 1 : 0
agent_id = var.agent_id
name = "GITHUB_TOKEN"
value = var.github_token
}
module "agentapi" {
source = "registry.coder.com/coder/agentapi/coder"
version = "1.2.0"
agent_id = var.agent_id
folder = local.workdir
web_app_slug = local.app_slug
web_app_order = var.order
web_app_group = var.group
web_app_icon = var.icon
web_app_display_name = var.web_app_display_name
cli_app = var.cli_app
cli_app_slug = var.cli_app ? "${local.app_slug}-cli" : null
cli_app_icon = var.cli_app ? var.icon : null
cli_app_display_name = var.cli_app ? var.cli_app_display_name : null
agentapi_subdomain = var.subdomain
module_dir_name = local.module_dir_name
install_agentapi = var.install_agentapi
agentapi_version = var.agentapi_version
pre_install_script = var.pre_install_script
post_install_script = var.post_install_script
start_script = <<-EOT
#!/bin/bash
set -o errexit
set -o pipefail
echo -n '${base64encode(local.start_script)}' | base64 -d > /tmp/start.sh
chmod +x /tmp/start.sh
ARG_WORKDIR='${local.workdir}' \
ARG_AI_PROMPT='${base64encode(var.ai_prompt)}' \
ARG_SYSTEM_PROMPT='${base64encode(local.final_system_prompt)}' \
ARG_COPILOT_MODEL='${var.copilot_model}' \
ARG_ALLOW_ALL_TOOLS='${var.allow_all_tools}' \
ARG_ALLOW_TOOLS='${join(",", var.allow_tools)}' \
ARG_DENY_TOOLS='${join(",", var.deny_tools)}' \
ARG_TRUSTED_DIRECTORIES='${join(",", var.trusted_directories)}' \
ARG_EXTERNAL_AUTH_ID='${var.external_auth_id}' \
ARG_RESUME_SESSION='${var.resume_session}' \
/tmp/start.sh
EOT
install_script = <<-EOT
#!/bin/bash
set -o errexit
set -o pipefail
echo -n '${base64encode(local.install_script)}' | base64 -d > /tmp/install.sh
chmod +x /tmp/install.sh
ARG_MCP_APP_STATUS_SLUG='${local.app_slug}' \
ARG_REPORT_TASKS='${var.report_tasks}' \
ARG_WORKDIR='${local.workdir}' \
ARG_MCP_CONFIG='${var.mcp_config != "" ? base64encode(var.mcp_config) : ""}' \
ARG_COPILOT_CONFIG='${base64encode(local.final_copilot_config)}' \
ARG_EXTERNAL_AUTH_ID='${var.external_auth_id}' \
ARG_COPILOT_VERSION='${var.copilot_version}' \
ARG_COPILOT_MODEL='${var.copilot_model}' \
/tmp/install.sh
EOT
}
@@ -1,234 +0,0 @@
#!/bin/bash
set -euo pipefail
source "$HOME"/.bashrc
command_exists() {
command -v "$1" > /dev/null 2>&1
}
ARG_WORKDIR=${ARG_WORKDIR:-"$HOME"}
ARG_REPORT_TASKS=${ARG_REPORT_TASKS:-true}
ARG_MCP_APP_STATUS_SLUG=${ARG_MCP_APP_STATUS_SLUG:-}
ARG_MCP_CONFIG=$(echo -n "${ARG_MCP_CONFIG:-}" | base64 -d 2> /dev/null || echo "")
ARG_COPILOT_CONFIG=$(echo -n "${ARG_COPILOT_CONFIG:-}" | base64 -d 2> /dev/null || echo "")
ARG_EXTERNAL_AUTH_ID=${ARG_EXTERNAL_AUTH_ID:-github}
ARG_COPILOT_VERSION=${ARG_COPILOT_VERSION:-0.0.334}
ARG_COPILOT_MODEL=${ARG_COPILOT_MODEL:-claude-sonnet-4.5}
validate_prerequisites() {
if ! command_exists node; then
echo "ERROR: Node.js not found. Copilot requires Node.js v22+."
echo "Install with: curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash - && sudo apt-get install -y nodejs"
exit 1
fi
if ! command_exists npm; then
echo "ERROR: npm not found. Copilot requires npm v10+."
exit 1
fi
node_version=$(node --version | sed 's/v//' | cut -d. -f1)
if [ "$node_version" -lt 22 ]; then
echo "WARNING: Node.js v$node_version detected. Copilot requires v22+."
fi
}
install_copilot() {
if ! command_exists copilot; then
echo "Installing GitHub Copilot CLI (version: ${ARG_COPILOT_VERSION})..."
if [ "$ARG_COPILOT_VERSION" = "latest" ]; then
npm install -g @github/copilot
else
npm install -g "@github/copilot@${ARG_COPILOT_VERSION}"
fi
if ! command_exists copilot; then
echo "ERROR: Failed to install Copilot"
exit 1
fi
echo "GitHub Copilot CLI installed successfully"
else
echo "GitHub Copilot CLI already installed"
fi
}
check_github_authentication() {
echo "Checking GitHub authentication..."
if [ -n "${GITHUB_TOKEN:-}" ]; then
echo "✓ GitHub token provided via module configuration"
return 0
fi
if command_exists coder; then
if coder external-auth access-token "${ARG_EXTERNAL_AUTH_ID:-github}" > /dev/null 2>&1; then
echo "✓ GitHub OAuth authentication via Coder external auth"
return 0
fi
fi
if command_exists gh && gh auth status > /dev/null 2>&1; then
echo "✓ GitHub OAuth authentication via GitHub CLI"
return 0
fi
echo "⚠ No GitHub authentication detected"
echo " Copilot will prompt for authentication when started"
echo " For seamless experience, configure GitHub external auth in Coder or run 'gh auth login'"
return 0
}
setup_copilot_configurations() {
mkdir -p "$ARG_WORKDIR"
local module_path="$HOME/.copilot-module"
mkdir -p "$module_path"
setup_copilot_config
echo "$ARG_WORKDIR" > "$module_path/trusted_directories"
}
setup_copilot_config() {
export XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
local copilot_config_dir="$XDG_CONFIG_HOME/.copilot"
local copilot_config_file="$copilot_config_dir/config.json"
local mcp_config_file="$copilot_config_dir/mcp-config.json"
mkdir -p "$copilot_config_dir"
if [ -n "$ARG_COPILOT_CONFIG" ]; then
echo "Setting up Copilot configuration..."
if command_exists jq; then
echo "$ARG_COPILOT_CONFIG" | jq 'del(.mcpServers)' > "$copilot_config_file"
else
echo "$ARG_COPILOT_CONFIG" > "$copilot_config_file"
fi
echo "Setting up MCP server configuration..."
setup_mcp_config "$mcp_config_file"
else
echo "ERROR: No Copilot configuration provided"
exit 1
fi
}
setup_mcp_config() {
local mcp_config_file="$1"
echo '{"mcpServers": {}}' > "$mcp_config_file"
if [ "$ARG_REPORT_TASKS" = "true" ] && [ -n "$ARG_MCP_APP_STATUS_SLUG" ]; then
echo "Adding Coder MCP server for task reporting..."
setup_coder_mcp_server "$mcp_config_file"
fi
if [ -n "$ARG_MCP_CONFIG" ]; then
echo "Adding custom MCP servers..."
add_custom_mcp_servers "$mcp_config_file"
fi
echo "MCP configuration completed: $mcp_config_file"
}
setup_coder_mcp_server() {
local mcp_config_file="$1"
local coder_mcp_wrapper_script
coder_mcp_wrapper_script=$(
cat << EOF
#!/usr/bin/env bash
set -e
export CODER_MCP_APP_STATUS_SLUG="${ARG_MCP_APP_STATUS_SLUG}"
export CODER_MCP_AI_AGENTAPI_URL="http://localhost:3284"
export CODER_AGENT_URL="${CODER_AGENT_URL}"
export CODER_AGENT_TOKEN="${CODER_AGENT_TOKEN}"
exec coder exp mcp server
EOF
)
echo "$coder_mcp_wrapper_script" > "/tmp/coder-mcp-server.sh"
chmod +x /tmp/coder-mcp-server.sh
local coder_mcp_config
coder_mcp_config=$(
cat << EOF
{
"mcpServers": {
"coder": {
"command": "/tmp/coder-mcp-server.sh",
"args": [],
"description": "CRITICAL: Call this tool immediately after receiving ANY user message to report task status. Rules: (1) Call FIRST before doing work - report what you will do with state='working'. (2) Be granular - report each step separately. (3) State 'working' = actively processing without needing user input. (4) State 'complete' = task 100% finished. (5) State 'failure' = need user input, missing info, or blocked. Example: User says 'fix the bug' -> call with state='working', description='Investigating authentication bug'. When done -> call with state='complete', description='Fixed token validation'. You MUST report on every interaction.",
"name": "Coder",
"timeout": 3000,
"type": "local",
"tools": ["*"],
"trust": true
}
}
}
EOF
)
echo "$coder_mcp_config" > "$mcp_config_file"
}
add_custom_mcp_servers() {
local mcp_config_file="$1"
if command_exists jq; then
local custom_servers
custom_servers=$(echo "$ARG_MCP_CONFIG" | jq '.mcpServers // {}')
local updated_config
updated_config=$(jq --argjson custom "$custom_servers" '.mcpServers += $custom' "$mcp_config_file")
echo "$updated_config" > "$mcp_config_file"
elif command_exists node; then
node -e "
const fs = require('fs');
const existing = JSON.parse(fs.readFileSync('$mcp_config_file', 'utf8'));
const input = JSON.parse(\`$ARG_MCP_CONFIG\`);
const custom = input.mcpServers || {};
existing.mcpServers = {...existing.mcpServers, ...custom};
fs.writeFileSync('$mcp_config_file', JSON.stringify(existing, null, 2));
"
else
echo "WARNING: jq and node not available, cannot merge custom MCP servers"
fi
}
configure_copilot_model() {
if [ -n "$ARG_COPILOT_MODEL" ] && [ "$ARG_COPILOT_MODEL" != "claude-sonnet-4.5" ]; then
echo "Setting Copilot model to: $ARG_COPILOT_MODEL"
copilot config model "$ARG_COPILOT_MODEL" || {
echo "WARNING: Failed to set model via copilot config, will use environment variable fallback"
export COPILOT_MODEL="$ARG_COPILOT_MODEL"
}
fi
}
configure_coder_integration() {
if [ "$ARG_REPORT_TASKS" = "true" ] && [ -n "$ARG_MCP_APP_STATUS_SLUG" ]; then
echo "Configuring Copilot task reporting..."
export CODER_MCP_APP_STATUS_SLUG="$ARG_MCP_APP_STATUS_SLUG"
export CODER_MCP_AI_AGENTAPI_URL="http://localhost:3284"
echo "✓ Coder MCP server configured for task reporting"
else
echo "Task reporting disabled or no app status slug provided."
export CODER_MCP_APP_STATUS_SLUG=""
export CODER_MCP_AI_AGENTAPI_URL=""
fi
}
validate_prerequisites
install_copilot
check_github_authentication
setup_copilot_configurations
configure_copilot_model
configure_coder_integration
echo "Copilot module setup completed."
@@ -1,157 +0,0 @@
#!/bin/bash
set -euo pipefail
source "$HOME"/.bashrc
export PATH="$HOME/.local/bin:$PATH"
command_exists() {
command -v "$1" > /dev/null 2>&1
}
ARG_WORKDIR=${ARG_WORKDIR:-"$HOME"}
ARG_AI_PROMPT=$(echo -n "${ARG_AI_PROMPT:-}" | base64 -d 2> /dev/null || echo "")
ARG_SYSTEM_PROMPT=$(echo -n "${ARG_SYSTEM_PROMPT:-}" | base64 -d 2> /dev/null || echo "")
ARG_COPILOT_MODEL=${ARG_COPILOT_MODEL:-}
ARG_ALLOW_ALL_TOOLS=${ARG_ALLOW_ALL_TOOLS:-false}
ARG_ALLOW_TOOLS=${ARG_ALLOW_TOOLS:-}
ARG_DENY_TOOLS=${ARG_DENY_TOOLS:-}
ARG_TRUSTED_DIRECTORIES=${ARG_TRUSTED_DIRECTORIES:-}
ARG_EXTERNAL_AUTH_ID=${ARG_EXTERNAL_AUTH_ID:-github}
ARG_RESUME_SESSION=${ARG_RESUME_SESSION:-true}
validate_copilot_installation() {
if ! command_exists copilot; then
echo "ERROR: Copilot not installed. Run: npm install -g @github/copilot"
exit 1
fi
}
build_initial_prompt() {
local initial_prompt=""
if [ -n "$ARG_AI_PROMPT" ]; then
if [ -n "$ARG_SYSTEM_PROMPT" ]; then
initial_prompt="$ARG_SYSTEM_PROMPT
$ARG_AI_PROMPT"
else
initial_prompt="$ARG_AI_PROMPT"
fi
fi
echo "$initial_prompt"
}
build_copilot_args() {
COPILOT_ARGS=()
if [ "$ARG_ALLOW_ALL_TOOLS" = "true" ]; then
COPILOT_ARGS+=(--allow-all-tools)
fi
if [ -n "$ARG_ALLOW_TOOLS" ]; then
IFS=',' read -ra ALLOW_ARRAY <<< "$ARG_ALLOW_TOOLS"
for tool in "${ALLOW_ARRAY[@]}"; do
if [ -n "$tool" ]; then
COPILOT_ARGS+=(--allow-tool "$tool")
fi
done
fi
if [ -n "$ARG_DENY_TOOLS" ]; then
IFS=',' read -ra DENY_ARRAY <<< "$ARG_DENY_TOOLS"
for tool in "${DENY_ARRAY[@]}"; do
if [ -n "$tool" ]; then
COPILOT_ARGS+=(--deny-tool "$tool")
fi
done
fi
}
check_existing_session() {
if [ "$ARG_RESUME_SESSION" = "true" ]; then
if copilot --help > /dev/null 2>&1; then
local session_dir="$HOME/.copilot/history-session-state"
if [ -d "$session_dir" ] && [ -n "$(ls "$session_dir"/session_*_*.json 2> /dev/null)" ]; then
echo "Found existing Copilot session. Will continue latest session." >&2
return 0
fi
fi
fi
return 1
}
setup_github_authentication() {
export XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
echo "Setting up GitHub authentication..."
if [ -n "${GITHUB_TOKEN:-}" ]; then
export GH_TOKEN="$GITHUB_TOKEN"
echo "✓ Using GitHub token from module configuration"
return 0
fi
if command_exists coder; then
local github_token
if github_token=$(coder external-auth access-token "${ARG_EXTERNAL_AUTH_ID:-github}" 2> /dev/null); then
if [ -n "$github_token" ] && [ "$github_token" != "null" ]; then
export GITHUB_TOKEN="$github_token"
export GH_TOKEN="$github_token"
echo "✓ Using Coder external auth OAuth token"
return 0
fi
fi
fi
if command_exists gh && gh auth status > /dev/null 2>&1; then
echo "✓ Using GitHub CLI OAuth authentication"
return 0
fi
echo "⚠ No GitHub authentication available"
echo " Copilot will prompt for login during first use"
echo " Use the '/login' command in Copilot to authenticate"
return 0
}
start_agentapi() {
echo "Starting in directory: $ARG_WORKDIR"
cd "$ARG_WORKDIR"
build_copilot_args
if check_existing_session; then
echo "Continuing latest Copilot session..."
if [ ${#COPILOT_ARGS[@]} -gt 0 ]; then
echo "Copilot arguments: ${COPILOT_ARGS[*]}"
agentapi server --type copilot --term-width 120 --term-height 40 -- copilot --continue "${COPILOT_ARGS[@]}"
else
agentapi server --type copilot --term-width 120 --term-height 40 -- copilot --continue
fi
else
echo "Starting new Copilot session..."
local initial_prompt
initial_prompt=$(build_initial_prompt)
if [ -n "$initial_prompt" ]; then
echo "Using initial prompt with system context"
if [ ${#COPILOT_ARGS[@]} -gt 0 ]; then
echo "Copilot arguments: ${COPILOT_ARGS[*]}"
agentapi server -I="$initial_prompt" --type copilot --term-width 120 --term-height 40 -- copilot "${COPILOT_ARGS[@]}"
else
agentapi server -I="$initial_prompt" --type copilot --term-width 120 --term-height 40 -- copilot
fi
else
if [ ${#COPILOT_ARGS[@]} -gt 0 ]; then
echo "Copilot arguments: ${COPILOT_ARGS[*]}"
agentapi server --type copilot --term-width 120 --term-height 40 -- copilot "${COPILOT_ARGS[@]}"
else
agentapi server --type copilot --term-width 120 --term-height 40 -- copilot
fi
fi
fi
}
setup_github_authentication
validate_copilot_installation
start_agentapi
@@ -1,12 +0,0 @@
#!/bin/bash
set -euo pipefail
if [[ "$1" == "--version" ]]; then
echo "GitHub Copilot CLI v1.0.0"
exit 0
fi
while true; do
echo "$(date) - Copilot mock running..."
sleep 15
done
@@ -13,7 +13,7 @@ Run the Cursor Agent CLI in your workspace for interactive coding assistance and
```tf
module "cursor_cli" {
source = "registry.coder.com/coder-labs/cursor-cli/coder"
version = "0.2.0"
version = "0.1.1"
agent_id = coder_agent.example.id
folder = "/home/coder/project"
}
@@ -42,7 +42,7 @@ module "coder-login" {
module "cursor_cli" {
source = "registry.coder.com/coder-labs/cursor-cli/coder"
version = "0.2.0"
version = "0.1.1"
agent_id = coder_agent.example.id
folder = "/home/coder/project"
@@ -56,7 +56,7 @@ variable "install_agentapi" {
variable "agentapi_version" {
type = string
description = "The version of AgentAPI to install."
default = "v0.10.0"
default = "v0.5.0"
}
variable "force" {
@@ -131,7 +131,7 @@ resource "coder_env" "cursor_api_key" {
module "agentapi" {
source = "registry.coder.com/coder/agentapi/coder"
version = "1.2.0"
version = "1.1.1"
agent_id = var.agent_id
web_app_slug = local.app_slug
+4 -4
View File
@@ -13,7 +13,7 @@ Run [Gemini CLI](https://github.com/google-gemini/gemini-cli) in your workspace
```tf
module "gemini" {
source = "registry.coder.com/coder-labs/gemini/coder"
version = "2.1.0"
version = "2.0.0"
agent_id = coder_agent.example.id
folder = "/home/coder/project"
}
@@ -46,7 +46,7 @@ variable "gemini_api_key" {
module "gemini" {
source = "registry.coder.com/coder-labs/gemini/coder"
version = "2.1.0"
version = "2.0.0"
agent_id = coder_agent.example.id
gemini_api_key = var.gemini_api_key
folder = "/home/coder/project"
@@ -94,7 +94,7 @@ data "coder_parameter" "ai_prompt" {
module "gemini" {
count = data.coder_workspace.me.start_count
source = "registry.coder.com/coder-labs/gemini/coder"
version = "2.1.0"
version = "2.0.0"
agent_id = coder_agent.example.id
gemini_api_key = var.gemini_api_key
gemini_model = "gemini-2.5-flash"
@@ -118,7 +118,7 @@ For enterprise users who prefer Google's Vertex AI platform:
```tf
module "gemini" {
source = "registry.coder.com/coder-labs/gemini/coder"
version = "2.1.0"
version = "2.0.0"
agent_id = coder_agent.example.id
gemini_api_key = var.gemini_api_key
folder = "/home/coder/project"
+2 -2
View File
@@ -81,7 +81,7 @@ variable "install_agentapi" {
variable "agentapi_version" {
type = string
description = "The version of AgentAPI to install."
default = "v0.10.0"
default = "v0.2.3"
}
variable "gemini_model" {
@@ -176,7 +176,7 @@ EOT
module "agentapi" {
source = "registry.coder.com/coder/agentapi/coder"
version = "1.2.0"
version = "1.1.1"
agent_id = var.agent_id
web_app_slug = local.app_slug
@@ -1,22 +0,0 @@
---
display_name: Nextflow
description: A module that adds Nextflow to your Coder template.
icon: ../../../../.icons/nextflow.svg
verified: true
tags: [nextflow, workflow, hpc, bioinformatics]
---
# Nextflow
A module that adds Nextflow to your Coder template.
![Nextflow](../../.images/nextflow.png)
```tf
module "nextflow" {
count = data.coder_workspace.me.start_count
source = "registry.coder.com/coder-labs/nextflow/coder"
version = "0.9.0"
agent_id = coder_agent.example.id
}
```
@@ -1,106 +0,0 @@
terraform {
required_version = ">= 1.0"
required_providers {
coder = {
source = "coder/coder"
version = ">= 2.5"
}
}
}
# Add required variables for your modules and remove any unneeded variables
variable "agent_id" {
type = string
description = "The ID of a Coder agent."
}
variable "nextflow_version" {
type = string
description = "Nextflow version"
default = "25.04.7"
}
variable "project_path" {
type = string
description = "The path to Nextflow project, it will be mounted in the container."
}
variable "http_server_port" {
type = number
description = "The port to run HTTP server on."
default = 9876
}
variable "http_server_reports_dir" {
type = string
description = "Subdirectory for HTTP server reports, relative to the project path."
default = "reports"
}
variable "http_server_log_path" {
type = string
description = "HTTP server logs"
default = "/tmp/nextflow_reports.log"
}
variable "stub_run" {
type = bool
description = "Execute a stub run?"
default = false
}
variable "stub_run_command" {
type = string
description = "Nextflow command to be executed in the stub run."
default = "run rnaseq-nf -with-report reports/report.html -with-trace reports/trace.txt -with-timeline reports/timeline.html -with-dag reports/flowchart.png"
}
variable "order" {
type = number
description = "The order determines the position of app in the UI presentation. The lowest order is shown first and apps with equal order are sorted by name (ascending order)."
default = null
}
variable "share" {
type = string
default = "owner"
validation {
condition = var.share == "owner" || var.share == "authenticated" || var.share == "public"
error_message = "Incorrect value. Please set either 'owner', 'authenticated', or 'public'."
}
}
variable "group" {
type = string
description = "The name of a group that this app belongs to."
default = null
}
resource "coder_script" "nextflow" {
agent_id = var.agent_id
display_name = "nextflow"
icon = "/icon/nextflow.svg"
script = templatefile("${path.module}/run.sh", {
NEXTFLOW_VERSION : var.nextflow_version,
PROJECT_PATH : var.project_path,
HTTP_SERVER_PORT : var.http_server_port,
HTTP_SERVER_REPORTS_DIR : var.http_server_reports_dir,
HTTP_SERVER_LOG_PATH : var.http_server_log_path,
STUB_RUN : var.stub_run,
STUB_RUN_COMMAND : var.stub_run_command,
})
run_on_start = true
}
resource "coder_app" "nextflow" {
agent_id = var.agent_id
slug = "nextflow-reports"
display_name = "Nextflow Reports"
url = "http://localhost:${var.http_server_port}"
icon = "/icon/nextflow.svg"
subdomain = true
share = var.share
order = var.order
group = var.group
}
@@ -1,49 +0,0 @@
#!/usr/bin/env sh
set -eu
BOLD='\033[0;1m'
RESET='\033[0m'
printf "$${BOLD}Starting Nextflow...$${RESET}\n"
if ! command -v nextflow > /dev/null 2>&1; then
# Update system dependencies
sudo apt update
sudo apt install openjdk-21-jdk graphviz salmon fastqc multiqc -y
# Install nextflow
export NXF_VER=${NEXTFLOW_VERSION}
curl -s https://get.nextflow.io | bash
sudo mv nextflow /usr/local/bin/
sudo chmod +x /usr/local/bin/nextflow
# Verify installation
tmp_verify=$(mktemp -d coder-nextflow-XXXXXX)
nextflow run hello \
-with-report "$${tmp_verify}/report.html" \
-with-trace "$${tmp_verify}/trace.txt" \
-with-timeline "$${tmp_verify}/timeline.html" \
-with-dag "$${tmp_verify}/flowchart.png"
rm -r "$${tmp_verify}"
else
echo "Nextflow is already installed\n\n"
fi
if [ ! -z ${PROJECT_PATH} ]; then
# Project is located at PROJECT_PATH
echo "Change directory: ${PROJECT_PATH}"
cd ${PROJECT_PATH}
fi
# Start a web server to preview reports
mkdir -p ${HTTP_SERVER_REPORTS_DIR}
echo "Starting HTTP server in background, check logs: ${HTTP_SERVER_LOG_PATH}"
python3 -m http.server --directory ${HTTP_SERVER_REPORTS_DIR} ${HTTP_SERVER_PORT} > "${HTTP_SERVER_LOG_PATH}" 2>&1 &
# Stub run?
if [ "${STUB_RUN}" = "true" ]; then
nextflow ${STUB_RUN_COMMAND} -stub-run
fi
printf "\n$${BOLD}Nextflow ${NEXTFLOW_VERSION} is ready. HTTP server is listening on port ${HTTP_SERVER_PORT}$${RESET}\n"
@@ -13,7 +13,7 @@ Run [Amp CLI](https://ampcode.com/) in your workspace to access Sourcegraph's AI
```tf
module "amp-cli" {
source = "registry.coder.com/coder-labs/sourcegraph-amp/coder"
version = "1.1.0"
version = "1.0.3"
agent_id = coder_agent.example.id
sourcegraph_amp_api_key = var.sourcegraph_amp_api_key
install_sourcegraph_amp = true
@@ -60,7 +60,7 @@ variable "sourcegraph_amp_api_key" {
module "amp-cli" {
count = data.coder_workspace.me.start_count
source = "registry.coder.com/coder-labs/sourcegraph-amp/coder"
version = "1.1.0"
version = "1.0.3"
agent_id = coder_agent.example.id
sourcegraph_amp_api_key = var.sourcegraph_amp_api_key # recommended for authenticated usage
install_sourcegraph_amp = true
@@ -69,7 +69,7 @@ variable "install_agentapi" {
variable "agentapi_version" {
type = string
description = "The version of AgentAPI to install."
default = "v0.10.0"
default = "v0.3.0"
}
variable "pre_install_script" {
@@ -151,7 +151,7 @@ locals {
module "agentapi" {
source = "registry.coder.com/coder/agentapi/coder"
version = "1.2.0"
version = "1.0.1"
agent_id = var.agent_id
web_app_slug = local.app_slug
@@ -22,16 +22,33 @@ provider "docker" {}
module "claude-code" {
count = data.coder_workspace.me.start_count
source = "registry.coder.com/coder/claude-code/coder"
version = "3.0.0"
version = "2.0.0"
agent_id = coder_agent.main.id
workdir = "/home/coder/projects"
agent_name = "main"
folder = "/home/coder/projects"
install_claude_code = true
claude_code_version = "latest"
order = 999
claude_api_key = ""
ai_prompt = data.coder_parameter.ai_prompt.value
system_prompt = data.coder_parameter.system_prompt.value
model = "sonnet"
permission_mode = "plan"
post_install_script = data.coder_parameter.setup_script.value
experiment_post_install_script = data.coder_parameter.setup_script.value
# This enables Coder Tasks
experiment_report_tasks = true
}
# You can also use a model provider, like AWS Bedrock or Vertex by replacing
# this with the special env vars from the Claude Code docs.
# see: https://docs.anthropic.com/en/docs/claude-code/third-party-integrations
variable "anthropic_api_key" {
type = string
description = "Generate one at: https://console.anthropic.com/settings/keys"
sensitive = true
}
resource "coder_env" "anthropic_api_key" {
agent_id = coder_agent.main.id
agent_name = "main"
name = "CODER_MCP_CLAUDE_API_KEY"
value = var.anthropic_api_key
}
# We are using presets to set the prompts, image, and set up instructions
@@ -157,6 +174,26 @@ data "coder_parameter" "preview_port" {
mutable = false
}
# Other variables for Claude Code
resource "coder_env" "claude_task_prompt" {
agent_id = coder_agent.main.id
agent_name = "main"
name = "CODER_MCP_CLAUDE_TASK_PROMPT"
value = data.coder_parameter.ai_prompt.value
}
resource "coder_env" "app_status_slug" {
agent_id = coder_agent.main.id
agent_name = "main"
name = "CODER_MCP_APP_STATUS_SLUG"
value = "ccw"
}
resource "coder_env" "claude_system_prompt" {
agent_id = coder_agent.main.id
agent_name = "main"
name = "CODER_MCP_CLAUDE_SYSTEM_PROMPT"
value = data.coder_parameter.system_prompt.value
}
data "coder_provisioner" "me" {}
data "coder_workspace" "me" {}
data "coder_workspace_owner" "me" {}
@@ -264,27 +301,38 @@ module "code-server" {
# This ensures that the latest non-breaking version of the module gets downloaded, you can also pin the module version to prevent breaking changes in production.
version = "~> 1.0"
agent_id = coder_agent.main.id
order = 1
agent_id = coder_agent.main.id
agent_name = "main"
order = 1
}
module "vscode" {
count = data.coder_workspace.me.start_count
source = "registry.coder.com/coder/vscode-desktop/coder"
version = "1.1.0"
agent_id = coder_agent.main.id
agent_name = "main"
}
module "windsurf" {
count = data.coder_workspace.me.start_count
source = "registry.coder.com/coder/windsurf/coder"
version = "1.1.0"
agent_id = coder_agent.main.id
count = data.coder_workspace.me.start_count
source = "registry.coder.com/coder/windsurf/coder"
version = "1.1.0"
agent_id = coder_agent.main.id
agent_name = "main"
}
module "cursor" {
count = data.coder_workspace.me.start_count
source = "registry.coder.com/coder/cursor/coder"
version = "1.2.0"
agent_id = coder_agent.main.id
count = data.coder_workspace.me.start_count
source = "registry.coder.com/coder/cursor/coder"
version = "1.2.0"
agent_id = coder_agent.main.id
agent_name = "main"
}
module "jetbrains" {
count = data.coder_workspace.me.start_count
source = "registry.coder.com/coder/jetbrains/coder"
source = "registry.coder.com/modules/coder/jetbrains/coder"
version = "~> 1.0"
agent_id = coder_agent.main.id
agent_name = "main"
@@ -320,6 +368,7 @@ resource "docker_volume" "home_volume" {
resource "coder_app" "preview" {
agent_id = coder_agent.main.id
agent_name = "main"
slug = "preview"
display_name = "Preview your app"
icon = "${data.coder_workspace.me.access_url}/emojis/1f50e.png"
Binary file not shown.

Before

Width:  |  Height:  |  Size: 976 KiB

After

Width:  |  Height:  |  Size: 67 KiB

+2 -1
View File
@@ -16,7 +16,7 @@ The AgentAPI module is a building block for modules that need to run an AgentAPI
```tf
module "agentapi" {
source = "registry.coder.com/coder/agentapi/coder"
version = "1.2.0"
version = "1.1.1"
agent_id = var.agent_id
web_app_slug = local.app_slug
@@ -28,6 +28,7 @@ module "agentapi" {
cli_app_display_name = "Goose CLI"
module_dir_name = local.module_dir_name
install_agentapi = var.install_agentapi
enable_tasks = var.enable_tasks # Set to false to disable AI tasks
pre_install_script = var.pre_install_script
post_install_script = var.post_install_script
start_script = local.start_script
+9 -2
View File
@@ -117,7 +117,7 @@ variable "install_agentapi" {
variable "agentapi_version" {
type = string
description = "The version of AgentAPI to install."
default = "v0.10.0"
default = "v0.3.3"
}
variable "agentapi_port" {
@@ -156,6 +156,11 @@ variable "module_dir_name" {
description = "Name of the subdirectory in the home directory for module files."
}
variable "enable_tasks" {
type = bool
description = "Whether to enable AI tasks. When false, the coder_ai_task resource will not be created, avoiding the requirement for an 'AI Prompt' parameter."
default = true
}
locals {
# we always trim the slash for consistency
@@ -240,7 +245,9 @@ resource "coder_app" "agentapi_cli" {
}
resource "coder_ai_task" "agentapi" {
count = var.enable_tasks ? 1 : 0
sidebar_app {
id = coder_app.agentapi_web.id
}
}
}
+64 -340
View File
@@ -1,26 +1,23 @@
---
display_name: Amazon Q
description: Run Amazon Q in your workspace to access Amazon's AI coding assistant with MCP integration and task reporting.
description: Run Amazon Q in your workspace to access Amazon's AI coding assistant.
icon: ../../../../.icons/amazon-q.svg
verified: true
tags: [agent, ai, aws, amazon-q, tasks]
tags: [agent, ai, aws, amazon-q]
---
# Amazon Q
Run [Amazon Q](https://aws.amazon.com/q/) in your workspace to access Amazon's AI coding assistant. This module provides a complete integration with Coder workspaces, including automatic installation, MCP (Model Context Protocol) integration for task reporting, and support for custom pre/post install scripts.
Run [Amazon Q](https://aws.amazon.com/q/) in your workspace to access Amazon's AI coding assistant. This module installs and launches Amazon Q, with support for background operation, task reporting, and custom pre/post install scripts.
```tf
module "amazon-q" {
source = "registry.coder.com/coder/amazon-q/coder"
version = "2.1.1"
version = "1.1.2"
agent_id = coder_agent.example.id
workdir = "/home/coder"
# Required: Authentication tarball (see below for generation)
auth_tarball = <<-EOF
base64encoded-tarball
EOF
# Required: see below for how to generate
experiment_auth_tarball = var.amazon_q_auth_tarball
}
```
@@ -28,370 +25,97 @@ EOF
## Prerequisites
- **zstd** - Required for compressing the authentication tarball
- **Ubuntu/Debian**: `sudo apt-get install zstd`
- **RHEL/CentOS/Fedora**: `sudo yum install zstd` or `sudo dnf install zstd`
- **auth_tarball** - Required for installation and authentication
- You must generate an authenticated Amazon Q tarball on another machine:
```sh
cd ~/.local/share/amazon-q && tar -c . | zstd | base64 -w 0
```
Paste the result into the `experiment_auth_tarball` variable.
- To run in the background, your workspace must have `screen` or `tmux` installed.
### Authentication Tarball
<details>
<summary><strong>How to generate the Amazon Q auth tarball (step-by-step)</strong></summary>
You must generate an authenticated Amazon Q tarball on another machine where you have successfully logged in:
**1. Install and authenticate Amazon Q on your local machine:**
```bash
# 1. Install Amazon Q and login on your local machine
q login
- Download and install Amazon Q from the [official site](https://aws.amazon.com/q/developer/).
- Run `q login` and complete the authentication process in your terminal.
# 2. Generate the authentication tarball
cd ~/.local/share/amazon-q
tar -c . | zstd | base64 -w 0
```
**2. Locate your Amazon Q config directory:**
Copy the output and use it as the `auth_tarball` variable.
- The config is typically stored at `~/.local/share/amazon-q`.
## Detailed Authentication Setup
**3. Generate the tarball:**
**Step 1: Install Amazon Q locally**
- Run the following command in your terminal:
```sh
cd ~/.local/share/amazon-q
tar -c . | zstd | base64 -w 0
```
- Download from [AWS Amazon Q Developer](https://aws.amazon.com/q/developer/)
- Follow the installation instructions for your platform
**4. Copy the output:**
**Step 2: Authenticate**
- The command will output a long string. Copy this entire string.
```bash
q login
```
**5. Paste into your Terraform variable:**
Complete the authentication process in your browser.
- Assign the string to the `experiment_auth_tarball` variable in your Terraform configuration, for example:
```tf
variable "amazon_q_auth_tarball" {
type = string
default = "PASTE_LONG_STRING_HERE"
}
```
**Step 3: Generate tarball**
**Note:**
```bash
cd ~/.local/share/amazon-q
tar -c . | zstd | base64 -w 0 > /tmp/amazon-q-auth.txt
```
- You must re-generate the tarball if you log out or re-authenticate Amazon Q on your local machine.
- This process is required for each user who wants to use Amazon Q in their workspace.
**Step 4: Use in Terraform**
[Reference: Amazon Q documentation](https://docs.aws.amazon.com/amazonq/latest/qdeveloper-ug/generate-docs.html)
```tf
variable "amazon_q_auth_tarball" {
type = string
sensitive = true
default = "PASTE_YOUR_TARBALL_HERE"
}
```
</details>
> [!IMPORTANT]
>
> - Regenerate the tarball if you logout or re-authenticate
> - Each user needs their own authentication tarball
> - Keep the tarball secure as it contains authentication credentials
## Examples
### Coder Tasks Integration
A `coder_parameter` named **'AI Prompt'** is required to enable integration with [Coder Tasks](https://coder.com/docs/ai-coder/tasks).
```tf
data "coder_parameter" "ai_prompt" {
name = "AI Prompt"
display_name = "AI Prompt"
description = "Prompt for the AI task to execute"
type = "string"
mutable = true
default = ""
}
module "amazon-q" {
source = "registry.coder.com/coder/amazon-q/coder"
version = "2.1.1"
agent_id = coder_agent.example.id
workdir = "/home/coder"
auth_tarball = var.amazon_q_auth_tarball
ai_prompt = data.coder_parameter.ai_prompt.value
trust_all_tools = true
# Task reporting configuration
report_tasks = true
# Enable CLI app alongside web app
cli_app = true
web_app_display_name = "Amazon Q"
cli_app_display_name = "Q CLI"
}
```
> [!IMPORTANT]
>
> - The parameter name must be exactly **'AI Prompt'** (case-sensitive)
> - This parameter enables the AI task workflow integration
> - The parameter value is passed to the Amazon Q module via the `ai_prompt` variable
> - Without this parameter, `coder_ai_task` resources will not function properly
>
> **_Security Notice_**
> In order to allow the tasks flow non-interactively all the tools are trusted
> This flag bypasses standard permission checks and allows Amazon Q broader access to your system than normally permitted.
> While this enables more functionality, it also means Amazon Q can potentially execute commands with the same privileges as the user running it.
> Use this module only in trusted environments and be aware of the security implications.
### Default System Prompt
The module includes a simple system prompt that instructs Amazon Q:
```
You are a helpful Coding assistant. Aim to autonomously investigate
and solve issues the user gives you and test your work, whenever possible.
Avoid shortcuts like mocking tests. When you get stuck, you can ask the user
but opt for autonomy.
```
You can customize this behavior by providing your own system prompt via the `system_prompt` variable.
### Default Coder MCP Instructions
The module includes specific instructions for the Coder MCP server integration that are separate from the system prompt:
```
YOU MUST REPORT ALL TASKS TO CODER.
When reporting tasks you MUST follow these EXACT instructions:
- IMMEDIATELY report status after receiving ANY user message
- Be granular If you are investigating with multiple steps report each step to coder.
Task state MUST be one of the following:
- Use "state": "working" when actively processing WITHOUT needing additional user input
- Use "state": "complete" only when finished with a task
- Use "state": "failure" when you need ANY user input lack sufficient details or encounter blockers.
Task summaries MUST:
- Include specifics about what you're doing
- Include clear and actionable steps for the user
- Be less than 160 characters in length
```
You can customize these instructions by providing your own via the `coder_mcp_instructions` variable.
## Default Agent Configuration
The module includes a default agent configuration template that provides a comprehensive setup for Amazon Q integration:
```json
{
"name": "agent",
"description": "This is an default agent config",
"prompt": "${system_prompt}",
"mcpServers": {},
"tools": [
"fs_read",
"fs_write",
"execute_bash",
"use_aws",
"@coder",
"knowledge"
],
"toolAliases": {},
"allowedTools": ["fs_read", "@coder"],
"resources": [
"file://AmazonQ.md",
"file://README.md",
"file://.amazonq/rules/**/*.md"
],
"hooks": {},
"toolsSettings": {},
"useLegacyMcpJson": true
}
```
### Configuration Details:
- **Tools Available:** File operations, bash execution, AWS CLI, Coder MCP integration, and knowledge base access
- **@coder Tool:** Enables Coder MCP integration for task reporting (`coder_report_task` and related tools)
- **Allowed Tools:** By default, only `fs_read` and `@coder` are allowed (can be customized for security)
- **Resources:** Access to documentation and rule files in the workspace
- **MCP Servers:** Empty by default, can be configured via `agent_config` variable
- **System Prompt:** Dynamically populated from the `system_prompt` variable
- **Legacy MCP:** Uses legacy MCP JSON format for compatibility
You can override this configuration by providing your own JSON via the `agent_config` variable.
### Agent Name Configuration
The module automatically extracts the agent name from the `"name"` field in the `agent_config` JSON and uses it for:
- **Configuration File:** Saves the agent config as `~/.aws/amazonq/cli-agents/{agent_name}.json`
- **Default Agent:** Sets the agent as the default using `q settings chat.defaultAgent {agent_name}`
- **MCP Integration:** Associates the Coder MCP server with the specified agent name
If no custom `agent_config` is provided, the default agent name "agent" is used.
## Usage Examples
### Basic Usage
### Run Amazon Q in the background with tmux
```tf
module "amazon-q" {
source = "registry.coder.com/coder/amazon-q/coder"
version = "2.1.1"
agent_id = coder_agent.example.id
workdir = "/home/coder"
auth_tarball = var.amazon_q_auth_tarball
source = "registry.coder.com/coder/amazon-q/coder"
version = "1.1.2"
agent_id = coder_agent.example.id
experiment_auth_tarball = var.amazon_q_auth_tarball
experiment_use_tmux = true
}
```
This example will:
1. Download and install Amazon Q CLI v1.14.1
2. Extract authentication tarball to ~/.local/share/amazon-q
3. Configure Coder MCP integration for task reporting
4. Create default agent configuration file
5. Start Amazon Q in /home/coder directory
6. Provide web interface through AgentAPI
> [!IMPORTANT]
> By default `fs_write` tool is not allowed, which will pause the task execution
> an will wait for the prompt to approve it usage.
> To avoid this, and allow the normal task flow, user has two options:
>
> - Change the parameter `trust_all_tools` value to `true` (default to `false`)
> OR
> - Provide you own agent configuration with the tools of your choice allowed
### With Custom AI Prompt
### Enable task reporting (experimental)
```tf
module "amazon-q" {
source = "registry.coder.com/coder/amazon-q/coder"
version = "2.1.1"
agent_id = coder_agent.example.id
workdir = "/home/coder"
auth_tarball = var.amazon_q_auth_tarball
ai_prompt = "Help me set up a Python FastAPI project with proper testing structure"
trust_all_tools = true
source = "registry.coder.com/coder/amazon-q/coder"
version = "1.1.2"
agent_id = coder_agent.example.id
experiment_auth_tarball = var.amazon_q_auth_tarball
experiment_report_tasks = true
}
```
> [!IMPORTANT]
> **_Security Notice_**
> In order to allow the tasks flow non-interactively all the tools are trusted
> This flag bypasses standard permission checks and allows Amazon Q broader access to your system than normally permitted.
> While this enables more functionality, it also means Amazon Q can potentially execute commands with the same privileges as the user running it.
> Use this module only in trusted environments and be aware of the security implications.
### With Custom Pre/Post Install Scripts
### Run custom scripts before/after install
```tf
module "amazon-q" {
source = "registry.coder.com/coder/amazon-q/coder"
version = "2.1.1"
agent_id = coder_agent.example.id
workdir = "/home/coder"
auth_tarball = var.amazon_q_auth_tarball
pre_install_script = <<-EOT
#!/bin/bash
echo "Setting up custom environment..."
# Install additional dependencies
sudo apt-get update && sudo apt-get install -y zstd
EOT
post_install_script = <<-EOT
#!/bin/bash
echo "Configuring Amazon Q settings..."
# Custom configuration commands
q settings chat.model claude-3-sonnet
EOT
source = "registry.coder.com/coder/amazon-q/coder"
version = "1.1.2"
agent_id = coder_agent.example.id
experiment_auth_tarball = var.amazon_q_auth_tarball
experiment_pre_install_script = "echo Pre-install!"
experiment_post_install_script = "echo Post-install!"
}
```
### Specific Version Installation
## Notes
```tf
module "amazon-q" {
source = "registry.coder.com/coder/amazon-q/coder"
version = "2.1.1"
agent_id = coder_agent.example.id
workdir = "/home/coder"
auth_tarball = var.amazon_q_auth_tarball
amazon_q_version = "1.14.0" # Specific version
install_amazon_q = true
}
```
### Custom Agent Configuration
```tf
module "amazon-q" {
source = "registry.coder.com/coder/amazon-q/coder"
version = "2.1.1"
agent_id = coder_agent.example.id
workdir = "/home/coder"
auth_tarball = var.amazon_q_auth_tarball
agent_config = <<-EOT
{
"name": "custom-agent",
"description": "Custom Amazon Q agent for my workspace",
"prompt": "You are a specialized DevOps assistant...",
"tools": ["fs_read", "fs_write", "execute_bash", "use_aws"]
}
EOT
}
```
### With Custom AgentAPI Configuration
```tf
module "amazon-q" {
source = "registry.coder.com/coder/amazon-q/coder"
version = "2.1.1"
agent_id = coder_agent.example.id
workdir = "/home/coder"
auth_tarball = var.amazon_q_auth_tarball
# AgentAPI configuration for environments without wildcard access url. https://coder.com/docs/admin/setup#wildcard-access-url
agentapi_chat_based_path = true
agentapi_version = "v0.10.0"
}
```
### Air-Gapped Installation
For environments without direct internet access, you can host Amazon Q installation files internally and configure the module to use your internal repository:
```tf
module "amazon-q" {
source = "registry.coder.com/coder/amazon-q/coder"
version = "2.1.1"
agent_id = coder_agent.example.id
workdir = "/home/coder"
auth_tarball = var.amazon_q_auth_tarball
# Point to internal artifact repository
q_install_url = "https://artifacts.internal.corp/amazon-q-releases"
# Use specific version available in your repository
amazon_q_version = "1.14.1"
}
```
**Prerequisites for Air-Gapped Setup:**
1. Download Amazon Q installation files from AWS and host them internally
2. Maintain the same directory structure: `{base_url}/{version}/q-{arch}-linux.zip`
3. Ensure both architectures are available:
- `q-x86_64-linux.zip` for Intel/AMD systems
- `q-aarch64-linux.zip` for ARM systems
4. Configure network access from Coder workspaces to your internal repository
## Troubleshooting
### Common Issues
**Authentication issues:**
- Regenerate the auth tarball on your local machine
- Ensure the tarball is properly base64 encoded
- Check that the original authentication is still valid
**MCP integration not working:**
- Verify that AgentAPI is installed (`install_agentapi = true`)
- Check that the Coder agent is properly configured
- Review the system prompt configuration
- Only one of `experiment_use_screen` or `experiment_use_tmux` can be true at a time.
- If neither is set, Amazon Q runs in the foreground.
- For more details, see the [main.tf](./main.tf) source.
@@ -1,372 +0,0 @@
run "required_variables" {
command = plan
variables {
agent_id = "test-agent-id"
workdir = "/tmp/test-workdir"
}
}
run "minimal_config" {
command = plan
variables {
agent_id = "test-agent-id"
workdir = "/tmp/test-workdir"
auth_tarball = "dGVzdA==" # base64 "test"
}
assert {
condition = resource.coder_env.status_slug.name == "CODER_MCP_APP_STATUS_SLUG"
error_message = "Status slug environment variable not configured correctly"
}
assert {
condition = resource.coder_env.status_slug.value == "amazonq"
error_message = "Status slug value should be 'amazonq'"
}
}
# Test Case 1: Basic Usage No Autonomous Use of Q
# Using vanilla Kubernetes Deployment Template configuration
run "test_case_1_basic_usage" {
command = plan
variables {
agent_id = "test-agent-id"
workdir = "/tmp/test-workdir"
auth_tarball = "dGVzdEF1dGhUYXJiYWxs" # base64 "testAuthTarball"
}
# Q is installed and authenticated
assert {
condition = resource.coder_env.status_slug.name == "CODER_MCP_APP_STATUS_SLUG"
error_message = "Status slug environment variable should be configured for basic usage"
}
assert {
condition = resource.coder_env.status_slug.value == "amazonq"
error_message = "Status slug value should be 'amazonq' for basic usage"
}
# AgentAPI is installed and configured (default behavior)
assert {
condition = length(resource.coder_env.auth_tarball) == 1
error_message = "Auth tarball environment variable should be created for authentication"
}
# Foundational configuration applied
assert {
condition = length(local.agent_config) > 0
error_message = "Agent config should be generated with foundational configuration"
}
# No additional parameters required (using defaults)
assert {
condition = local.agent_name == "agent"
error_message = "Default agent name should be 'agent' when no custom config provided"
}
}
# Test Case 2: Autonomous Usage Autonomous Use of Q
# AI prompt passed through from external source (Tasks interface or Issue Tracker CI)
run "test_case_2_autonomous_usage" {
command = plan
variables {
agent_id = "test-agent-id"
workdir = "/tmp/test-workdir"
auth_tarball = "dGVzdEF1dGhUYXJiYWxs" # base64 "testAuthTarball"
ai_prompt = "Help me set up a Python FastAPI project with proper testing structure"
}
# Q is installed and authenticated
assert {
condition = resource.coder_env.status_slug.name == "CODER_MCP_APP_STATUS_SLUG"
error_message = "Status slug environment variable should be configured for autonomous usage"
}
assert {
condition = resource.coder_env.status_slug.value == "amazonq"
error_message = "Status slug value should be 'amazonq' for autonomous usage"
}
# AgentAPI is installed and configured
assert {
condition = length(resource.coder_env.auth_tarball) == 1
error_message = "Auth tarball environment variable should be created for autonomous usage"
}
# Foundational configuration for all components applied
assert {
condition = length(local.agent_config) > 0
error_message = "Agent config should be generated for autonomous usage"
}
# AI prompt is configured
assert {
condition = local.full_prompt == "Help me set up a Python FastAPI project with proper testing structure"
error_message = "AI prompt should be configured correctly for autonomous usage"
}
# Default agent name when no custom config
assert {
condition = local.agent_name == "agent"
error_message = "Default agent name should be 'agent' for autonomous usage"
}
}
# Test Case 3: Extended Configuration Parameter Validation and File Rendering
# Validates extended configuration options and parameter application
run "test_case_3_extended_configuration" {
command = plan
variables {
agent_id = "test-agent-id"
workdir = "/tmp/test-workdir"
auth_tarball = "dGVzdEF1dGhUYXJiYWxs" # base64 "testAuthTarball"
amazon_q_version = "1.14.1"
q_install_url = "https://desktop-release.q.us-east-1.amazonaws.com"
install_amazon_q = true
install_agentapi = true
agentapi_version = "v0.6.0"
trust_all_tools = true
ai_prompt = "Help me create a production-grade TypeScript monorepo with testing and deployment"
system_prompt = "You are a helpful software assistant working in a secure enterprise environment"
pre_install_script = "echo 'Pre-install setup'"
post_install_script = "echo 'Post-install cleanup'"
agent_config = jsonencode({
name = "production-agent"
description = "Production Amazon Q agent for enterprise environment"
prompt = "You are a helpful software assistant working in a secure enterprise environment"
mcpServers = {}
tools = ["fs_read", "fs_write", "execute_bash", "use_aws", "knowledge"]
toolAliases = {}
allowedTools = ["fs_read"]
resources = ["file://AmazonQ.md", "file://README.md", "file://.amazonq/rules/**/*.md"]
hooks = {}
toolsSettings = {}
useLegacyMcpJson = true
})
}
# All installation parameters are applied correctly
assert {
condition = resource.coder_env.status_slug.value == "amazonq"
error_message = "Status slug should be configured correctly with extended parameters"
}
assert {
condition = resource.coder_env.auth_tarball[0].value == "dGVzdEF1dGhUYXJiYWxs"
error_message = "Auth tarball should be configured correctly with extended parameters"
}
# Custom agent configuration is loaded and referenced correctly
assert {
condition = local.agent_name == "production-agent"
error_message = "Agent name should be extracted from custom agent config"
}
assert {
condition = length(local.agent_config) > 0
error_message = "Custom agent config should be processed correctly"
}
# AI prompt and system prompt are configured
assert {
condition = local.full_prompt == "Help me create a production-grade TypeScript monorepo with testing and deployment"
error_message = "AI prompt should be configured correctly in extended configuration"
}
# Pre-install and post-install scripts are provided
assert {
condition = length(local.agent_config) > 0
error_message = "Agent config should be generated correctly for extended configuration"
}
}
run "full_config" {
command = plan
variables {
agent_id = "test-agent-id"
workdir = "/tmp/test-workdir"
install_amazon_q = true
install_agentapi = true
agentapi_version = "v0.5.0"
amazon_q_version = "latest"
trust_all_tools = true
ai_prompt = "Build a web application"
auth_tarball = "dGVzdA=="
order = 1
group = "AI Tools"
icon = "/icon/custom-amazon-q.svg"
pre_install_script = "echo 'pre-install'"
post_install_script = "echo 'post-install'"
agent_config = jsonencode({
name = "test-agent"
description = "Test agent configuration"
prompt = "You are a helpful AI assistant for testing."
mcpServers = {}
tools = ["fs_read", "fs_write", "execute_bash", "use_aws", "knowledge"]
toolAliases = {}
allowedTools = ["fs_read"]
resources = ["file://AmazonQ.md", "file://README.md", "file://.amazonq/rules/**/*.md"]
hooks = {}
toolsSettings = {}
useLegacyMcpJson = true
})
}
assert {
condition = resource.coder_env.status_slug.name == "CODER_MCP_APP_STATUS_SLUG"
error_message = "Status slug environment variable not configured correctly"
}
assert {
condition = resource.coder_env.status_slug.value == "amazonq"
error_message = "Status slug value should be 'amazonq'"
}
assert {
condition = length(resource.coder_env.auth_tarball) == 1
error_message = "Auth tarball environment variable should be created when provided"
}
}
run "auth_tarball_environment" {
command = plan
variables {
agent_id = "test-agent-id"
workdir = "/tmp/test-workdir"
auth_tarball = "dGVzdEF1dGhUYXJiYWxs" # base64 "testAuthTarball"
}
assert {
condition = resource.coder_env.auth_tarball[0].name == "AMAZON_Q_AUTH_TARBALL"
error_message = "Auth tarball environment variable name should be 'AMAZON_Q_AUTH_TARBALL'"
}
assert {
condition = resource.coder_env.auth_tarball[0].value == "dGVzdEF1dGhUYXJiYWxs"
error_message = "Auth tarball environment variable value should match input"
}
}
run "empty_auth_tarball" {
command = plan
variables {
agent_id = "test-agent-id"
workdir = "/tmp/test-workdir"
auth_tarball = ""
}
assert {
condition = length(resource.coder_env.auth_tarball) == 0
error_message = "Auth tarball environment variable should not be created when empty"
}
}
run "custom_system_prompt" {
command = plan
variables {
agent_id = "test-agent-id"
workdir = "/tmp/test-workdir"
system_prompt = "Custom system prompt for testing"
}
# Test that the system prompt is used in the agent config template
assert {
condition = length(local.agent_config) > 0
error_message = "Agent config should be generated with custom system prompt"
}
}
run "install_options" {
command = plan
variables {
agent_id = "test-agent-id"
workdir = "/tmp/test-workdir"
install_amazon_q = false
install_agentapi = false
}
assert {
condition = resource.coder_env.status_slug.name == "CODER_MCP_APP_STATUS_SLUG"
error_message = "Status slug should still be configured even when install options are disabled"
}
}
run "version_configuration" {
command = plan
variables {
agent_id = "test-agent-id"
workdir = "/tmp/test-workdir"
amazon_q_version = "2.15.0"
agentapi_version = "v0.4.0"
}
assert {
condition = resource.coder_env.status_slug.value == "amazonq"
error_message = "Status slug value should remain 'amazonq' regardless of version"
}
}
# Additional test for agent name extraction
run "agent_name_extraction" {
command = plan
variables {
agent_id = "test-agent-id"
workdir = "/tmp/test-workdir"
agent_config = jsonencode({
name = "custom-enterprise-agent"
description = "Custom enterprise agent configuration"
prompt = "You are a custom enterprise AI assistant."
mcpServers = {}
tools = ["fs_read", "fs_write", "execute_bash", "use_aws", "knowledge"]
toolAliases = {}
allowedTools = ["fs_read", "fs_write"]
resources = ["file://README.md"]
hooks = {}
toolsSettings = {}
useLegacyMcpJson = true
})
}
assert {
condition = local.agent_name == "custom-enterprise-agent"
error_message = "Agent name should be extracted correctly from custom agent config"
}
assert {
condition = length(local.agent_config) > 0
error_message = "Agent config should be processed correctly"
}
}
# Test for JSON encoding validation
run "json_encoding_validation" {
command = plan
variables {
agent_id = "test-agent-id"
workdir = "/tmp/test-workdir"
system_prompt = "Multi-line\nsystem prompt\nwith newlines"
}
assert {
condition = length(local.system_prompt) > 0
error_message = "System prompt should be JSON encoded correctly"
}
assert {
condition = length(local.agent_config) > 0
error_message = "Agent config should be generated correctly with multi-line system prompt"
}
}
+17 -507
View File
@@ -2,530 +2,40 @@ import { describe, it, expect } from "bun:test";
import {
runTerraformApply,
runTerraformInit,
testRequiredVariables,
findResourceInstance,
} from "~test";
import path from "path";
const moduleDir = path.resolve(__dirname);
// Always provide agent_config to bypass template parsing issues
const baseAgentConfig = JSON.stringify({
name: "test-agent",
description: "Test agent configuration",
prompt: "You are a helpful AI assistant.",
mcpServers: {},
tools: ["fs_read", "fs_write", "execute_bash", "use_aws", "knowledge"],
toolAliases: {},
allowedTools: ["fs_read"],
resources: ["file://README.md", "file://.amazonq/rules/**/*.md"],
hooks: {},
toolsSettings: {},
useLegacyMcpJson: true,
});
const requiredVars = {
agent_id: "dummy-agent-id",
agent_config: baseAgentConfig,
workdir: "/tmp/test-workdir",
};
const fullConfigVars = {
agent_id: "dummy-agent-id",
workdir: "/tmp/test-workdir",
install_amazon_q: true,
install_agentapi: true,
agentapi_version: "v0.6.0",
amazon_q_version: "1.14.1",
q_install_url: "https://desktop-release.q.us-east-1.amazonaws.com",
trust_all_tools: false,
ai_prompt: "Build a comprehensive test suite",
auth_tarball: "dGVzdEF1dGhUYXJiYWxs", // base64 "testAuthTarball"
order: 1,
group: "AI Tools",
icon: "/icon/custom-amazon-q.svg",
pre_install_script: "echo 'Starting pre-install'",
post_install_script: "echo 'Completed post-install'",
agent_config: baseAgentConfig,
};
describe("amazon-q module v2.0.0", async () => {
describe("amazon-q module", async () => {
await runTerraformInit(moduleDir);
// Test Case 1: Basic Usage No Autonomous Use of Q
// Matches CDES-203 Test Case #1: Basic Usage
it("Test Case 1: Basic Usage - No Autonomous Use of Q", async () => {
const basicUsageVars = {
agent_id: "dummy-agent-id",
workdir: "/tmp/test-workdir",
auth_tarball: "dGVzdEF1dGhUYXJiYWxs", // base64 "testAuthTarball"
};
// 1. Required variables
testRequiredVariables(moduleDir, requiredVars);
const state = await runTerraformApply(moduleDir, basicUsageVars);
// Q is installed and authenticated
const statusSlugEnv = findResourceInstance(
state,
"coder_env",
"status_slug",
);
expect(statusSlugEnv).toBeDefined();
expect(statusSlugEnv.name).toBe("CODER_MCP_APP_STATUS_SLUG");
expect(statusSlugEnv.value).toBe("amazonq");
// AgentAPI is installed and configured (default behavior)
const authTarballEnv = findResourceInstance(
state,
"coder_env",
"auth_tarball",
);
expect(authTarballEnv).toBeDefined();
expect(authTarballEnv.name).toBe("AMAZON_Q_AUTH_TARBALL");
expect(authTarballEnv.value).toBe("dGVzdEF1dGhUYXJiYWxs");
// Foundational configuration for all components is applied
// No additional parameters are required for the module to work
// Using the terminal application and Q chat returns a functional interface
});
// Test Case 2: Autonomous Usage Autonomous Use of Q
// Matches CDES-203 Test Case 2: Autonomous Usage
it("Test Case 2: Autonomous Usage - Autonomous Use of Q", async () => {
const autonomousUsageVars = {
agent_id: "dummy-agent-id",
workdir: "/tmp/test-workdir",
auth_tarball: "dGVzdEF1dGhUYXJiYWxs", // base64 "testAuthTarball"
ai_prompt:
"Help me set up a Python FastAPI project with proper testing structure",
};
const state = await runTerraformApply(moduleDir, autonomousUsageVars);
// Q is installed and authenticated
const statusSlugEnv = findResourceInstance(
state,
"coder_env",
"status_slug",
);
expect(statusSlugEnv).toBeDefined();
expect(statusSlugEnv.name).toBe("CODER_MCP_APP_STATUS_SLUG");
expect(statusSlugEnv.value).toBe("amazonq");
// AgentAPI is installed and configured
const authTarballEnv = findResourceInstance(
state,
"coder_env",
"auth_tarball",
);
expect(authTarballEnv).toBeDefined();
expect(authTarballEnv.name).toBe("AMAZON_Q_AUTH_TARBALL");
// AI prompt is passed through from external source
// The Chat interface functions as required
// The Tasks interface functions as required
// The template can be invoked from GitHub integration as expected
});
// Test Case 3: Extended Configuration Parameter Validation and File Rendering
// Matches CDES-203 Test Case 3: Extended Configuration
it("Test Case 3: Extended Configuration - Parameter Validation and File Rendering", async () => {
const extendedConfigVars = {
agent_id: "dummy-agent-id",
workdir: "/tmp/test-workdir",
auth_tarball: "dGVzdEF1dGhUYXJiYWxs", // base64 "testAuthTarball"
amazon_q_version: "1.14.1",
q_install_url: "https://desktop-release.q.us-east-1.amazonaws.com",
install_amazon_q: true,
install_agentapi: true,
agentapi_version: "v0.6.0",
trust_all_tools: true,
ai_prompt:
"Help me create a production-grade TypeScript monorepo with testing and deployment",
system_prompt:
"You are a helpful software assistant working in a secure enterprise environment",
pre_install_script: "echo 'Pre-install setup'",
post_install_script: "echo 'Post-install cleanup'",
agent_config: JSON.stringify({
name: "production-agent",
description: "Production Amazon Q agent for enterprise environment",
prompt:
"You are a helpful software assistant working in a secure enterprise environment",
mcpServers: {},
tools: ["fs_read", "fs_write", "execute_bash", "use_aws", "knowledge"],
toolAliases: {},
allowedTools: ["fs_read"],
resources: [
"file://AmazonQ.md",
"file://README.md",
"file://.amazonq/rules/**/*.md",
],
hooks: {},
toolsSettings: {},
useLegacyMcpJson: true,
}),
};
const state = await runTerraformApply(moduleDir, extendedConfigVars);
// All installation steps execute in the correct order
const statusSlugEnv = findResourceInstance(
state,
"coder_env",
"status_slug",
);
expect(statusSlugEnv).toBeDefined();
expect(statusSlugEnv.name).toBe("CODER_MCP_APP_STATUS_SLUG");
expect(statusSlugEnv.value).toBe("amazonq");
// auth_tarball is unpacked and used as expected
const authTarballEnv = findResourceInstance(
state,
"coder_env",
"auth_tarball",
);
expect(authTarballEnv).toBeDefined();
expect(authTarballEnv.value).toBe("dGVzdEF1dGhUYXJiYWxs");
// agent_config is rendered correctly, and the name field is used as the agent's name
// The specified ai_prompt and system_prompt are respected by the Q agent
// Tools are trusted globally if trust_all_tools = true
// Files and scripts execute in proper sequence
});
// 1. Basic functionality test (replaces testRequiredVariables)
it("works with required variables", async () => {
// 2. coder_script resource is created
it("creates coder_script resource", async () => {
const state = await runTerraformApply(moduleDir, requiredVars);
// Should create the basic resources
const statusSlugEnv = findResourceInstance(
state,
"coder_env",
"status_slug",
);
expect(statusSlugEnv).toBeDefined();
expect(statusSlugEnv.name).toBe("CODER_MCP_APP_STATUS_SLUG");
expect(statusSlugEnv.value).toBe("amazonq");
const scriptResource = findResourceInstance(state, "coder_script");
expect(scriptResource).toBeDefined();
expect(scriptResource.agent_id).toBe(requiredVars.agent_id);
// Optionally, check that the script contains expected lines
expect(scriptResource.script).toContain("Installing Amazon Q");
});
// 2. Environment variables are created correctly
it("creates required environment variables", async () => {
const state = await runTerraformApply(moduleDir, fullConfigVars);
// Check status slug environment variable
const statusSlugEnv = findResourceInstance(
state,
"coder_env",
"status_slug",
);
expect(statusSlugEnv).toBeDefined();
expect(statusSlugEnv.name).toBe("CODER_MCP_APP_STATUS_SLUG");
expect(statusSlugEnv.value).toBe("amazonq");
// Check auth tarball environment variable
const authTarballEnv = findResourceInstance(
state,
"coder_env",
"auth_tarball",
);
expect(authTarballEnv).toBeDefined();
expect(authTarballEnv.name).toBe("AMAZON_Q_AUTH_TARBALL");
expect(authTarballEnv.value).toBe("dGVzdEF1dGhUYXJiYWxs");
});
// 3. Empty auth tarball handling
it("handles empty auth tarball correctly", async () => {
const noAuthVars = {
...requiredVars,
auth_tarball: "",
};
const state = await runTerraformApply(moduleDir, noAuthVars);
// Auth tarball environment variable should not be created when empty
const authTarballEnv = state.resources?.find(
(r) => r.type === "coder_env" && r.name === "auth_tarball",
);
expect(authTarballEnv).toBeUndefined();
});
// 4. Status slug is always created
it("creates status slug environment variable", async () => {
// 3. coder_app resource is created
it("creates coder_app resource", async () => {
const state = await runTerraformApply(moduleDir, requiredVars);
// Status slug should always be configured
const statusSlugEnv = findResourceInstance(
state,
"coder_env",
"status_slug",
);
expect(statusSlugEnv).toBeDefined();
expect(statusSlugEnv.name).toBe("CODER_MCP_APP_STATUS_SLUG");
expect(statusSlugEnv.value).toBe("amazonq");
const appResource = findResourceInstance(state, "coder_app", "amazon_q");
expect(appResource).toBeDefined();
expect(appResource.agent_id).toBe(requiredVars.agent_id);
});
// 5. Install options configuration
it("respects install option flags", async () => {
const noInstallVars = {
...requiredVars,
install_amazon_q: false,
install_agentapi: false,
};
const state = await runTerraformApply(moduleDir, noInstallVars);
// Status slug should still be configured even when install options are disabled
const statusSlugEnv = findResourceInstance(
state,
"coder_env",
"status_slug",
);
expect(statusSlugEnv).toBeDefined();
expect(statusSlugEnv.value).toBe("amazonq");
});
// 6. Configurable installation URL
it("uses configurable q_install_url parameter", async () => {
const customUrlVars = {
...requiredVars,
q_install_url: "https://internal-mirror.company.com/amazon-q",
};
const state = await runTerraformApply(moduleDir, customUrlVars);
// Should create the basic resources
const statusSlugEnv = findResourceInstance(
state,
"coder_env",
"status_slug",
);
expect(statusSlugEnv).toBeDefined();
});
// 7. Version configuration
it("uses specified versions", async () => {
const versionVars = {
...requiredVars,
amazon_q_version: "1.14.1",
agentapi_version: "v0.6.0",
};
const state = await runTerraformApply(moduleDir, versionVars);
// Should create the basic resources
const statusSlugEnv = findResourceInstance(
state,
"coder_env",
"status_slug",
);
expect(statusSlugEnv).toBeDefined();
});
// 8. UI configuration options
it("supports UI customization options", async () => {
const uiCustomVars = {
...requiredVars,
order: 5,
group: "Custom AI Tools",
icon: "/icon/custom-amazon-q-icon.svg",
};
const state = await runTerraformApply(moduleDir, uiCustomVars);
// Should create the basic resources
const statusSlugEnv = findResourceInstance(
state,
"coder_env",
"status_slug",
);
expect(statusSlugEnv).toBeDefined();
});
// 9. Pre and post install scripts
it("supports pre and post install scripts", async () => {
const scriptVars = {
...requiredVars,
pre_install_script: "echo 'Pre-install setup'",
post_install_script: "echo 'Post-install cleanup'",
};
const state = await runTerraformApply(moduleDir, scriptVars);
// Should create the basic resources
const statusSlugEnv = findResourceInstance(
state,
"coder_env",
"status_slug",
);
expect(statusSlugEnv).toBeDefined();
});
// 10. Valid agent_config JSON with different agent name
it("handles valid agent_config JSON with custom agent name", async () => {
const customAgentConfig = JSON.stringify({
name: "production-agent",
description: "Production Amazon Q agent",
prompt: "You are a production AI assistant.",
mcpServers: {},
tools: ["fs_read", "fs_write"],
toolAliases: {},
allowedTools: ["fs_read"],
resources: ["file://README.md"],
hooks: {},
toolsSettings: {},
useLegacyMcpJson: true,
});
const validAgentConfigVars = {
...requiredVars,
agent_config: customAgentConfig,
};
const state = await runTerraformApply(moduleDir, validAgentConfigVars);
// Should create the basic resources
const statusSlugEnv = findResourceInstance(
state,
"coder_env",
"status_slug",
);
expect(statusSlugEnv).toBeDefined();
});
// 11. Air-gapped installation support
it("supports air-gapped installation with custom URL", async () => {
const airGappedVars = {
...requiredVars,
q_install_url: "https://artifacts.internal.corp/amazon-q-releases",
amazon_q_version: "1.14.1",
};
const state = await runTerraformApply(moduleDir, airGappedVars);
// Should create the basic resources
const statusSlugEnv = findResourceInstance(
state,
"coder_env",
"status_slug",
);
expect(statusSlugEnv).toBeDefined();
});
// 12. Trust all tools configuration
it("handles trust_all_tools configuration", async () => {
const trustVars = {
...requiredVars,
trust_all_tools: true,
};
const state = await runTerraformApply(moduleDir, trustVars);
// Should create the basic resources
const statusSlugEnv = findResourceInstance(
state,
"coder_env",
"status_slug",
);
expect(statusSlugEnv).toBeDefined();
});
// 13. AI prompt configuration
it("handles AI prompt configuration", async () => {
const promptVars = {
...requiredVars,
ai_prompt: "Create a comprehensive test suite for the application",
};
const state = await runTerraformApply(moduleDir, promptVars);
// Should create the basic resources
const statusSlugEnv = findResourceInstance(
state,
"coder_env",
"status_slug",
);
expect(statusSlugEnv).toBeDefined();
});
// 14. Agent config with minimal structure
it("handles minimal agent config structure", async () => {
const minimalAgentConfig = JSON.stringify({
name: "minimal-agent",
description: "Minimal agent config",
prompt: "You are a minimal AI assistant.",
mcpServers: {},
tools: ["fs_read", "fs_write", "execute_bash", "use_aws", "knowledge"],
toolAliases: {},
allowedTools: ["fs_read"],
resources: ["file://README.md"],
hooks: {},
toolsSettings: {},
useLegacyMcpJson: true,
});
const minimalVars = {
...requiredVars,
agent_config: minimalAgentConfig,
};
const state = await runTerraformApply(moduleDir, minimalVars);
// Should create the basic resources
const statusSlugEnv = findResourceInstance(
state,
"coder_env",
"status_slug",
);
expect(statusSlugEnv).toBeDefined();
});
// 15. JSON encoding validation for system prompts with newlines
it("handles system prompts with newlines correctly", async () => {
const multilinePromptVars = {
...requiredVars,
system_prompt: "Multi-line\nsystem prompt\nwith newlines",
};
const state = await runTerraformApply(moduleDir, multilinePromptVars);
// Should create the basic resources without JSON parsing errors
const statusSlugEnv = findResourceInstance(
state,
"coder_env",
"status_slug",
);
expect(statusSlugEnv).toBeDefined();
expect(statusSlugEnv.value).toBe("amazonq");
});
// 16. Agent name extraction from custom config
it("extracts agent name from custom configuration correctly", async () => {
const customNameConfig = JSON.stringify({
name: "enterprise-production-agent",
description: "Enterprise production agent configuration",
prompt: "You are an enterprise production AI assistant.",
mcpServers: {},
tools: ["fs_read", "fs_write", "execute_bash", "use_aws", "knowledge"],
toolAliases: {},
allowedTools: ["fs_read", "fs_write", "execute_bash"],
resources: ["file://README.md", "file://.amazonq/rules/**/*.md"],
hooks: {},
toolsSettings: {},
useLegacyMcpJson: true,
});
const customNameVars = {
...requiredVars,
agent_config: customNameConfig,
};
const state = await runTerraformApply(moduleDir, customNameVars);
// Should create the basic resources
const statusSlugEnv = findResourceInstance(
state,
"coder_env",
"status_slug",
);
expect(statusSlugEnv).toBeDefined();
expect(statusSlugEnv.value).toBe("amazonq");
});
// Add more state-based tests as needed
});
+232 -183
View File
@@ -1,12 +1,10 @@
# Improved amazon-q module main.tf
terraform {
required_version = ">= 1.0"
required_providers {
coder = {
source = "coder/coder"
version = ">= 2.7"
version = ">= 2.5"
}
}
}
@@ -17,6 +15,7 @@ variable "agent_id" {
}
data "coder_workspace" "me" {}
data "coder_workspace_owner" "me" {}
variable "order" {
@@ -37,63 +36,10 @@ variable "icon" {
default = "/icon/amazon-q.svg"
}
variable "report_tasks" {
type = bool
description = "Whether to enable task reporting to Coder UI via AgentAPI"
default = true
}
variable "cli_app" {
type = bool
description = "Whether to create a CLI app for Amazon Q"
default = false
}
variable "web_app_display_name" {
type = string
description = "Display name for the web app"
default = "AmazonQ"
}
variable "cli_app_display_name" {
type = string
description = "Display name for the CLI app"
default = "AmazonQ CLI"
}
variable "install_agentapi" {
type = bool
description = "Whether to install AgentAPI."
default = true
}
variable "ai_prompt" {
type = string
description = "The initial task prompt to send to Amazon Q."
default = ""
}
variable "pre_install_script" {
type = string
description = "Optional script to run before installing Amazon Q."
default = null
}
variable "post_install_script" {
type = string
description = "Optional script to run after installing Amazon Q."
default = null
}
variable "agentapi_version" {
type = string
description = "The version of AgentAPI to install."
default = "v0.10.0"
}
variable "workdir" {
variable "folder" {
type = string
description = "The folder to run Amazon Q in."
default = "/home/coder"
}
variable "install_amazon_q" {
@@ -105,21 +51,45 @@ variable "install_amazon_q" {
variable "amazon_q_version" {
type = string
description = "The version of Amazon Q to install."
default = "1.14.1"
default = "latest"
}
variable "q_install_url" {
type = string
description = "Base URL for Amazon Q installation downloads."
default = "https://desktop-release.q.us-east-1.amazonaws.com"
}
variable "trust_all_tools" {
variable "experiment_use_screen" {
type = bool
description = "Whether to trust all tools in Amazon Q."
description = "Whether to use screen for running Amazon Q in the background."
default = false
}
variable "experiment_use_tmux" {
type = bool
description = "Whether to use tmux instead of screen for running Amazon Q in the background."
default = false
}
variable "experiment_report_tasks" {
type = bool
description = "Whether to enable task reporting."
default = false
}
variable "experiment_pre_install_script" {
type = string
description = "Custom script to run before installing Amazon Q."
default = null
}
variable "experiment_post_install_script" {
type = string
description = "Custom script to run after installing Amazon Q."
default = null
}
variable "experiment_auth_tarball" {
type = string
description = "Base64 encoded, zstd compressed tarball of a pre-authenticated ~/.local/share/amazon-q directory. After running `q login` on another machine, you may generate it with: `cd ~/.local/share/amazon-q && tar -c . | zstd | base64 -w 0`"
default = "tarball"
}
variable "system_prompt" {
type = string
description = "The system prompt to use for Amazon Q. This should instruct the agent how to do task reporting."
@@ -128,143 +98,222 @@ variable "system_prompt" {
and solve issues the user gives you and test your work, whenever possible.
Avoid shortcuts like mocking tests. When you get stuck, you can ask the user
but opt for autonomy.
EOT
}
variable "coder_mcp_instructions" {
type = string
description = "Instructions for the Coder MCP server integration. This defines how the agent should report tasks to Coder."
default = <<-EOT
YOU MUST REPORT ALL TASKS TO CODER.
When reporting tasks you MUST follow these EXACT instructions:
- IMMEDIATELY report status after receiving ANY user message
- Be granular If you are investigating with multiple steps report each step to coder.
When reporting tasks, you MUST follow these EXACT instructions:
- IMMEDIATELY report status after receiving ANY user message.
- Be granular. If you are investigating with multiple steps, report each step to coder.
Task state MUST be one of the following:
- Use "state": "working" when actively processing WITHOUT needing additional user input
- Use "state": "complete" only when finished with a task
- Use "state": "failure" when you need ANY user input lack sufficient details or encounter blockers.
- Use "state": "working" when actively processing WITHOUT needing additional user input.
- Use "state": "complete" only when finished with a task.
- Use "state": "failure" when you need ANY user input, lack sufficient details, or encounter blockers.
Task summaries MUST:
- Include specifics about what you're doing
- Include clear and actionable steps for the user
- Be less than 160 characters in length
- Include specifics about what you're doing.
- Include clear and actionable steps for the user.
- Be less than 160 characters in length.
EOT
}
variable "auth_tarball" {
variable "ai_prompt" {
type = string
description = "Base64 encoded, zstd compressed tarball of a pre-authenticated ~/.local/share/amazon-q directory."
default = ""
sensitive = true
}
variable "agent_config" {
type = string
description = "Optional Agent configuration JSON for Amazon Q."
default = null
}
variable "agentapi_chat_based_path" {
type = bool
description = "Whether to use chat-based path for AgentAPI.Required if CODER_WILDCARD_ACCESS_URL is not defined in coder deployment"
default = false
}
# Expose status slug to the agent environment
resource "coder_env" "status_slug" {
agent_id = var.agent_id
name = "CODER_MCP_APP_STATUS_SLUG"
value = local.app_slug
}
# Expose auth tarball as environment variable for install script
resource "coder_env" "auth_tarball" {
count = var.auth_tarball != "" ? 1 : 0
agent_id = var.agent_id
name = "AMAZON_Q_AUTH_TARBALL"
value = var.auth_tarball
description = "The initial task prompt to send to Amazon Q."
default = "Please help me with my coding tasks. I'll provide specific instructions as needed."
}
locals {
app_slug = "amazonq"
workdir = trimsuffix(var.workdir, "/")
install_script = file("${path.module}/scripts/install.sh")
start_script = file("${path.module}/scripts/start.sh")
module_dir_name = ".amazonq-module"
system_prompt = jsonencode(replace(var.system_prompt, "/[\r\n]/", ""))
coder_mcp_instructions = jsonencode(replace(var.coder_mcp_instructions, "/[\r\n]/", ""))
encoded_pre_install_script = var.experiment_pre_install_script != null ? base64encode(var.experiment_pre_install_script) : ""
encoded_post_install_script = var.experiment_post_install_script != null ? base64encode(var.experiment_post_install_script) : ""
full_prompt = <<-EOT
${var.system_prompt}
# Create default agent config structure
default_agent_config = templatefile("${path.module}/templates/agent-config.json.tpl", {
system_prompt = local.system_prompt
})
Your first task is:
# Choose the JSON string: use var.agent_config if provided, otherwise encode default
agent_config = var.agent_config != null ? var.agent_config : local.default_agent_config
# Extract agent name from the selected config
agent_name = try(jsondecode(local.agent_config).name, "agent")
full_prompt = var.ai_prompt != null ? "${var.ai_prompt}" : ""
server_chat_parameters = var.agentapi_chat_based_path ? "--chat-base-path /@${data.coder_workspace_owner.me.name}/${data.coder_workspace.me.name}.${var.agent_id}/apps/${local.app_slug}/chat" : ""
${var.ai_prompt}
EOT
}
module "agentapi" {
source = "registry.coder.com/coder/agentapi/coder"
version = "1.2.0"
agent_id = var.agent_id
folder = local.workdir
web_app_slug = local.app_slug
web_app_order = var.order
web_app_group = var.group
web_app_icon = var.icon
web_app_display_name = var.web_app_display_name
cli_app = var.cli_app
cli_app_slug = var.cli_app ? "${local.app_slug}-cli" : null
cli_app_display_name = var.cli_app ? var.cli_app_display_name : null
module_dir_name = local.module_dir_name
install_agentapi = var.install_agentapi
agentapi_version = var.agentapi_version
pre_install_script = var.pre_install_script
post_install_script = var.post_install_script
start_script = <<-EOT
resource "coder_script" "amazon_q" {
agent_id = var.agent_id
display_name = "Amazon Q"
icon = var.icon
script = <<-EOT
#!/bin/bash
set -o errexit
set -o pipefail
echo -n '${base64encode(local.start_script)}' | base64 -d > /tmp/start.sh
chmod +x /tmp/start.sh
ARG_TRUST_ALL_TOOLS='${var.trust_all_tools}' \
ARG_AI_PROMPT='${base64encode(local.full_prompt)}' \
ARG_MODULE_DIR_NAME='${local.module_dir_name}' \
ARG_WORKDIR='${var.workdir}' \
ARG_SERVER_PARAMETERS="${local.server_chat_parameters}" \
ARG_REPORT_TASKS='${var.report_tasks}' \
/tmp/start.sh
EOT
command_exists() {
command -v "$1" >/dev/null 2>&1
}
install_script = <<-EOT
#!/bin/bash
set -o errexit
set -o pipefail
if [ -n "${local.encoded_pre_install_script}" ]; then
echo "Running pre-install script..."
echo "${local.encoded_pre_install_script}" | base64 -d > /tmp/pre_install.sh
chmod +x /tmp/pre_install.sh
/tmp/pre_install.sh
fi
echo -n '${base64encode(local.install_script)}' | base64 -d > /tmp/install.sh
chmod +x /tmp/install.sh
ARG_INSTALL='${var.install_amazon_q}' \
ARG_VERSION='${var.amazon_q_version}' \
ARG_Q_INSTALL_URL='${var.q_install_url}' \
ARG_AUTH_TARBALL='${var.auth_tarball}' \
ARG_AGENT_CONFIG='${local.agent_config != null ? base64encode(local.agent_config) : ""}' \
ARG_AGENT_NAME='${local.agent_name}' \
ARG_MODULE_DIR_NAME='${local.module_dir_name}' \
ARG_CODER_MCP_APP_STATUS_SLUG='${local.app_slug}' \
ARG_CODER_MCP_INSTRUCTIONS='${base64encode(local.coder_mcp_instructions)}' \
ARG_REPORT_TASKS='${var.report_tasks}' \
/tmp/install.sh
EOT
if [ "${var.install_amazon_q}" = "true" ]; then
echo "Installing Amazon Q..."
PREV_DIR="$PWD"
TMP_DIR="$(mktemp -d)"
cd "$TMP_DIR"
ARCH="$(uname -m)"
case "$ARCH" in
"x86_64")
Q_URL="https://desktop-release.q.us-east-1.amazonaws.com/${var.amazon_q_version}/q-x86_64-linux.zip"
;;
"aarch64"|"arm64")
Q_URL="https://desktop-release.codewhisperer.us-east-1.amazonaws.com/${var.amazon_q_version}/q-aarch64-linux.zip"
;;
*)
echo "Error: Unsupported architecture: $ARCH. Amazon Q only supports x86_64 and arm64."
exit 1
;;
esac
echo "Downloading Amazon Q for $ARCH..."
curl --proto '=https' --tlsv1.2 -sSf "$Q_URL" -o "q.zip"
unzip q.zip
./q/install.sh --no-confirm
cd "$PREV_DIR"
export PATH="$PATH:$HOME/.local/bin"
echo "Installed Amazon Q version: $(q --version)"
fi
echo "Extracting auth tarball..."
PREV_DIR="$PWD"
echo "${var.experiment_auth_tarball}" | base64 -d > /tmp/auth.tar.zst
rm -rf ~/.local/share/amazon-q
mkdir -p ~/.local/share/amazon-q
cd ~/.local/share/amazon-q
tar -I zstd -xf /tmp/auth.tar.zst
rm /tmp/auth.tar.zst
cd "$PREV_DIR"
echo "Extracted auth tarball"
if [ "${var.experiment_report_tasks}" = "true" ]; then
echo "Configuring Amazon Q to report tasks via Coder MCP..."
q mcp add --name coder --command "coder" --args "exp,mcp,server,--allowed-tools,coder_report_task" --env "CODER_MCP_APP_STATUS_SLUG=amazon-q" --scope global --force
echo "Added Coder MCP server to Amazon Q configuration"
fi
if [ -n "${local.encoded_post_install_script}" ]; then
echo "Running post-install script..."
echo "${local.encoded_post_install_script}" | base64 -d > /tmp/post_install.sh
chmod +x /tmp/post_install.sh
/tmp/post_install.sh
fi
if [ "${var.experiment_use_tmux}" = "true" ] && [ "${var.experiment_use_screen}" = "true" ]; then
echo "Error: Both experiment_use_tmux and experiment_use_screen cannot be true simultaneously."
echo "Please set only one of them to true."
exit 1
fi
if [ "${var.experiment_use_tmux}" = "true" ]; then
echo "Running Amazon Q in the background with tmux..."
if ! command_exists tmux; then
echo "Error: tmux is not installed. Please install tmux manually."
exit 1
fi
touch "$HOME/.amazon-q.log"
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
tmux new-session -d -s amazon-q -c "${var.folder}" "q chat --trust-all-tools | tee -a "$HOME/.amazon-q.log" && exec bash"
tmux send-keys -t amazon-q "${local.full_prompt}"
sleep 5
tmux send-keys -t amazon-q Enter
fi
if [ "${var.experiment_use_screen}" = "true" ]; then
echo "Running Amazon Q in the background..."
if ! command_exists screen; then
echo "Error: screen is not installed. Please install screen manually."
exit 1
fi
touch "$HOME/.amazon-q.log"
if [ ! -f "$HOME/.screenrc" ]; then
echo "Creating ~/.screenrc and adding multiuser settings..." | tee -a "$HOME/.amazon-q.log"
echo -e "multiuser on\nacladd $(whoami)" > "$HOME/.screenrc"
fi
if ! grep -q "^multiuser on$" "$HOME/.screenrc"; then
echo "Adding 'multiuser on' to ~/.screenrc..." | tee -a "$HOME/.amazon-q.log"
echo "multiuser on" >> "$HOME/.screenrc"
fi
if ! grep -q "^acladd $(whoami)$" "$HOME/.screenrc"; then
echo "Adding 'acladd $(whoami)' to ~/.screenrc..." | tee -a "$HOME/.amazon-q.log"
echo "acladd $(whoami)" >> "$HOME/.screenrc"
fi
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
screen -U -dmS amazon-q bash -c '
cd ${var.folder}
q chat --trust-all-tools | tee -a "$HOME/.amazon-q.log
exec bash
'
# Extremely hacky way to send the prompt to the screen session
# This will be fixed in the future, but `amazon-q` was not sending MCP
# tasks when an initial prompt is provided.
screen -S amazon-q -X stuff "${local.full_prompt}"
sleep 5
screen -S amazon-q -X stuff "^M"
else
if ! command_exists q; then
echo "Error: Amazon Q is not installed. Please enable install_amazon_q or install it manually."
exit 1
fi
fi
EOT
run_on_start = true
}
resource "coder_app" "amazon_q" {
slug = "amazon-q"
display_name = "Amazon Q"
agent_id = var.agent_id
command = <<-EOT
#!/bin/bash
set -e
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
if [ "${var.experiment_use_tmux}" = "true" ]; then
if tmux has-session -t amazon-q 2>/dev/null; then
echo "Attaching to existing Amazon Q tmux session." | tee -a "$HOME/.amazon-q.log"
tmux attach-session -t amazon-q
else
echo "Starting a new Amazon Q tmux session." | tee -a "$HOME/.amazon-q.log"
tmux new-session -s amazon-q -c ${var.folder} "q chat --trust-all-tools | tee -a \"$HOME/.amazon-q.log\"; exec bash"
fi
elif [ "${var.experiment_use_screen}" = "true" ]; then
if screen -list | grep -q "amazon-q"; then
echo "Attaching to existing Amazon Q screen session." | tee -a "$HOME/.amazon-q.log"
screen -xRR amazon-q
else
echo "Starting a new Amazon Q screen session." | tee -a "$HOME/.amazon-q.log"
screen -S amazon-q bash -c 'q chat --trust-all-tools | tee -a "$HOME/.amazon-q.log"; exec bash'
fi
else
cd ${var.folder}
q chat --trust-all-tools
fi
EOT
icon = var.icon
order = var.order
group = var.group
}
@@ -1,159 +0,0 @@
#!/bin/bash
# Install script for amazon-q module
set -o errexit
set -o pipefail
command_exists() {
command -v "$1" > /dev/null 2>&1
}
# Inputs
ARG_INSTALL=${ARG_INSTALL:-true}
ARG_VERSION=${ARG_VERSION:-latest}
ARG_Q_INSTALL_URL=${ARG_Q_INSTALL_URL:-https://desktop-release.q.us-east-1.amazonaws.com}
ARG_AUTH_TARBALL=${ARG_AUTH_TARBALL:-}
ARG_AGENT_CONFIG=${ARG_AGENT_CONFIG:-}
ARG_AGENT_NAME=${ARG_AGENT_NAME:-default-agent}
ARG_MODULE_DIR_NAME=${ARG_MODULE_DIR_NAME:-.aws/.amazonq}
ARG_CODER_MCP_APP_STATUS_SLUG=${ARG_CODER_MCP_APP_STATUS_SLUG:-}
ARG_CODER_MCP_INSTRUCTIONS=${ARG_CODER_MCP_INSTRUCTIONS:-}
ARG_REPORT_TASKS=${ARG_REPORT_TASKS:-true}
mkdir -p "$HOME/$ARG_MODULE_DIR_NAME"
# Decode base64 inputs
ARG_AGENT_CONFIG_DECODED=""
if [ -n "$ARG_AGENT_CONFIG" ]; then
ARG_AGENT_CONFIG_DECODED=$(echo -n "$ARG_AGENT_CONFIG" | base64 -d)
fi
ARG_CODER_MCP_INSTRUCTIONS_DECODED=""
if [ -n "$ARG_CODER_MCP_INSTRUCTIONS" ]; then
ARG_CODER_MCP_INSTRUCTIONS_DECODED=$(echo -n "$ARG_CODER_MCP_INSTRUCTIONS" | base64 -d)
fi
echo "--------------------------------"
echo "install: $ARG_INSTALL"
echo "version: $ARG_VERSION"
echo "q_install_url: $ARG_Q_INSTALL_URL"
echo "agent_name: $ARG_AGENT_NAME"
echo "coder_mcp_app_status_slug: $ARG_CODER_MCP_APP_STATUS_SLUG"
echo "module_dir_name: $ARG_MODULE_DIR_NAME"
echo "auth_tarball_provided: ${ARG_AUTH_TARBALL}"
echo "report_tasks: ${ARG_REPORT_TASKS}"
echo "--------------------------------"
# Install Amazon Q if requested
function install_amazon_q() {
if [ "$ARG_INSTALL" = "true" ]; then
echo "Installing Amazon Q..."
PREV_DIR="$PWD"
TMP_DIR="$(mktemp -d)"
cd "$TMP_DIR"
ARCH="$(uname -m)"
case "$ARCH" in
"x86_64")
Q_URL="${ARG_Q_INSTALL_URL}/${ARG_VERSION}/q-x86_64-linux.zip"
;;
"aarch64" | "arm64")
Q_URL="${ARG_Q_INSTALL_URL}/${ARG_VERSION}/q-aarch64-linux.zip"
;;
*)
echo "Error: Unsupported architecture: $ARCH. Amazon Q only supports x86_64 and arm64."
exit 1
;;
esac
echo "Downloading Amazon Q for $ARCH from $Q_URL..."
curl --proto '=https' --tlsv1.2 -sSf "$Q_URL" -o "q.zip"
unzip q.zip
./q/install.sh --no-confirm
cd "$PREV_DIR"
rm -rf "$TMP_DIR"
# Ensure binaries are discoverable; create stable symlink to q
CANDIDATES=(
"$(command -v q || true)"
"$HOME/.local/bin/q"
)
FOUND_BIN=""
for c in "${CANDIDATES[@]}"; do
if [ -n "$c" ] && [ -x "$c" ]; then
FOUND_BIN="$c"
break
fi
done
export PATH="$PATH:$HOME/.local/bin"
echo "Installed Amazon Q at: $(command -v q || true) (resolved: $FOUND_BIN)"
fi
}
# Extract authentication tarball
function extract_auth_tarball() {
if [ -n "$ARG_AUTH_TARBALL" ]; then
echo "Extracting auth tarball..."
if ! command_exists zstd; then
echo "Error: zstd is required to extract the authentication tarball but is not installed."
echo "Please install zstd using the pre_install_script parameter."
exit 1
fi
PREV_DIR="$PWD"
echo "$ARG_AUTH_TARBALL" | base64 -d > /tmp/auth.tar.zst
rm -rf ~/.local/share/amazon-q
mkdir -p ~/.local/share/amazon-q
cd ~/.local/share/amazon-q
tar -I zstd -xf /tmp/auth.tar.zst
rm /tmp/auth.tar.zst
cd "$PREV_DIR"
echo "Extracted auth tarball to ~/.local/share/amazon-q"
else
echo "Warning: No auth tarball provided. Amazon Q may require manual authentication."
fi
}
# Configure MCP integration and create agent
function configure_agent() {
# Create Amazon Q agent configuration directory
AGENT_CONFIG_DIR="$HOME/.aws/amazonq/cli-agents"
mkdir -p "$AGENT_CONFIG_DIR"
ALLOWED_TOOLS="coder_get_workspace\,coder_create_workspace\,coder_list_workspaces\,coder_list_templates\,coder_template_version_parameters\,coder_get_authenticated_user\,coder_create_workspace_build\,coder_create_template_version\,coder_get_workspace_agent_logs\,coder_get_workspace_build_logs\,coder_get_template_version_logs\,coder_update_template_active_version\,coder_upload_tar_file\,coder_create_template\,coder_delete_template\,coder_workspace_bash"
if [ -n "$ARG_AGENT_CONFIG_DECODED" ]; then
echo "Applying custom MCP configuration..."
# Use agent name as filename for the configuration
echo "$ARG_AGENT_CONFIG_DECODED" > "$AGENT_CONFIG_DIR/${ARG_AGENT_NAME}.json"
echo "Custom configuration saved to $AGENT_CONFIG_DIR/${ARG_AGENT_NAME}.json"
fi
if [ "$ARG_REPORT_TASKS" = "true" ]; then
echo "Configuring Amazon Q to report tasks via Coder MCP..."
q mcp add --name coder \
--command "coder" \
--agent "$ARG_AGENT_NAME" \
--args "exp,mcp,server,--allowed-tools,coder_report_task,--instructions,'$ARG_CODER_MCP_INSTRUCTIONS_DECODED'" \
--env "CODER_MCP_APP_STATUS_SLUG=${ARG_CODER_MCP_APP_STATUS_SLUG}" \
--env "CODER_MCP_AI_AGENTAPI_URL=http://localhost:3284" \
--env "CODER_AGENT_URL=${CODER_AGENT_URL}" \
--env "CODER_AGENT_TOKEN=${CODER_AGENT_TOKEN}" \
--force || echo "Warning: Failed to add Coder MCP server"
else
q mcp add --name coder \
--command "coder" \
--agent "$ARG_AGENT_NAME" \
--args "exp,mcp,server,--allowed-tools,coder_report_task" \
--env "CODER_AGENT_URL=${CODER_AGENT_URL}" \
--env "CODER_AGENT_TOKEN=${CODER_AGENT_TOKEN}" \
--force || echo "Warning: Failed to add Coder MCP server"
fi
echo "Added Coder MCP server into $ARG_AGENT_NAME in Amazon Q configuration"
q settings chat.defaultAgent "$ARG_AGENT_NAME"
}
# Main execution
install_amazon_q
extract_auth_tarball
configure_agent
echo "Amazon Q installation and configuration complete!"
@@ -1,67 +0,0 @@
#!/bin/bash
# Start script for amazon-q module
set -o errexit
set -o pipefail
command_exists() {
command -v "$1" > /dev/null 2>&1
}
# Decode inputs
ARG_AI_PROMPT=$(echo -n "${ARG_AI_PROMPT:-}" | base64 -d)
ARG_TRUST_ALL_TOOLS=${ARG_TRUST_ALL_TOOLS:-true}
ARG_MODULE_DIR_NAME=${ARG_MODULE_DIR_NAME:-.aws/amazonq}
ARG_WORKDIR=${ARG_WORKDIR:-"$HOME"}
ARG_REPORT_TASKS=${ARG_REPORT_TASKS:-true}
ARG_SERVER_PARAMETERS=${ARG_SERVER_PARAMETERS:-""}
echo "--------------------------------"
echo "ai_prompt: $ARG_AI_PROMPT"
echo "trust_all_tools: $ARG_TRUST_ALL_TOOLS"
echo "module_dir_name: $ARG_MODULE_DIR_NAME"
echo "workdir: $ARG_WORKDIR"
echo "report_tasks: ${ARG_REPORT_TASKS}"
echo "--------------------------------"
mkdir -p "$HOME/$ARG_MODULE_DIR_NAME"
# Find Amazon Q CLI
if command_exists q; then
Q_CMD=q
elif [ -x "$HOME/.local/bin/q" ]; then
Q_CMD="$HOME/.local/bin/q"
else
echo "Error: Amazon Q CLI not found. Install it or set install_amazon_q=true."
exit 1
fi
mkdir -p "$ARG_WORKDIR"
cd "$ARG_WORKDIR"
# Set up environment
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
# Build command arguments
ARGS=(chat)
if [ "$ARG_TRUST_ALL_TOOLS" = "true" ]; then
ARGS+=(--trust-all-tools)
fi
# Log and run with agentapi integration
printf "Running: %q %s\n" "$Q_CMD" "$(printf '%q ' "${ARGS[@]}")"
# If we have an AI prompt, we need to handle it specially
if [ -n "$ARG_AI_PROMPT" ]; then
if [ "$ARG_REPORT_TASKS" == "true" ]; then
PROMPT="Every step of the way, report your progress using coder_report_task tool with proper summary and statuses. Your task at hand: $ARG_AI_PROMPT"
else
PROMPT="$ARG_AI_PROMPT"
fi
ARGS+=("$PROMPT")
fi
# Use agentapi to manage the interactive session with initial prompt
agentapi server ${ARG_SERVER_PARAMETERS} --term-width 67 --term-height 1190 -- "$Q_CMD" "${ARGS[@]}"
@@ -1,27 +0,0 @@
{
"name": "agent",
"description": "This is an default agent config",
"prompt": ${system_prompt},
"mcpServers": {},
"tools": [
"fs_read",
"fs_write",
"execute_bash",
"use_aws",
"@coder",
"knowledge"
],
"toolAliases": {},
"allowedTools": [
"fs_read",
"@coder"
],
"resources": [
"file://AmazonQ.md",
"file://README.md",
"file://.amazonq/rules/**/*.md"
],
"hooks": {},
"toolsSettings": {},
"useLegacyMcpJson": true
}
+80 -260
View File
@@ -1,297 +1,117 @@
---
display_name: Claude Code
description: Run the Claude Code agent in your workspace.
description: Run Claude Code in your workspace
icon: ../../../../.icons/claude.svg
verified: true
tags: [agent, claude-code, ai, tasks, anthropic]
tags: [agent, claude-code, ai, tasks]
---
# Claude Code
Run the [Claude Code](https://docs.anthropic.com/en/docs/agents-and-tools/claude-code/overview) agent in your workspace to generate code and perform tasks. This module integrates with [AgentAPI](https://github.com/coder/agentapi) for task reporting in the Coder UI.
```tf
module "claude-code" {
source = "registry.coder.com/coder/claude-code/coder"
version = "3.1.1"
agent_id = coder_agent.example.id
workdir = "/home/coder/project"
claude_api_key = "xxxx-xxxxx-xxxx"
}
```
> [!WARNING]
> **Security Notice**: This module uses the `--dangerously-skip-permissions` flag when running Claude Code tasks. This flag bypasses standard permission checks and allows Claude Code broader access to your system than normally permitted. While this enables more functionality, it also means Claude Code can potentially execute commands with the same privileges as the user running it. Use this module _only_ in trusted environments and be aware of the security implications.
> [!NOTE]
> By default, this module is configured to run the embedded chat interface as a path-based application. In production, we recommend that you configure a [wildcard access URL](https://coder.com/docs/admin/setup#wildcard-access-url) and set `subdomain = true`. See [here](https://coder.com/docs/tutorials/best-practices/security-best-practices#disable-path-based-apps) for more details.
## Prerequisites
- An **Anthropic API key** or a _Claude Session Token_ is required for tasks.
- You can get the API key from the [Anthropic Console](https://console.anthropic.com/dashboard).
- You can get the Session Token using the `claude setup-token` command. This is a long-lived authentication token (requires Claude subscription)
## Examples
### Usage with Tasks and Advanced Configuration
This example shows how to configure the Claude Code module with an AI prompt, API key shared by all users of the template, and other custom settings.
```tf
data "coder_parameter" "ai_prompt" {
type = "string"
name = "AI Prompt"
default = ""
description = "Initial task prompt for Claude Code."
mutable = true
}
module "claude-code" {
source = "registry.coder.com/coder/claude-code/coder"
version = "3.1.1"
agent_id = coder_agent.example.id
workdir = "/home/coder/project"
claude_api_key = "xxxx-xxxxx-xxxx"
# OR
claude_code_oauth_token = "xxxxx-xxxx-xxxx"
claude_code_version = "1.0.82" # Pin to a specific version
agentapi_version = "v0.10.0"
ai_prompt = data.coder_parameter.ai_prompt.value
model = "sonnet"
permission_mode = "plan"
mcp = <<-EOF
{
"mcpServers": {
"my-custom-tool": {
"command": "my-tool-server"
"args": ["--port", "8080"]
}
}
}
EOF
}
```
### Standalone Mode
Run and configure Claude Code as a standalone CLI in your workspace.
Run the [Claude Code](https://docs.anthropic.com/en/docs/agents-and-tools/claude-code/overview) agent in your workspace to generate code and perform tasks.
```tf
module "claude-code" {
source = "registry.coder.com/coder/claude-code/coder"
version = "3.1.1"
version = "2.2.0"
agent_id = coder_agent.example.id
workdir = "/home/coder"
folder = "/home/coder"
install_claude_code = true
claude_code_version = "latest"
report_tasks = false
cli_app = true
}
```
### Usage with Claude Code Subscription
> **Security Notice**: This module uses the [`--dangerously-skip-permissions`](https://docs.anthropic.com/en/docs/claude-code/cli-usage#cli-flags) flag when running Claude Code. This flag
> bypasses standard permission checks and allows Claude Code broader access to your system than normally permitted. While
> this enables more functionality, it also means Claude Code can potentially execute commands with the same privileges as
> the user running it. Use this module _only_ in trusted environments and be aware of the security implications.
## Prerequisites
- You must add the [Coder Login](https://registry.coder.com/modules/coder-login) module to your template
The `codercom/oss-dogfood:latest` container image can be used for testing on container-based workspaces.
## Examples
### Run in the background and report tasks (Experimental)
> This functionality is in early access as of Coder v2.21 and is still evolving.
> For now, we recommend testing it in a demo or staging environment,
> rather than deploying to production
>
> Learn more in [the Coder documentation](https://coder.com/docs/tutorials/ai-agents)
>
> Join our [Discord channel](https://discord.gg/coder) or
> [contact us](https://coder.com/contact) to get help or share feedback.
```tf
variable "claude_code_oauth_token" {
variable "anthropic_api_key" {
type = string
description = "Generate one using `claude setup-token` command"
description = "The Anthropic API key"
sensitive = true
value = "xxxx-xxx-xxxx"
}
module "coder-login" {
count = data.coder_workspace.me.start_count
source = "registry.coder.com/coder/coder-login/coder"
version = "1.0.15"
agent_id = coder_agent.example.id
}
data "coder_parameter" "ai_prompt" {
type = "string"
name = "AI Prompt"
default = ""
description = "Write a prompt for Claude Code"
mutable = true
}
# Set the prompt and system prompt for Claude Code via environment variables
resource "coder_agent" "main" {
# ...
env = {
CODER_MCP_CLAUDE_API_KEY = var.anthropic_api_key # or use a coder_parameter
CODER_MCP_CLAUDE_TASK_PROMPT = data.coder_parameter.ai_prompt.value
CODER_MCP_APP_STATUS_SLUG = "claude-code"
CODER_MCP_CLAUDE_SYSTEM_PROMPT = <<-EOT
You are a helpful assistant that can help with code.
EOT
}
}
module "claude-code" {
source = "registry.coder.com/coder/claude-code/coder"
version = "3.1.1"
agent_id = coder_agent.example.id
workdir = "/home/coder/project"
claude_code_oauth_token = var.claude_code_oauth_token
count = data.coder_workspace.me.start_count
source = "registry.coder.com/coder/claude-code/coder"
version = "2.2.0"
agent_id = coder_agent.example.id
folder = "/home/coder"
install_claude_code = true
claude_code_version = "1.0.40"
# Enable experimental features
experiment_report_tasks = true
}
```
### Usage with AWS Bedrock
## Run standalone
#### Prerequisites
AWS account with Bedrock access, Claude models enabled in Bedrock console, appropriate IAM permissions.
Configure Claude Code to use AWS Bedrock for accessing Claude models through your AWS infrastructure.
Run Claude Code as a standalone app in your workspace. This will install Claude Code and run it without any task reporting to the Coder UI.
```tf
resource "coder_env" "bedrock_use" {
agent_id = coder_agent.example.id
name = "CLAUDE_CODE_USE_BEDROCK"
value = "1"
}
resource "coder_env" "aws_region" {
agent_id = coder_agent.example.id
name = "AWS_REGION"
value = "us-east-1" # Choose your preferred region
}
# Option 1: Using AWS credentials
variable "aws_access_key_id" {
type = string
description = "Your AWS access key ID. Create this in the AWS IAM console under 'Security credentials'."
sensitive = true
value = "xxxx-xxx-xxxx"
}
variable "aws_secret_access_key" {
type = string
description = "Your AWS secret access key. This is shown once when you create an access key in the AWS IAM console."
sensitive = true
value = "xxxx-xxx-xxxx"
}
resource "coder_env" "aws_access_key_id" {
agent_id = coder_agent.example.id
name = "AWS_ACCESS_KEY_ID"
value = var.aws_access_key_id
}
resource "coder_env" "aws_secret_access_key" {
agent_id = coder_agent.example.id
name = "AWS_SECRET_ACCESS_KEY"
value = var.aws_secret_access_key
}
# Option 2: Using Bedrock API key (simpler)
variable "aws_bearer_token_bedrock" {
type = string
description = "Your AWS Bedrock bearer token. This provides access to Bedrock without needing separate access key and secret key."
sensitive = true
value = "xxxx-xxx-xxxx"
}
resource "coder_env" "bedrock_api_key" {
agent_id = coder_agent.example.id
name = "AWS_BEARER_TOKEN_BEDROCK"
value = var.aws_bearer_token_bedrock
}
module "claude-code" {
source = "registry.coder.com/coder/claude-code/coder"
version = "3.1.1"
agent_id = coder_agent.example.id
workdir = "/home/coder/project"
model = "global.anthropic.claude-sonnet-4-5-20250929-v1:0"
source = "registry.coder.com/coder/claude-code/coder"
version = "2.2.0"
agent_id = coder_agent.example.id
folder = "/home/coder"
install_claude_code = true
claude_code_version = "latest"
# Icon is not available in Coder v2.20 and below, so we'll use a custom icon URL
icon = "https://registry.npmmirror.com/@lobehub/icons-static-png/1.24.0/files/dark/claude-color.png"
}
```
> [!NOTE]
> For additional Bedrock configuration options (model selection, token limits, region overrides, etc.), see the [Claude Code Bedrock documentation](https://docs.claude.com/en/docs/claude-code/amazon-bedrock).
### Usage with Google Vertex AI
#### Prerequisites
GCP project with Vertex AI API enabled, Claude models enabled through Model Garden, service account with Vertex AI permissions, appropriate IAM permissions (Vertex AI User role).
Configure Claude Code to use Google Vertex AI for accessing Claude models through Google Cloud Platform.
```tf
variable "vertex_sa_json" {
type = string
description = "The complete JSON content of your Google Cloud service account key file. Create a service account in the GCP Console under 'IAM & Admin > Service Accounts', then create and download a JSON key. Copy the entire JSON content into this variable."
sensitive = true
}
resource "coder_env" "vertex_use" {
agent_id = coder_agent.example.id
name = "CLAUDE_CODE_USE_VERTEX"
value = "1"
}
resource "coder_env" "vertex_project_id" {
agent_id = coder_agent.example.id
name = "ANTHROPIC_VERTEX_PROJECT_ID"
value = "your-gcp-project-id"
}
resource "coder_env" "cloud_ml_region" {
agent_id = coder_agent.example.id
name = "CLOUD_ML_REGION"
value = "global"
}
resource "coder_env" "vertex_sa_json" {
agent_id = coder_agent.example.id
name = "VERTEX_SA_JSON"
value = var.vertex_sa_json
}
resource "coder_env" "google_application_credentials" {
agent_id = coder_agent.example.id
name = "GOOGLE_APPLICATION_CREDENTIALS"
value = "/tmp/gcp-sa.json"
}
module "claude-code" {
source = "registry.coder.com/coder/claude-code/coder"
version = "3.1.1"
agent_id = coder_agent.example.id
workdir = "/home/coder/project"
model = "claude-sonnet-4@20250514"
pre_install_script = <<-EOT
#!/bin/bash
# Write the service account JSON to a file
echo "$VERTEX_SA_JSON" > /tmp/gcp-sa.json
# Install prerequisite packages
sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates gnupg curl
# Add Google Cloud public key
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo gpg --dearmor -o /usr/share/keyrings/cloud.google.gpg
# Add Google Cloud SDK repo to apt sources
echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | sudo tee /etc/apt/sources.list.d/google-cloud-sdk.list
# Update and install the Google Cloud SDK
sudo apt-get update && sudo apt-get install -y google-cloud-cli
# Authenticate gcloud with the service account
gcloud auth activate-service-account --key-file=/tmp/gcp-sa.json
EOT
}
```
> [!NOTE]
> For additional Vertex AI configuration options (model selection, token limits, region overrides, etc.), see the [Claude Code Vertex AI documentation](https://docs.claude.com/en/docs/claude-code/google-vertex-ai).
## Troubleshooting
If you encounter any issues, check the log files in the `~/.claude-module` directory within your workspace for detailed information.
```bash
# Installation logs
cat ~/.claude-module/install.log
# Startup logs
cat ~/.claude-module/agentapi-start.log
# Pre/post install script logs
cat ~/.claude-module/pre_install.log
cat ~/.claude-module/post_install.log
```
> [!NOTE]
> To use tasks with Claude Code, you must provide an `anthropic_api_key` or `claude_code_oauth_token`.
> The `workdir` variable is required and specifies the directory where Claude Code will run.
## References
- [Claude Code Documentation](https://docs.anthropic.com/en/docs/agents-and-tools/claude-code/overview)
- [AgentAPI Documentation](https://github.com/coder/agentapi)
- [Coder AI Agents Guide](https://coder.com/docs/tutorials/ai-agents)
The module will create log files in the workspace's `~/.claude-module` directory. If you run into any issues, look at them for more information.
+247 -219
View File
@@ -1,26 +1,37 @@
import {
test,
afterEach,
expect,
describe,
setDefaultTimeout,
beforeAll,
expect,
} from "bun:test";
import { execContainer, readFileContainer, runTerraformInit } from "~test";
import path from "path";
import {
loadTestFile,
writeExecutable,
setup as setupUtil,
execModuleScript,
expectAgentAPIStarted,
} from "../agentapi/test-util";
import dedent from "dedent";
execContainer,
findResourceInstance,
readFileContainer,
removeContainer,
runContainer,
runTerraformApply,
runTerraformInit,
writeCoder,
writeFileContainer,
} from "~test";
let cleanupFunctions: (() => Promise<void>)[] = [];
const registerCleanup = (cleanup: () => Promise<void>) => {
cleanupFunctions.push(cleanup);
};
// Cleanup logic depends on the fact that bun's built-in test runner
// runs tests sequentially.
// https://bun.sh/docs/test/discovery#execution-order
// Weird things would happen if tried to run tests in parallel.
// One test could clean up resources that another test was still using.
afterEach(async () => {
// reverse the cleanup functions so that they are run in the correct order
const cleanupFnsCopy = cleanupFunctions.slice().reverse();
cleanupFunctions = [];
for (const cleanup of cleanupFnsCopy) {
@@ -32,281 +43,298 @@ afterEach(async () => {
}
});
const setupContainer = async ({
image,
vars,
}: {
image?: string;
vars?: Record<string, string>;
} = {}) => {
const state = await runTerraformApply(import.meta.dir, {
agent_id: "foo",
...vars,
});
const coderScript = findResourceInstance(state, "coder_script");
const id = await runContainer(image ?? "codercom/enterprise-node:latest");
registerCleanup(() => removeContainer(id));
return { id, coderScript };
};
const loadTestFile = async (...relativePath: string[]) => {
return await Bun.file(
path.join(import.meta.dir, "testdata", ...relativePath),
).text();
};
const writeExecutable = async ({
containerId,
filePath,
content,
}: {
containerId: string;
filePath: string;
content: string;
}) => {
await writeFileContainer(containerId, filePath, content, {
user: "root",
});
await execContainer(
containerId,
["bash", "-c", `chmod 755 ${filePath}`],
["--user", "root"],
);
};
const writeAgentAPIMockControl = async ({
containerId,
content,
}: {
containerId: string;
content: string;
}) => {
await writeFileContainer(containerId, "/tmp/agentapi-mock.control", content, {
user: "coder",
});
};
interface SetupProps {
skipAgentAPIMock?: boolean;
skipClaudeMock?: boolean;
moduleVariables?: Record<string, string>;
agentapiMockScript?: string;
}
const projectDir = "/home/coder/project";
const setup = async (props?: SetupProps): Promise<{ id: string }> => {
const projectDir = "/home/coder/project";
const { id } = await setupUtil({
moduleDir: import.meta.dir,
moduleVariables: {
install_claude_code: props?.skipClaudeMock ? "true" : "false",
const { id, coderScript } = await setupContainer({
vars: {
experiment_report_tasks: "true",
install_agentapi: props?.skipAgentAPIMock ? "true" : "false",
workdir: projectDir,
...props?.moduleVariables,
install_claude_code: "false",
agentapi_version: "preview",
folder: projectDir,
},
registerCleanup,
projectDir,
skipAgentAPIMock: props?.skipAgentAPIMock,
agentapiMockScript: props?.agentapiMockScript,
});
await execContainer(id, ["bash", "-c", `mkdir -p '${projectDir}'`]);
// the module script assumes that there is a coder executable in the PATH
await writeCoder(id, await loadTestFile("coder-mock.js"));
if (!props?.skipAgentAPIMock) {
await writeExecutable({
containerId: id,
filePath: "/usr/bin/agentapi",
content: await loadTestFile("agentapi-mock.js"),
});
}
if (!props?.skipClaudeMock) {
await writeExecutable({
containerId: id,
filePath: "/usr/bin/claude",
content: await loadTestFile(import.meta.dir, "claude-mock.sh"),
content: await loadTestFile("claude-mock.js"),
});
}
await writeExecutable({
containerId: id,
filePath: "/home/coder/script.sh",
content: coderScript.script,
});
return { id };
};
const expectAgentAPIStarted = async (id: string) => {
const resp = await execContainer(id, [
"bash",
"-c",
`curl -fs -o /dev/null "http://localhost:3284/status"`,
]);
if (resp.exitCode !== 0) {
console.log("agentapi not started");
console.log(resp.stdout);
console.log(resp.stderr);
}
expect(resp.exitCode).toBe(0);
};
const execModuleScript = async (id: string) => {
const resp = await execContainer(id, [
"bash",
"-c",
`set -o errexit; set -o pipefail; cd /home/coder && ./script.sh 2>&1 | tee /home/coder/script.log`,
]);
if (resp.exitCode !== 0) {
console.log(resp.stdout);
console.log(resp.stderr);
}
return resp;
};
// increase the default timeout to 60 seconds
setDefaultTimeout(60 * 1000);
// we don't run these tests in CI because they take too long and make network
// calls. they are dedicated for local development.
describe("claude-code", async () => {
beforeAll(async () => {
await runTerraformInit(import.meta.dir);
});
// test that the script runs successfully if claude starts without any errors
test("happy-path", async () => {
const { id } = await setup();
await execModuleScript(id);
await expectAgentAPIStarted(id);
});
test("install-claude-code-version", async () => {
const version_to_install = "1.0.40";
const { id } = await setup({
skipClaudeMock: true,
moduleVariables: {
install_claude_code: "true",
claude_code_version: version_to_install,
},
});
await execModuleScript(id);
const resp = await execContainer(id, [
"bash",
"-c",
"cat /home/coder/.claude-module/install.log",
"sudo /home/coder/script.sh",
]);
expect(resp.stdout).toContain(version_to_install);
});
expect(resp.exitCode).toBe(0);
test("check-latest-claude-code-version-works", async () => {
const { id } = await setup({
skipClaudeMock: true,
skipAgentAPIMock: true,
moduleVariables: {
install_claude_code: "true",
},
});
await execModuleScript(id);
await expectAgentAPIStarted(id);
});
test("claude-api-key", async () => {
const apiKey = "test-api-key-123";
const { id } = await setup({
moduleVariables: {
claude_api_key: apiKey,
},
});
await execModuleScript(id);
// test that the script removes lastSessionId from the .claude.json file
test("last-session-id-removed", async () => {
const { id } = await setup();
const envCheck = await execContainer(id, [
"bash",
"-c",
'env | grep CLAUDE_API_KEY || echo "CLAUDE_API_KEY not found"',
]);
expect(envCheck.stdout).toContain("CLAUDE_API_KEY");
});
test("claude-mcp-config", async () => {
const mcpConfig = JSON.stringify({
mcpServers: {
test: {
command: "test-cmd",
type: "stdio",
await writeFileContainer(
id,
"/home/coder/.claude.json",
JSON.stringify({
projects: {
[projectDir]: {
lastSessionId: "123",
},
},
},
});
const { id } = await setup({
skipClaudeMock: true,
moduleVariables: {
mcp: mcpConfig,
},
});
await execModuleScript(id);
}),
);
const resp = await readFileContainer(id, "/home/coder/.claude.json");
expect(resp).toContain("test-cmd");
});
test("claude-task-prompt", async () => {
const prompt = "This is a task prompt for Claude.";
const { id } = await setup({
moduleVariables: {
ai_prompt: prompt,
},
});
await execModuleScript(id);
const resp = await execContainer(id, [
const catResp = await execContainer(id, [
"bash",
"-c",
"cat /home/coder/.claude-module/agentapi-start.log",
"cat /home/coder/.claude.json",
]);
expect(resp.stdout).toContain(prompt);
});
expect(catResp.exitCode).toBe(0);
expect(catResp.stdout).toContain("lastSessionId");
test("claude-permission-mode", async () => {
const mode = "plan";
const { id } = await setup({
moduleVariables: {
permission_mode: mode,
task_prompt: "test prompt",
},
});
await execModuleScript(id);
const respModuleScript = await execModuleScript(id);
expect(respModuleScript.exitCode).toBe(0);
const startLog = await execContainer(id, [
await expectAgentAPIStarted(id);
const catResp2 = await execContainer(id, [
"bash",
"-c",
"cat /home/coder/.claude-module/agentapi-start.log",
"cat /home/coder/.claude.json",
]);
expect(startLog.stdout).toContain(`--permission-mode ${mode}`);
expect(catResp2.exitCode).toBe(0);
expect(catResp2.stdout).not.toContain("lastSessionId");
});
test("claude-model", async () => {
const model = "opus";
const { id } = await setup({
moduleVariables: {
model: model,
task_prompt: "test prompt",
},
});
await execModuleScript(id);
// test that the script handles a .claude.json file that doesn't contain
// a lastSessionId field
test("last-session-id-not-found", async () => {
const { id } = await setup();
const startLog = await execContainer(id, [
"bash",
"-c",
"cat /home/coder/.claude-module/agentapi-start.log",
]);
expect(startLog.stdout).toContain(`--model ${model}`);
});
test("claude-continue-previous-conversation", async () => {
const { id } = await setup({
moduleVariables: {
continue: "true",
task_prompt: "test prompt",
},
});
await execModuleScript(id);
const startLog = await execContainer(id, [
"bash",
"-c",
"cat /home/coder/.claude-module/agentapi-start.log",
]);
expect(startLog.stdout).toContain("--continue");
});
test("pre-post-install-scripts", async () => {
const { id } = await setup({
moduleVariables: {
pre_install_script: "#!/bin/bash\necho 'claude-pre-install-script'",
post_install_script: "#!/bin/bash\necho 'claude-post-install-script'",
},
});
await execModuleScript(id);
const preInstallLog = await readFileContainer(
await writeFileContainer(
id,
"/home/coder/.claude-module/pre_install.log",
"/home/coder/.claude.json",
JSON.stringify({
projects: {
"/home/coder": {},
},
}),
);
expect(preInstallLog).toContain("claude-pre-install-script");
const postInstallLog = await readFileContainer(
id,
"/home/coder/.claude-module/post_install.log",
);
expect(postInstallLog).toContain("claude-post-install-script");
});
const respModuleScript = await execModuleScript(id);
expect(respModuleScript.exitCode).toBe(0);
test("workdir-variable", async () => {
const workdir = "/home/coder/claude-test-folder";
const { id } = await setup({
skipClaudeMock: false,
moduleVariables: {
workdir,
},
});
await execModuleScript(id);
await expectAgentAPIStarted(id);
const resp = await readFileContainer(
id,
"/home/coder/.claude-module/agentapi-start.log",
);
expect(resp).toContain(workdir);
});
test("coder-mcp-config-created", async () => {
const { id } = await setup({
moduleVariables: {
install_claude_code: "false",
},
});
await execModuleScript(id);
const installLog = await readFileContainer(
id,
"/home/coder/.claude-module/install.log",
);
expect(installLog).toContain(
"Configuring Claude Code to report tasks via Coder MCP",
);
});
test("dangerously-skip-permissions", async () => {
const { id } = await setup({
moduleVariables: {
dangerously_skip_permissions: "true",
},
});
await execModuleScript(id);
const startLog = await execContainer(id, [
const catResp = await execContainer(id, [
"bash",
"-c",
"cat /home/coder/.claude-module/agentapi-start.log",
]);
expect(startLog.stdout).toContain(`--dangerously-skip-permissions`);
expect(catResp.exitCode).toBe(0);
expect(catResp.stdout).toContain(
"No lastSessionId found in .claude.json - nothing to do",
);
});
test("subdomain-false", async () => {
const { id } = await setup({
skipAgentAPIMock: true,
moduleVariables: {
subdomain: "false",
post_install_script: dedent`
#!/bin/bash
env | grep AGENTAPI_CHAT_BASE_PATH || echo "AGENTAPI_CHAT_BASE_PATH not found"
`,
},
// test that if claude fails to run with the --continue flag and returns a
// no conversation found error, then the module script retries without the flag
test("no-conversation-found", async () => {
const { id } = await setup();
await writeAgentAPIMockControl({
containerId: id,
content: "no-conversation-found",
});
await execModuleScript(id);
const startLog = await execContainer(id, [
// check that mocking works
const respAgentAPI = await execContainer(id, [
"bash",
"-c",
"cat /home/coder/.claude-module/post_install.log",
"agentapi --continue",
]);
expect(startLog.stdout).toContain(
"ARG_AGENTAPI_CHAT_BASE_PATH=/@default/default.foo/apps/ccw/chat",
expect(respAgentAPI.exitCode).toBe(1);
expect(respAgentAPI.stderr).toContain("No conversation found to continue");
const respModuleScript = await execModuleScript(id);
expect(respModuleScript.exitCode).toBe(0);
await expectAgentAPIStarted(id);
});
test("install-agentapi", async () => {
const { id } = await setup({ skipAgentAPIMock: true });
const respModuleScript = await execModuleScript(id);
expect(respModuleScript.exitCode).toBe(0);
await expectAgentAPIStarted(id);
const respAgentAPI = await execContainer(id, [
"bash",
"-c",
"agentapi --version",
]);
expect(respAgentAPI.exitCode).toBe(0);
});
// the coder binary should be executed with specific env vars
// that are set by the module script
test("coder-env-vars", async () => {
const { id } = await setup();
const respModuleScript = await execModuleScript(id);
expect(respModuleScript.exitCode).toBe(0);
const respCoderMock = await execContainer(id, [
"bash",
"-c",
"cat /home/coder/coder-mock-output.json",
]);
if (respCoderMock.exitCode !== 0) {
console.log(respCoderMock.stdout);
console.log(respCoderMock.stderr);
}
expect(respCoderMock.exitCode).toBe(0);
expect(JSON.parse(respCoderMock.stdout)).toEqual({
statusSlug: "ccw",
agentApiUrl: "http://localhost:3284",
});
});
// verify that the agentapi binary has access to the AGENTAPI_ALLOWED_HOSTS environment variable
// set in main.tf
test("agentapi-allowed-hosts", async () => {
const { id } = await setup();
const respModuleScript = await execModuleScript(id);
expect(respModuleScript.exitCode).toBe(0);
await expectAgentAPIStarted(id);
const agentApiStartLog = await readFileContainer(
id,
"/home/coder/agentapi-mock.log",
);
expect(agentApiStartLog).toContain("AGENTAPI_ALLOWED_HOSTS: *");
});
});
+217 -241
View File
@@ -36,72 +36,12 @@ variable "icon" {
default = "/icon/claude.svg"
}
variable "workdir" {
variable "folder" {
type = string
description = "The folder to run Claude Code in."
default = "/home/coder"
}
variable "report_tasks" {
type = bool
description = "Whether to enable task reporting to Coder UI via AgentAPI"
default = true
}
variable "cli_app" {
type = bool
description = "Whether to create a CLI app for Claude Code"
default = false
}
variable "web_app_display_name" {
type = string
description = "Display name for the web app"
default = "Claude Code"
}
variable "cli_app_display_name" {
type = string
description = "Display name for the CLI app"
default = "Claude Code CLI"
}
variable "pre_install_script" {
type = string
description = "Custom script to run before installing Claude Code."
default = null
}
variable "post_install_script" {
type = string
description = "Custom script to run after installing Claude Code."
default = null
}
variable "install_agentapi" {
type = bool
description = "Whether to install AgentAPI."
default = true
}
variable "agentapi_version" {
type = string
description = "The version of AgentAPI to install."
default = "v0.10.0"
}
variable "ai_prompt" {
type = string
description = "Initial task prompt for Claude Code."
default = ""
}
variable "subdomain" {
type = bool
description = "Whether to use a subdomain for AgentAPI."
default = false
}
variable "install_claude_code" {
type = bool
description = "Whether to install Claude Code."
@@ -114,209 +54,245 @@ variable "claude_code_version" {
default = "latest"
}
variable "claude_api_key" {
type = string
description = "The API key to use for the Claude Code server."
default = ""
}
variable "model" {
type = string
description = "Sets the model for the current session with an alias for the latest model (sonnet or opus) or a models full name."
default = ""
}
variable "resume_session_id" {
type = string
description = "Resume a specific session by ID."
default = ""
}
variable "continue" {
variable "experiment_cli_app" {
type = bool
description = "Load the most recent conversation in the current directory. Task will fail in a new workspace with no conversation/session to continue"
description = "Whether to create the CLI workspace app."
default = false
}
variable "dangerously_skip_permissions" {
variable "experiment_cli_app_order" {
type = number
description = "The order of the CLI workspace app."
default = null
}
variable "experiment_cli_app_group" {
type = string
description = "The group of the CLI workspace app."
default = null
}
variable "experiment_report_tasks" {
type = bool
description = "Skip the permission prompts. Use with caution. This will be set to true if using Coder Tasks"
description = "Whether to enable task reporting."
default = false
}
variable "permission_mode" {
variable "experiment_pre_install_script" {
type = string
description = "Permission mode for the cli, check https://docs.anthropic.com/en/docs/claude-code/iam#permission-modes"
default = ""
validation {
condition = contains(["", "default", "acceptEdits", "plan", "bypassPermissions"], var.permission_mode)
error_message = "interaction_mode must be one of: default, acceptEdits, plan, bypassPermissions."
}
description = "Custom script to run before installing Claude Code."
default = null
}
variable "mcp" {
variable "experiment_post_install_script" {
type = string
description = "MCP JSON to be added to the claude code local scope"
default = ""
description = "Custom script to run after installing Claude Code."
default = null
}
variable "allowed_tools" {
variable "install_agentapi" {
type = bool
description = "Whether to install AgentAPI."
default = true
}
variable "agentapi_version" {
type = string
description = "A list of tools that should be allowed without prompting the user for permission, in addition to settings.json files."
default = ""
description = "The version of AgentAPI to install."
default = "v0.3.3"
}
variable "disallowed_tools" {
type = string
description = "A list of tools that should be disallowed without prompting the user for permission, in addition to settings.json files."
default = ""
}
variable "claude_code_oauth_token" {
type = string
description = "Set up a long-lived authentication token (requires Claude subscription). Generated using `claude setup-token` command"
sensitive = true
default = ""
}
variable "system_prompt" {
type = string
description = "The system prompt to use for the Claude Code server."
default = ""
}
variable "claude_md_path" {
type = string
description = "The path to CLAUDE.md."
default = "$HOME/.claude/CLAUDE.md"
}
resource "coder_env" "claude_code_md_path" {
count = var.claude_md_path == "" ? 0 : 1
agent_id = var.agent_id
name = "CODER_MCP_CLAUDE_MD_PATH"
value = var.claude_md_path
}
resource "coder_env" "claude_code_system_prompt" {
agent_id = var.agent_id
name = "CODER_MCP_CLAUDE_SYSTEM_PROMPT"
value = local.final_system_prompt
}
resource "coder_env" "claude_code_oauth_token" {
agent_id = var.agent_id
name = "CLAUDE_CODE_OAUTH_TOKEN"
value = var.claude_code_oauth_token
}
resource "coder_env" "claude_api_key" {
count = length(var.claude_api_key) > 0 ? 1 : 0
agent_id = var.agent_id
name = "CLAUDE_API_KEY"
value = var.claude_api_key
variable "subdomain" {
type = bool
description = "Whether to use a subdomain for the Claude Code app."
default = true
}
locals {
# we have to trim the slash because otherwise coder exp mcp will
# set up an invalid claude config
workdir = trimsuffix(var.workdir, "/")
app_slug = "ccw"
install_script = file("${path.module}/scripts/install.sh")
start_script = file("${path.module}/scripts/start.sh")
module_dir_name = ".claude-module"
remove_last_session_id_script_b64 = base64encode(file("${path.module}/scripts/remove-last-session-id.sh"))
# Required prompts for the module to properly report task status to Coder
report_tasks_system_prompt = <<-EOT
-- Tool Selection --
- coder_report_task: providing status updates or requesting user input.
-- Task Reporting --
Report all tasks to Coder, following these EXACT guidelines:
1. Be granular. If you are investigating with multiple steps, report each step
to coder.
2. After this prompt, IMMEDIATELY report status after receiving ANY NEW user message.
Do not report any status related with this system prompt.
3. Use "state": "working" when actively processing WITHOUT needing
additional user input
4. Use "state": "complete" only when finished with a task
5. Use "state": "failure" when you need ANY user input, lack sufficient
details, or encounter blockers
In your summary on coder_report_task:
- Be specific about what you're doing
- Clearly indicate what information you need from the user when in "failure" state
- Keep it under 160 characters
- Make it actionable
EOT
# Only include coder system prompts if report_tasks is enabled
custom_system_prompt = trimspace(try(var.system_prompt, ""))
final_system_prompt = format("<system>%s%s</system>",
var.report_tasks ? format("\n%s\n", local.report_tasks_system_prompt) : "",
local.custom_system_prompt != "" ? format("\n%s\n", local.custom_system_prompt) : ""
)
workdir = trimsuffix(var.folder, "/")
encoded_pre_install_script = var.experiment_pre_install_script != null ? base64encode(var.experiment_pre_install_script) : ""
encoded_post_install_script = var.experiment_post_install_script != null ? base64encode(var.experiment_post_install_script) : ""
agentapi_start_script_b64 = base64encode(file("${path.module}/scripts/agentapi-start.sh"))
agentapi_wait_for_start_script_b64 = base64encode(file("${path.module}/scripts/agentapi-wait-for-start.sh"))
remove_last_session_id_script_b64 = base64encode(file("${path.module}/scripts/remove-last-session-id.sh"))
claude_code_app_slug = "ccw"
// Chat base path is only set if not using a subdomain.
// NOTE:
// - Initial support for --chat-base-path was added in v0.3.1 but configuration
// via environment variable AGENTAPI_CHAT_BASE_PATH was added in v0.3.3.
// - As CODER_WORKSPACE_AGENT_NAME is a recent addition we use agent ID
// for backward compatibility.
agentapi_chat_base_path = var.subdomain ? "" : "/@${data.coder_workspace_owner.me.name}/${data.coder_workspace.me.name}.${var.agent_id}/apps/${local.claude_code_app_slug}/chat"
server_base_path = var.subdomain ? "" : "/@${data.coder_workspace_owner.me.name}/${data.coder_workspace.me.name}.${var.agent_id}/apps/${local.claude_code_app_slug}"
healthcheck_url = "http://localhost:3284${local.server_base_path}/status"
}
module "agentapi" {
source = "registry.coder.com/coder/agentapi/coder"
version = "1.2.0"
agent_id = var.agent_id
web_app_slug = local.app_slug
web_app_order = var.order
web_app_group = var.group
web_app_icon = var.icon
web_app_display_name = var.web_app_display_name
folder = local.workdir
cli_app = var.cli_app
cli_app_slug = var.cli_app ? "${local.app_slug}-cli" : null
cli_app_display_name = var.cli_app ? var.cli_app_display_name : null
agentapi_subdomain = var.subdomain
module_dir_name = local.module_dir_name
install_agentapi = var.install_agentapi
agentapi_version = var.agentapi_version
pre_install_script = var.pre_install_script
post_install_script = var.post_install_script
start_script = <<-EOT
#!/bin/bash
set -o errexit
set -o pipefail
echo -n '${base64encode(local.start_script)}' | base64 -d > /tmp/start.sh
echo -n "${local.remove_last_session_id_script_b64}" | base64 -d > "/tmp/remove-last-session-id.sh"
chmod +x /tmp/start.sh
chmod +x /tmp/remove-last-session-id.sh
ARG_MODEL='${var.model}' \
ARG_RESUME_SESSION_ID='${var.resume_session_id}' \
ARG_CONTINUE='${var.continue}' \
ARG_DANGEROUSLY_SKIP_PERMISSIONS='${var.dangerously_skip_permissions}' \
ARG_PERMISSION_MODE='${var.permission_mode}' \
ARG_WORKDIR='${local.workdir}' \
ARG_AI_PROMPT='${base64encode(var.ai_prompt)}' \
/tmp/start.sh
EOT
install_script = <<-EOT
# Install and Initialize Claude Code
resource "coder_script" "claude_code" {
agent_id = var.agent_id
display_name = "Claude Code"
icon = var.icon
script = <<-EOT
#!/bin/bash
set -o errexit
set -o pipefail
set -e
set -x
echo -n '${base64encode(local.install_script)}' | base64 -d > /tmp/install.sh
chmod +x /tmp/install.sh
ARG_CLAUDE_CODE_VERSION='${var.claude_code_version}' \
ARG_MCP_APP_STATUS_SLUG='${local.app_slug}' \
ARG_INSTALL_CLAUDE_CODE='${var.install_claude_code}' \
ARG_REPORT_TASKS='${var.report_tasks}' \
ARG_WORKDIR='${local.workdir}' \
ARG_ALLOWED_TOOLS='${var.allowed_tools}' \
ARG_DISALLOWED_TOOLS='${var.disallowed_tools}' \
ARG_MCP='${var.mcp != null ? base64encode(replace(var.mcp, "'", "'\\''")) : ""}' \
/tmp/install.sh
EOT
command_exists() {
command -v "$1" >/dev/null 2>&1
}
function install_claude_code_cli() {
echo "Installing Claude Code via official installer"
set +e
curl -fsSL claude.ai/install.sh | bash -s -- "${var.claude_code_version}" 2>&1
CURL_EXIT=$${PIPESTATUS[0]}
set -e
if [ $CURL_EXIT -ne 0 ]; then
echo "Claude Code installer failed with exit code $$CURL_EXIT"
fi
# Ensure binaries are discoverable.
export PATH="~/.local/bin:$PATH"
echo "Installed Claude Code successfully. Version: $(claude --version || echo 'unknown')"
}
if [ ! -d "${local.workdir}" ]; then
echo "Warning: The specified folder '${local.workdir}' does not exist."
echo "Creating the folder..."
mkdir -p "${local.workdir}"
echo "Folder created successfully."
fi
if [ -n "${local.encoded_pre_install_script}" ]; then
echo "Running pre-install script..."
echo "${local.encoded_pre_install_script}" | base64 -d > /tmp/pre_install.sh
chmod +x /tmp/pre_install.sh
/tmp/pre_install.sh
fi
if [ "${var.install_claude_code}" = "true" ]; then
install_claude_code_cli
fi
# Install AgentAPI if enabled
if [ "${var.install_agentapi}" = "true" ]; then
echo "Installing AgentAPI..."
arch=$(uname -m)
if [ "$arch" = "x86_64" ]; then
binary_name="agentapi-linux-amd64"
elif [ "$arch" = "aarch64" ]; then
binary_name="agentapi-linux-arm64"
else
echo "Error: Unsupported architecture: $arch"
exit 1
fi
curl \
--retry 5 \
--retry-delay 5 \
--fail \
--retry-all-errors \
-L \
-C - \
-o agentapi \
"https://github.com/coder/agentapi/releases/download/${var.agentapi_version}/$binary_name"
chmod +x agentapi
sudo mv agentapi /usr/local/bin/agentapi
fi
if ! command_exists agentapi; then
echo "Error: AgentAPI is not installed. Please enable install_agentapi or install it manually."
exit 1
fi
# this must be kept in sync with the agentapi-start.sh script
module_path="$HOME/.claude-module"
mkdir -p "$module_path/scripts"
# save the prompt for the agentapi start command
echo -n "$CODER_MCP_CLAUDE_TASK_PROMPT" > "$module_path/prompt.txt"
echo -n "${local.agentapi_start_script_b64}" | base64 -d > "$module_path/scripts/agentapi-start.sh"
echo -n "${local.agentapi_wait_for_start_script_b64}" | base64 -d > "$module_path/scripts/agentapi-wait-for-start.sh"
echo -n "${local.remove_last_session_id_script_b64}" | base64 -d > "$module_path/scripts/remove-last-session-id.sh"
chmod +x "$module_path/scripts/agentapi-start.sh"
chmod +x "$module_path/scripts/agentapi-wait-for-start.sh"
if [ "${var.experiment_report_tasks}" = "true" ]; then
echo "Configuring Claude Code to report tasks via Coder MCP..."
export CODER_MCP_APP_STATUS_SLUG="${local.claude_code_app_slug}"
export CODER_MCP_AI_AGENTAPI_URL="http://localhost:3284"
coder exp mcp configure claude-code "${local.workdir}"
fi
if [ -n "${local.encoded_post_install_script}" ]; then
echo "Running post-install script..."
echo "${local.encoded_post_install_script}" | base64 -d > /tmp/post_install.sh
chmod +x /tmp/post_install.sh
/tmp/post_install.sh
fi
if ! command_exists claude; then
echo "Error: Claude Code is not installed. Please enable install_claude_code or install it manually."
exit 1
fi
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
cd "${local.workdir}"
# Disable host header check since AgentAPI is proxied by Coder (which does its own validation)
export AGENTAPI_ALLOWED_HOSTS="*"
# Set chat base path for non-subdomain routing (only set if not using subdomain)
export AGENTAPI_CHAT_BASE_PATH="${local.agentapi_chat_base_path}"
nohup "$module_path/scripts/agentapi-start.sh" use_prompt &> "$module_path/agentapi-start.log" &
"$module_path/scripts/agentapi-wait-for-start.sh"
EOT
run_on_start = true
}
resource "coder_app" "claude_code_web" {
# use a short slug to mitigate https://github.com/coder/coder/issues/15178
slug = local.claude_code_app_slug
display_name = "Claude Code Web"
agent_id = var.agent_id
url = "http://localhost:3284/"
icon = var.icon
order = var.order
group = var.group
subdomain = var.subdomain
healthcheck {
url = local.healthcheck_url
interval = 3
threshold = 20
}
}
resource "coder_app" "claude_code" {
count = var.experiment_cli_app ? 1 : 0
slug = "claude-code"
display_name = "Claude Code CLI"
agent_id = var.agent_id
command = <<-EOT
#!/bin/bash
set -e
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
agentapi attach
EOT
icon = var.icon
order = var.experiment_cli_app_order
group = var.experiment_cli_app_group
}
resource "coder_ai_task" "claude_code" {
sidebar_app {
id = coder_app.claude_code_web.id
}
}
@@ -1,270 +0,0 @@
run "test_claude_code_basic" {
command = plan
variables {
agent_id = "test-agent-123"
workdir = "/home/coder/projects"
}
assert {
condition = var.workdir == "/home/coder/projects"
error_message = "Workdir variable should be set correctly"
}
assert {
condition = var.agent_id == "test-agent-123"
error_message = "Agent ID variable should be set correctly"
}
assert {
condition = var.install_claude_code == true
error_message = "Install claude_code should default to true"
}
assert {
condition = var.install_agentapi == true
error_message = "Install agentapi should default to true"
}
assert {
condition = var.report_tasks == true
error_message = "report_tasks should default to true"
}
}
run "test_claude_code_with_api_key" {
command = plan
variables {
agent_id = "test-agent-456"
workdir = "/home/coder/workspace"
claude_api_key = "test-api-key-123"
}
assert {
condition = coder_env.claude_api_key[0].value == "test-api-key-123"
error_message = "Claude API key value should match the input"
}
}
run "test_claude_code_with_custom_options" {
command = plan
variables {
agent_id = "test-agent-789"
workdir = "/home/coder/custom"
order = 5
group = "development"
icon = "/icon/custom.svg"
model = "opus"
task_prompt = "Help me write better code"
permission_mode = "plan"
continue = true
install_claude_code = false
install_agentapi = false
claude_code_version = "1.0.0"
agentapi_version = "v0.6.0"
dangerously_skip_permissions = true
}
assert {
condition = var.order == 5
error_message = "Order variable should be set to 5"
}
assert {
condition = var.group == "development"
error_message = "Group variable should be set to 'development'"
}
assert {
condition = var.icon == "/icon/custom.svg"
error_message = "Icon variable should be set to custom icon"
}
assert {
condition = var.model == "opus"
error_message = "Claude model variable should be set to 'opus'"
}
assert {
condition = var.task_prompt == "Help me write better code"
error_message = "Task prompt variable should be set correctly"
}
assert {
condition = var.permission_mode == "plan"
error_message = "Permission mode should be set to 'plan'"
}
assert {
condition = var.continue == true
error_message = "Continue should be set to true"
}
assert {
condition = var.claude_code_version == "1.0.0"
error_message = "Claude Code version should be set to '1.0.0'"
}
assert {
condition = var.agentapi_version == "v0.6.0"
error_message = "AgentAPI version should be set to 'v0.6.0'"
}
assert {
condition = var.dangerously_skip_permissions == true
error_message = "dangerously_skip_permissions should be set to true"
}
}
run "test_claude_code_with_mcp_and_tools" {
command = plan
variables {
agent_id = "test-agent-mcp"
workdir = "/home/coder/mcp-test"
mcp = jsonencode({
mcpServers = {
test = {
command = "test-server"
args = ["--config", "test.json"]
}
}
})
allowed_tools = "bash,python"
disallowed_tools = "rm"
}
assert {
condition = var.mcp != ""
error_message = "MCP configuration should be provided"
}
assert {
condition = var.allowed_tools == "bash,python"
error_message = "Allowed tools should be set"
}
assert {
condition = var.disallowed_tools == "rm"
error_message = "Disallowed tools should be set"
}
}
run "test_claude_code_with_scripts" {
command = plan
variables {
agent_id = "test-agent-scripts"
workdir = "/home/coder/scripts"
pre_install_script = "echo 'Pre-install script'"
post_install_script = "echo 'Post-install script'"
}
assert {
condition = var.pre_install_script == "echo 'Pre-install script'"
error_message = "Pre-install script should be set correctly"
}
assert {
condition = var.post_install_script == "echo 'Post-install script'"
error_message = "Post-install script should be set correctly"
}
}
run "test_claude_code_permission_mode_validation" {
command = plan
variables {
agent_id = "test-agent-validation"
workdir = "/home/coder/test"
permission_mode = "acceptEdits"
}
assert {
condition = contains(["", "default", "acceptEdits", "plan", "bypassPermissions"], var.permission_mode)
error_message = "Permission mode should be one of the valid options"
}
}
run "test_claude_code_system_prompt" {
command = plan
variables {
agent_id = "test-agent-system-prompt"
workdir = "/home/coder/test"
system_prompt = "Custom addition"
}
assert {
condition = trimspace(coder_env.claude_code_system_prompt.value) != ""
error_message = "System prompt should not be empty"
}
assert {
condition = length(regexall("Custom addition", coder_env.claude_code_system_prompt.value)) > 0
error_message = "System prompt should have system_prompt variable value"
}
}
run "test_claude_report_tasks_default" {
command = plan
variables {
agent_id = "test-agent-report-tasks"
workdir = "/home/coder/test"
# report_tasks: default is true
}
assert {
condition = trimspace(coder_env.claude_code_system_prompt.value) != ""
error_message = "System prompt should not be empty"
}
# Ensure system prompt is wrapped by <system>
assert {
condition = startswith(trimspace(coder_env.claude_code_system_prompt.value), "<system>")
error_message = "System prompt should start with <system>"
}
assert {
condition = endswith(trimspace(coder_env.claude_code_system_prompt.value), "</system>")
error_message = "System prompt should end with </system>"
}
# Ensure Coder sections are injected when report_tasks=true (default)
assert {
condition = length(regexall("-- Tool Selection --", coder_env.claude_code_system_prompt.value)) > 0
error_message = "System prompt should have Tool Selection section"
}
assert {
condition = length(regexall("-- Task Reporting --", coder_env.claude_code_system_prompt.value)) > 0
error_message = "System prompt should have Task Reporting section"
}
}
run "test_claude_report_tasks_disabled" {
command = plan
variables {
agent_id = "test-agent-report-tasks"
workdir = "/home/coder/test"
report_tasks = false
}
assert {
condition = trimspace(coder_env.claude_code_system_prompt.value) != ""
error_message = "System prompt should not be empty"
}
# Ensure system prompt is wrapped by <system>
assert {
condition = startswith(trimspace(coder_env.claude_code_system_prompt.value), "<system>")
error_message = "System prompt should start with <system>"
}
assert {
condition = endswith(trimspace(coder_env.claude_code_system_prompt.value), "</system>")
error_message = "System prompt should end with </system>"
}
}
@@ -0,0 +1,63 @@
#!/bin/bash
set -o errexit
set -o pipefail
# this must be kept in sync with the main.tf file
module_path="$HOME/.claude-module"
scripts_dir="$module_path/scripts"
log_file_path="$module_path/agentapi.log"
# if the first argument is not empty, start claude with the prompt
if [ -n "$1" ]; then
cp "$module_path/prompt.txt" /tmp/claude-code-prompt
else
rm -f /tmp/claude-code-prompt
fi
# if the log file already exists, archive it
if [ -f "$log_file_path" ]; then
mv "$log_file_path" "$log_file_path"".$(date +%s)"
fi
# see the remove-last-session-id.sh script for details
# about why we need it
# avoid exiting if the script fails
bash "$scripts_dir/remove-last-session-id.sh" "$(pwd)" 2> /dev/null || true
# we'll be manually handling errors from this point on
set +o errexit
function start_agentapi() {
local continue_flag="$1"
local prompt_subshell='"$(cat /tmp/claude-code-prompt)"'
# use low width to fit in the tasks UI sidebar. height is adjusted so that width x height ~= 80x1000 characters
# visible in the terminal screen by default.
agentapi server --term-width 67 --term-height 1190 -- \
bash -c "claude $continue_flag --dangerously-skip-permissions $prompt_subshell" \
> "$log_file_path" 2>&1
}
echo "Starting AgentAPI..."
# attempt to start claude with the --continue flag
start_agentapi --continue
exit_code=$?
echo "First AgentAPI exit code: $exit_code"
if [ $exit_code -eq 0 ]; then
exit 0
fi
# if there was no conversation to continue, claude exited with an error.
# start claude without the --continue flag.
if grep -q "No conversation found to continue" "$log_file_path"; then
echo "AgentAPI with --continue flag failed, starting claude without it."
start_agentapi
exit_code=$?
fi
echo "Second AgentAPI exit code: $exit_code"
exit $exit_code
@@ -0,0 +1,30 @@
#!/bin/bash
set -o errexit
set -o pipefail
# This script waits for the agentapi server to start on port 3284.
# It considers the server started after 3 consecutive successful responses.
agentapi_started=false
echo "Waiting for agentapi server to start on port 3284..."
for i in $(seq 1 150); do
for j in $(seq 1 3); do
sleep 0.1
if curl -fs -o /dev/null "http://localhost:3284/status"; then
echo "agentapi response received ($j/3)"
else
echo "agentapi server not responding ($i/15)"
continue 2
fi
done
agentapi_started=true
break
done
if [ "$agentapi_started" != "true" ]; then
echo "Error: agentapi server did not start on port 3284 after 15 seconds."
exit 1
fi
echo "agentapi server started on port 3284."
@@ -1,104 +0,0 @@
#!/bin/bash
set -euo pipefail
if [ -f "$HOME/.bashrc" ]; then
source "$HOME"/.bashrc
fi
BOLD='\033[0;1m'
command_exists() {
command -v "$1" > /dev/null 2>&1
}
ARG_CLAUDE_CODE_VERSION=${ARG_CLAUDE_CODE_VERSION:-}
ARG_WORKDIR=${ARG_WORKDIR:-"$HOME"}
ARG_INSTALL_CLAUDE_CODE=${ARG_INSTALL_CLAUDE_CODE:-}
ARG_REPORT_TASKS=${ARG_REPORT_TASKS:-true}
ARG_MCP_APP_STATUS_SLUG=${ARG_MCP_APP_STATUS_SLUG:-}
ARG_MCP=$(echo -n "${ARG_MCP:-}" | base64 -d)
ARG_ALLOWED_TOOLS=${ARG_ALLOWED_TOOLS:-}
ARG_DISALLOWED_TOOLS=${ARG_DISALLOWED_TOOLS:-}
echo "--------------------------------"
printf "ARG_CLAUDE_CODE_VERSION: %s\n" "$ARG_CLAUDE_CODE_VERSION"
printf "ARG_WORKDIR: %s\n" "$ARG_WORKDIR"
printf "ARG_INSTALL_CLAUDE_CODE: %s\n" "$ARG_INSTALL_CLAUDE_CODE"
printf "ARG_REPORT_TASKS: %s\n" "$ARG_REPORT_TASKS"
printf "ARG_MCP_APP_STATUS_SLUG: %s\n" "$ARG_MCP_APP_STATUS_SLUG"
printf "ARG_MCP: %s\n" "$ARG_MCP"
printf "ARG_ALLOWED_TOOLS: %s\n" "$ARG_ALLOWED_TOOLS"
printf "ARG_DISALLOWED_TOOLS: %s\n" "$ARG_DISALLOWED_TOOLS"
echo "--------------------------------"
function install_claude_code_cli() {
if [ "$ARG_INSTALL_CLAUDE_CODE" = "true" ]; then
echo "Installing Claude Code via official installer"
set +e
curl -fsSL claude.ai/install.sh | bash -s -- "$ARG_CLAUDE_CODE_VERSION" 2>&1
CURL_EXIT=${PIPESTATUS[0]}
set -e
if [ $CURL_EXIT -ne 0 ]; then
echo "Claude Code installer failed with exit code $$CURL_EXIT"
fi
# Ensure binaries are discoverable.
echo "Creating a symlink for claude"
sudo ln -s /home/coder/.local/bin/claude /usr/local/bin/claude
echo "Installed Claude Code successfully. Version: $(claude --version || echo 'unknown')"
else
echo "Skipping Claude Code installation as per configuration."
fi
}
function setup_claude_configurations() {
if [ ! -d "$ARG_WORKDIR" ]; then
echo "Warning: The specified folder '$ARG_WORKDIR' does not exist."
echo "Creating the folder..."
mkdir -p "$ARG_WORKDIR"
echo "Folder created successfully."
fi
module_path="$HOME/.claude-module"
mkdir -p "$module_path"
if [ "$ARG_MCP" != "" ]; then
while IFS= read -r server_name && IFS= read -r server_json; do
echo "------------------------"
echo "Executing: claude mcp add \"$server_name\" '$server_json'"
claude mcp add "$server_name" "$server_json"
echo "------------------------"
echo ""
done < <(echo "$ARG_MCP" | jq -r '.mcpServers | to_entries[] | .key, (.value | @json)')
fi
if [ -n "$ARG_ALLOWED_TOOLS" ]; then
coder --allowedTools "$ARG_ALLOWED_TOOLS"
fi
if [ -n "$ARG_DISALLOWED_TOOLS" ]; then
coder --disallowedTools "$ARG_DISALLOWED_TOOLS"
fi
}
function report_tasks() {
if [ "$ARG_REPORT_TASKS" = "true" ]; then
echo "Configuring Claude Code to report tasks via Coder MCP..."
export CODER_MCP_APP_STATUS_SLUG="$ARG_MCP_APP_STATUS_SLUG"
export CODER_MCP_AI_AGENTAPI_URL="http://localhost:3284"
coder exp mcp configure claude-code "$ARG_WORKDIR"
else
export CODER_MCP_APP_STATUS_SLUG=""
export CODER_MCP_AI_AGENTAPI_URL=""
echo "Configuring Claude Code with Coder MCP..."
coder exp mcp configure claude-code "$ARG_WORKDIR"
fi
}
install_claude_code_cli
setup_claude_configurations
report_tasks
@@ -1,84 +0,0 @@
#!/bin/bash
set -euo pipefail
if [ -f "$HOME/.bashrc" ]; then
source "$HOME"/.bashrc
fi
export PATH="$HOME/.local/bin:$PATH"
command_exists() {
command -v "$1" > /dev/null 2>&1
}
ARG_MODEL=${ARG_MODEL:-}
ARG_RESUME_SESSION_ID=${ARG_RESUME_SESSION_ID:-}
ARG_CONTINUE=${ARG_CONTINUE:-false}
ARG_DANGEROUSLY_SKIP_PERMISSIONS=${ARG_DANGEROUSLY_SKIP_PERMISSIONS:-}
ARG_PERMISSION_MODE=${ARG_PERMISSION_MODE:-}
ARG_WORKDIR=${ARG_WORKDIR:-"$HOME"}
ARG_AI_PROMPT=$(echo -n "${ARG_AI_PROMPT:-}" | base64 -d)
echo "--------------------------------"
printf "ARG_MODEL: %s\n" "$ARG_MODEL"
printf "ARG_RESUME: %s\n" "$ARG_RESUME_SESSION_ID"
printf "ARG_CONTINUE: %s\n" "$ARG_CONTINUE"
printf "ARG_DANGEROUSLY_SKIP_PERMISSIONS: %s\n" "$ARG_DANGEROUSLY_SKIP_PERMISSIONS"
printf "ARG_PERMISSION_MODE: %s\n" "$ARG_PERMISSION_MODE"
printf "ARG_AI_PROMPT: %s\n" "$ARG_AI_PROMPT"
printf "ARG_WORKDIR: %s\n" "$ARG_WORKDIR"
echo "--------------------------------"
# see the remove-last-session-id.sh script for details
# about why we need it
# avoid exiting if the script fails
bash "/tmp/remove-last-session-id.sh" "$(pwd)" 2> /dev/null || true
function validate_claude_installation() {
if command_exists claude; then
printf "Claude Code is installed\n"
else
printf "Error: Claude Code is not installed. Please enable install_claude_code or install it manually\n"
exit 1
fi
}
ARGS=()
function build_claude_args() {
if [ -n "$ARG_MODEL" ]; then
ARGS+=(--model "$ARG_MODEL")
fi
if [ -n "$ARG_RESUME_SESSION_ID" ]; then
ARGS+=(--resume "$ARG_RESUME_SESSION_ID")
fi
if [ "$ARG_CONTINUE" = "true" ]; then
ARGS+=(--continue)
fi
if [ -n "$ARG_PERMISSION_MODE" ]; then
ARGS+=(--permission-mode "$ARG_PERMISSION_MODE")
fi
}
function start_agentapi() {
mkdir -p "$ARG_WORKDIR"
cd "$ARG_WORKDIR"
if [ -n "$ARG_AI_PROMPT" ]; then
ARGS+=(--dangerously-skip-permissions "$ARG_AI_PROMPT")
else
if [ -n "$ARG_DANGEROUSLY_SKIP_PERMISSIONS" ]; then
ARGS+=(--dangerously-skip-permissions)
fi
fi
printf "Running claude code with args: %s\n" "$(printf '%q ' "${ARGS[@]}")"
agentapi server --type claude --term-width 67 --term-height 1190 -- claude "${ARGS[@]}"
}
validate_claude_installation
build_claude_args
start_agentapi
@@ -0,0 +1,39 @@
#!/usr/bin/env node
const http = require("http");
const fs = require("fs");
const args = process.argv.slice(2);
const port = 3284;
const controlFile = "/tmp/agentapi-mock.control";
let control = "";
if (fs.existsSync(controlFile)) {
control = fs.readFileSync(controlFile, "utf8");
}
if (
control === "no-conversation-found" &&
args.join(" ").includes("--continue")
) {
// this must match the error message in the agentapi-start.sh script
console.error("No conversation found to continue");
process.exit(1);
}
fs.writeFileSync(
"/home/coder/agentapi-mock.log",
`AGENTAPI_ALLOWED_HOSTS: ${process.env.AGENTAPI_ALLOWED_HOSTS}`,
);
console.log(`starting server on port ${port}`);
http
.createServer(function (_request, response) {
response.writeHead(200);
response.end(
JSON.stringify({
status: "stable",
}),
);
})
.listen(port);
@@ -0,0 +1,9 @@
#!/usr/bin/env node
const main = async () => {
console.log("mocking claude");
// sleep for 30 minutes
await new Promise((resolve) => setTimeout(resolve, 30 * 60 * 1000));
};
main();
@@ -1,13 +0,0 @@
#!/bin/bash
if [[ "$1" == "--version" ]]; then
echo "claude version v1.0.0"
exit 0
fi
set -e
while true; do
echo "$(date) - claude-mock"
sleep 15
done
@@ -0,0 +1,14 @@
#!/usr/bin/env node
const fs = require("fs");
const statusSlugEnvVar = "CODER_MCP_APP_STATUS_SLUG";
const agentApiUrlEnvVar = "CODER_MCP_AI_AGENTAPI_URL";
fs.writeFileSync(
"/home/coder/coder-mock-output.json",
JSON.stringify({
statusSlug: process.env[statusSlugEnvVar] ?? "env var not set",
agentApiUrl: process.env[agentApiUrlEnvVar] ?? "env var not set",
}),
);
+11 -34
View File
@@ -14,7 +14,7 @@ This module allows you to automatically clone a repository by URL and skip if it
module "git-clone" {
count = data.coder_workspace.me.start_count
source = "registry.coder.com/coder/git-clone/coder"
version = "1.2.0"
version = "1.1.1"
agent_id = coder_agent.example.id
url = "https://github.com/coder/coder"
}
@@ -28,7 +28,7 @@ module "git-clone" {
module "git-clone" {
count = data.coder_workspace.me.start_count
source = "registry.coder.com/coder/git-clone/coder"
version = "1.2.0"
version = "1.1.1"
agent_id = coder_agent.example.id
url = "https://github.com/coder/coder"
base_dir = "~/projects/coder"
@@ -43,12 +43,12 @@ To use with [Git Authentication](https://coder.com/docs/v2/latest/admin/git-prov
module "git-clone" {
count = data.coder_workspace.me.start_count
source = "registry.coder.com/coder/git-clone/coder"
version = "1.2.0"
version = "1.1.1"
agent_id = coder_agent.example.id
url = "https://github.com/coder/coder"
}
data "coder_external_auth" "github" {
data "coder_git_auth" "github" {
id = "github"
}
```
@@ -69,7 +69,7 @@ data "coder_parameter" "git_repo" {
module "git_clone" {
count = data.coder_workspace.me.start_count
source = "registry.coder.com/coder/git-clone/coder"
version = "1.2.0"
version = "1.1.1"
agent_id = coder_agent.example.id
url = data.coder_parameter.git_repo.value
}
@@ -103,7 +103,7 @@ Configuring `git-clone` for a self-hosted GitHub Enterprise Server running at `g
module "git-clone" {
count = data.coder_workspace.me.start_count
source = "registry.coder.com/coder/git-clone/coder"
version = "1.2.0"
version = "1.1.1"
agent_id = coder_agent.example.id
url = "https://github.example.com/coder/coder/tree/feat/example"
git_providers = {
@@ -122,7 +122,7 @@ To GitLab clone with a specific branch like `feat/example`
module "git-clone" {
count = data.coder_workspace.me.start_count
source = "registry.coder.com/coder/git-clone/coder"
version = "1.2.0"
version = "1.1.1"
agent_id = coder_agent.example.id
url = "https://gitlab.com/coder/coder/-/tree/feat/example"
}
@@ -134,7 +134,7 @@ Configuring `git-clone` for a self-hosted GitLab running at `gitlab.example.com`
module "git-clone" {
count = data.coder_workspace.me.start_count
source = "registry.coder.com/coder/git-clone/coder"
version = "1.2.0"
version = "1.1.1"
agent_id = coder_agent.example.id
url = "https://gitlab.example.com/coder/coder/-/tree/feat/example"
git_providers = {
@@ -155,7 +155,7 @@ For example, to clone the `feat/example` branch:
module "git-clone" {
count = data.coder_workspace.me.start_count
source = "registry.coder.com/coder/git-clone/coder"
version = "1.2.0"
version = "1.1.1"
agent_id = coder_agent.example.id
url = "https://github.com/coder/coder"
branch_name = "feat/example"
@@ -173,7 +173,7 @@ For example, this will clone into the `~/projects/coder/coder-dev` folder:
module "git-clone" {
count = data.coder_workspace.me.start_count
source = "registry.coder.com/coder/git-clone/coder"
version = "1.2.0"
version = "1.1.1"
agent_id = coder_agent.example.id
url = "https://github.com/coder/coder"
folder_name = "coder-dev"
@@ -192,32 +192,9 @@ If not defined, the default, `0`, performs a full clone.
module "git-clone" {
count = data.coder_workspace.me.start_count
source = "registry.coder.com/modules/git-clone/coder"
version = "1.2.0"
version = "1.1.0"
agent_id = coder_agent.example.id
url = "https://github.com/coder/coder"
depth = 1
}
```
## Post-clone script
Run a custom script after cloning the repository by setting the `post_clone_script` variable.
This is useful for running initialization tasks like installing dependencies or setting up the environment.
```tf
module "git-clone" {
count = data.coder_workspace.me.start_count
source = "registry.coder.com/coder/git-clone/coder"
version = "1.2.0"
agent_id = coder_agent.example.id
url = "https://github.com/coder/coder"
post_clone_script = <<-EOT
#!/bin/bash
echo "Repository cloned successfully!"
# Install dependencies
npm install
# Run any other initialization tasks
make setup
EOT
}
```
+1 -18
View File
@@ -30,12 +30,11 @@ describe("git-clone", async () => {
url: "fake-url",
});
const output = await executeScriptInContainer(state, "alpine/git");
expect(output.exitCode).toBe(128);
expect(output.stdout).toEqual([
"Creating directory ~/fake-url...",
"Cloning fake-url to ~/fake-url...",
]);
expect(output.stderr.join(" ")).toContain("fatal");
expect(output.stderr.join(" ")).toContain("fake-url");
});
it("repo_dir should match repo name for https", async () => {
@@ -245,20 +244,4 @@ describe("git-clone", async () => {
"Cloning https://github.com/michaelbrewer/repo-tests.log to ~/repo-tests.log on branch feat/branch...",
]);
});
it("runs post-clone script", async () => {
const state = await runTerraformApply(import.meta.dir, {
agent_id: "foo",
url: "fake-url",
post_clone_script: "echo 'Post-clone script executed'",
});
const output = await executeScriptInContainer(
state,
"alpine/git",
"sh",
"mkdir -p ~/fake-url && echo 'existing' > ~/fake-url/file.txt",
);
expect(output.stdout).toContain("Running post-clone script...");
expect(output.stdout).toContain("Post-clone script executed");
});
});
-9
View File
@@ -62,12 +62,6 @@ variable "depth" {
default = 0
}
variable "post_clone_script" {
description = "Custom script to run after cloning the repository. Runs always after git clone, even if the repository already exists."
type = string
default = null
}
locals {
# Remove query parameters and fragments from the URL
url = replace(replace(var.url, "/\\?.*/", ""), "/#.*/", "")
@@ -87,8 +81,6 @@ locals {
clone_path = var.base_dir != "" ? join("/", [var.base_dir, local.folder_name]) : join("/", ["~", local.folder_name])
# Construct the web URL
web_url = startswith(local.clone_url, "git@") ? replace(replace(local.clone_url, ":", "/"), "git@", "https://") : local.clone_url
# Encode the post_clone_script for passing to the shell script
encoded_post_clone_script = var.post_clone_script != null ? base64encode(var.post_clone_script) : ""
}
output "repo_dir" {
@@ -128,7 +120,6 @@ resource "coder_script" "git_clone" {
REPO_URL : local.clone_url,
BRANCH_NAME : local.branch_name,
DEPTH = var.depth,
POST_CLONE_SCRIPT : local.encoded_post_clone_script,
})
display_name = "Git Clone"
icon = "/icon/git.svg"
+1 -11
View File
@@ -6,7 +6,6 @@ BRANCH_NAME="${BRANCH_NAME}"
# Expand home if it's specified!
CLONE_PATH="$${CLONE_PATH/#\~/$${HOME}}"
DEPTH="${DEPTH}"
POST_CLONE_SCRIPT="${POST_CLONE_SCRIPT}"
# Check if the variable is empty...
if [ -z "$REPO_URL" ]; then
@@ -53,14 +52,5 @@ if [ -z "$(ls -A "$CLONE_PATH")" ]; then
fi
else
echo "$CLONE_PATH already exists and isn't empty, skipping clone!"
fi
# Run post-clone script if provided
if [ -n "$POST_CLONE_SCRIPT" ]; then
echo "Running post-clone script..."
echo "$POST_CLONE_SCRIPT" | base64 -d > /tmp/post_clone.sh
chmod +x /tmp/post_clone.sh
cd "$CLONE_PATH"
/tmp/post_clone.sh
rm /tmp/post_clone.sh
exit 0
fi
+2 -4
View File
@@ -13,7 +13,7 @@ Run the [Goose](https://block.github.io/goose/) agent in your workspace to gener
```tf
module "goose" {
source = "registry.coder.com/coder/goose/coder"
version = "2.2.1"
version = "2.1.1"
agent_id = coder_agent.example.id
folder = "/home/coder"
install_goose = true
@@ -79,7 +79,7 @@ resource "coder_agent" "main" {
module "goose" {
count = data.coder_workspace.me.start_count
source = "registry.coder.com/coder/goose/coder"
version = "2.2.1"
version = "2.1.1"
agent_id = coder_agent.example.id
folder = "/home/coder"
install_goose = true
@@ -123,6 +123,4 @@ Note: The indentation in the heredoc is preserved, so you can write the YAML nat
## Troubleshooting
By default, this module is configured to run the embedded chat interface as a path-based application. In production, we recommend that you configure a [wildcard access URL](https://coder.com/docs/admin/setup#wildcard-access-url) and set `subdomain = true`. See [here](https://coder.com/docs/tutorials/best-practices/security-best-practices#disable-path-based-apps) for more details.
The module will create log files in the workspace's `~/.goose-module` directory. If you run into any issues, look at them for more information.
+14 -34
View File
@@ -2,7 +2,6 @@ import {
test,
afterEach,
describe,
it,
setDefaultTimeout,
beforeAll,
expect,
@@ -254,41 +253,22 @@ describe("goose", async () => {
expect(prompt.stderr).toContain("No such file or directory");
});
describe("subdomain", async () => {
it("sets AGENTAPI_CHAT_BASE_PATH when false", async () => {
const { id } = await setup({
agentapiMockScript: await loadTestFile(
import.meta.dir,
"agentapi-mock-print-args.js",
),
moduleVariables: {
subdomain: "false",
},
});
await execModuleScript(id);
const agentapiMockOutput = await readFileContainer(id, agentapiStartLog);
expect(agentapiMockOutput).toContain(
"AGENTAPI_CHAT_BASE_PATH=/@default/default.foo/apps/goose/chat",
);
test("subdomain-false", async () => {
const { id } = await setup({
agentapiMockScript: await loadTestFile(
import.meta.dir,
"agentapi-mock-print-args.js",
),
moduleVariables: {
subdomain: "false",
},
});
it("does not set AGENTAPI_CHAT_BASE_PATH when true", async () => {
const { id } = await setup({
agentapiMockScript: await loadTestFile(
import.meta.dir,
"agentapi-mock-print-args.js",
),
moduleVariables: {
subdomain: "true",
},
});
await execModuleScript(id);
await execModuleScript(id);
const agentapiMockOutput = await readFileContainer(id, agentapiStartLog);
expect(agentapiMockOutput).toMatch(/AGENTAPI_CHAT_BASE_PATH=$/m);
});
const agentapiMockOutput = await readFileContainer(id, agentapiStartLog);
expect(agentapiMockOutput).toContain(
"AGENTAPI_CHAT_BASE_PATH=/@default/default.foo/apps/goose/chat",
);
});
});
+3 -5
View File
@@ -63,13 +63,13 @@ variable "install_agentapi" {
variable "agentapi_version" {
type = string
description = "The version of AgentAPI to install."
default = "v0.10.0"
default = "v0.3.3"
}
variable "subdomain" {
type = bool
description = "Whether to use a subdomain for AgentAPI."
default = false
default = true
}
variable "goose_provider" {
@@ -135,12 +135,11 @@ EOT
install_script = file("${path.module}/scripts/install.sh")
start_script = file("${path.module}/scripts/start.sh")
module_dir_name = ".goose-module"
folder = trimsuffix(var.folder, "/")
}
module "agentapi" {
source = "registry.coder.com/coder/agentapi/coder"
version = "1.2.0"
version = "1.1.1"
agent_id = var.agent_id
web_app_slug = local.app_slug
@@ -157,7 +156,6 @@ module "agentapi" {
pre_install_script = var.pre_install_script
post_install_script = var.post_install_script
start_script = local.start_script
folder = local.folder
install_script = <<-EOT
#!/bin/bash
set -o errexit
@@ -10,9 +10,6 @@ tags: [ide, jetbrains, parameter, gateway]
This module adds a JetBrains Gateway Button to open any workspace with a single click.
> [!TIP]
> We recommend using the [Coder Toolbox module](https://registry.coder.com/modules/coder/jetbrains), which offers significant stability and connectivity benefits over Gateway. Reference our [documentation](https://coder.com/docs/user-guides/workspace-access/jetbrains/toolbox) for more information.
JetBrains recommends a minimum of 4 CPU cores and 8GB of RAM.
Consult the [JetBrains documentation](https://www.jetbrains.com/help/idea/prerequisites.html#min_requirements) to confirm other system requirements.
@@ -20,7 +17,7 @@ Consult the [JetBrains documentation](https://www.jetbrains.com/help/idea/prereq
module "jetbrains_gateway" {
count = data.coder_workspace.me.start_count
source = "registry.coder.com/coder/jetbrains-gateway/coder"
version = "1.2.5"
version = "1.2.2"
agent_id = coder_agent.example.id
folder = "/home/coder/example"
jetbrains_ides = ["CL", "GO", "IU", "PY", "WS"]
@@ -38,7 +35,7 @@ module "jetbrains_gateway" {
module "jetbrains_gateway" {
count = data.coder_workspace.me.start_count
source = "registry.coder.com/coder/jetbrains-gateway/coder"
version = "1.2.5"
version = "1.2.2"
agent_id = coder_agent.example.id
folder = "/home/coder/example"
jetbrains_ides = ["GO", "WS"]
@@ -52,7 +49,7 @@ module "jetbrains_gateway" {
module "jetbrains_gateway" {
count = data.coder_workspace.me.start_count
source = "registry.coder.com/coder/jetbrains-gateway/coder"
version = "1.2.5"
version = "1.2.2"
agent_id = coder_agent.example.id
folder = "/home/coder/example"
jetbrains_ides = ["IU", "PY"]
@@ -67,7 +64,7 @@ module "jetbrains_gateway" {
module "jetbrains_gateway" {
count = data.coder_workspace.me.start_count
source = "registry.coder.com/coder/jetbrains-gateway/coder"
version = "1.2.5"
version = "1.2.2"
agent_id = coder_agent.example.id
folder = "/home/coder/example"
jetbrains_ides = ["IU", "PY"]
@@ -92,7 +89,7 @@ module "jetbrains_gateway" {
module "jetbrains_gateway" {
count = data.coder_workspace.me.start_count
source = "registry.coder.com/coder/jetbrains-gateway/coder"
version = "1.2.5"
version = "1.2.2"
agent_id = coder_agent.example.id
folder = "/home/coder/example"
jetbrains_ides = ["GO", "WS"]
@@ -110,7 +107,7 @@ Due to the highest priority of the `ide_download_link` parameter in the `(jetbra
module "jetbrains_gateway" {
count = data.coder_workspace.me.start_count
source = "registry.coder.com/coder/jetbrains-gateway/coder"
version = "1.2.5"
version = "1.2.2"
agent_id = coder_agent.example.id
folder = "/home/coder/example"
jetbrains_ides = ["GO", "WS"]
@@ -20,7 +20,7 @@ describe("jetbrains-gateway", async () => {
folder: "/home/coder",
});
expect(state.outputs.url.value).toBe(
"jetbrains-gateway://connect#type=coder&workspace=default&owner=default&folder=/home/coder&url=https://mydeployment.coder.com&token=$SESSION_TOKEN&ide_product_code=IU&ide_build_number=243.21565.193&ide_download_link=https://download.jetbrains.com/idea/ideaIU-2024.3.tar.gz&agent=",
"jetbrains-gateway://connect#type=coder&workspace=default&owner=default&folder=/home/coder&url=https://mydeployment.coder.com&token=$SESSION_TOKEN&ide_product_code=IU&ide_build_number=243.21565.193&ide_download_link=https://download.jetbrains.com/idea/ideaIU-2024.3.tar.gz&agent_id=foo",
);
const coder_app = state.resources.find(
@@ -40,28 +40,4 @@ describe("jetbrains-gateway", async () => {
});
expect(state.outputs.identifier.value).toBe("IU");
});
it("optionally includes agent when an agent name is provided", async () => {
const state = await runTerraformApply(import.meta.dir, {
agent_id: "foo",
agent_name: "main",
folder: "/home/coder",
});
expect(state.outputs.url.value).toBe(
"jetbrains-gateway://connect#type=coder&workspace=default&owner=default&folder=/home/coder&url=https://mydeployment.coder.com&token=$SESSION_TOKEN&ide_product_code=IU&ide_build_number=243.21565.193&ide_download_link=https://download.jetbrains.com/idea/ideaIU-2024.3.tar.gz&agent=main",
);
});
it("includes the agent parameter even when the provided value is blank", async () => {
const state = await runTerraformApply(import.meta.dir, {
agent_id: "foo",
agent_name: " ",
folder: "/home/coder",
});
expect(state.outputs.url.value).toBe(
"jetbrains-gateway://connect#type=coder&workspace=default&owner=default&folder=/home/coder&url=https://mydeployment.coder.com&token=$SESSION_TOKEN&ide_product_code=IU&ide_build_number=243.21565.193&ide_download_link=https://download.jetbrains.com/idea/ideaIU-2024.3.tar.gz&agent= ",
);
});
});
@@ -30,14 +30,15 @@ variable "agent_id" {
variable "slug" {
type = string
description = "The slug for the coder_app. Allows reusing the module with the same template."
description = "The slug for the coder_app. Allows resuing the module with the same template."
default = "gateway"
}
variable "agent_name" {
type = string
description = "Agent name."
default = ""
description = "Agent name. (unused). Will be removed in a future version"
default = ""
}
variable "folder" {
@@ -347,8 +348,8 @@ resource "coder_app" "gateway" {
local.build_number,
"&ide_download_link=",
local.download_link,
"&agent=",
var.agent_name,
"&agent_id=",
var.agent_id,
])
}
+6 -30
View File
@@ -14,10 +14,9 @@ This module adds JetBrains IDE buttons to launch IDEs directly from the dashboar
module "jetbrains" {
count = data.coder_workspace.me.start_count
source = "registry.coder.com/coder/jetbrains/coder"
version = "1.1.0"
version = "1.0.3"
agent_id = coder_agent.example.id
folder = "/home/coder/project"
# tooltip = "You need to [Install Coder Desktop](https://coder.com/docs/user-guides/desktop#install-coder-desktop) to use this button." # Optional
}
```
@@ -40,7 +39,7 @@ When `default` contains IDE codes, those IDEs are created directly without user
module "jetbrains" {
count = data.coder_workspace.me.start_count
source = "registry.coder.com/coder/jetbrains/coder"
version = "1.1.0"
version = "1.0.3"
agent_id = coder_agent.example.id
folder = "/home/coder/project"
default = ["PY", "IU"] # Pre-configure GoLand and IntelliJ IDEA
@@ -53,7 +52,7 @@ module "jetbrains" {
module "jetbrains" {
count = data.coder_workspace.me.start_count
source = "registry.coder.com/coder/jetbrains/coder"
version = "1.1.0"
version = "1.0.3"
agent_id = coder_agent.example.id
folder = "/home/coder/project"
# Show parameter with limited options
@@ -67,7 +66,7 @@ module "jetbrains" {
module "jetbrains" {
count = data.coder_workspace.me.start_count
source = "registry.coder.com/coder/jetbrains/coder"
version = "1.1.0"
version = "1.0.3"
agent_id = coder_agent.example.id
folder = "/home/coder/project"
default = ["IU", "PY"]
@@ -82,7 +81,7 @@ module "jetbrains" {
module "jetbrains" {
count = data.coder_workspace.me.start_count
source = "registry.coder.com/coder/jetbrains/coder"
version = "1.1.0"
version = "1.0.3"
agent_id = coder_agent.example.id
folder = "/workspace/project"
@@ -108,7 +107,7 @@ module "jetbrains" {
module "jetbrains_pycharm" {
count = data.coder_workspace.me.start_count
source = "registry.coder.com/coder/jetbrains/coder"
version = "1.1.0"
version = "1.0.3"
agent_id = coder_agent.example.id
folder = "/workspace/project"
@@ -120,22 +119,6 @@ module "jetbrains_pycharm" {
}
```
### Custom Tooltip
Add helpful tooltip text that appears when users hover over the IDE app buttons:
```tf
module "jetbrains" {
count = data.coder_workspace.me.start_count
source = "registry.coder.com/coder/jetbrains/coder"
version = "1.1.0"
agent_id = coder_agent.example.id
folder = "/home/coder/project"
default = ["IU", "PY"]
tooltip = "You need to [Install Coder Desktop](https://coder.com/docs/user-guides/desktop#install-coder-desktop) to use this button."
}
```
## Behavior
### Parameter vs Direct Apps
@@ -149,13 +132,6 @@ module "jetbrains" {
- If the API is unreachable (air-gapped environments), the module automatically falls back to build numbers from `ide_config`
- `major_version` and `channel` control which API endpoint is queried (when API access is available)
### Tooltip
- **`tooltip`**: Optional markdown text displayed when hovering over IDE app buttons
- If not specified, no tooltip is shown
- Supports markdown formatting for rich text (bold, italic, links, etc.)
- All IDE apps created by this module will show the same tooltip text
## Supported IDEs
All JetBrains IDEs with remote development capabilities:
@@ -129,34 +129,3 @@ run "app_order_when_default_not_empty" {
error_message = "Expected coder_app order to be set to 10"
}
}
run "tooltip_when_provided" {
command = plan
variables {
agent_id = "foo"
folder = "/home/coder"
default = ["GO"]
tooltip = "You need to [Install Coder Desktop](https://coder.com/docs/user-guides/desktop#install-coder-desktop) to use this button."
}
assert {
condition = anytrue([for app in values(resource.coder_app.jetbrains) : app.tooltip == "You need to [Install Coder Desktop](https://coder.com/docs/user-guides/desktop#install-coder-desktop) to use this button."])
error_message = "Expected coder_app tooltip to be set when provided"
}
}
run "tooltip_null_when_not_provided" {
command = plan
variables {
agent_id = "foo"
folder = "/home/coder"
default = ["GO"]
}
assert {
condition = anytrue([for app in values(resource.coder_app.jetbrains) : app.tooltip == null])
error_message = "Expected coder_app tooltip to be null when not provided"
}
}
@@ -276,36 +276,6 @@ describe("jetbrains", async () => {
);
expect(parameter?.instances[0].attributes.order).toBe(5);
});
it("should set tooltip when specified", async () => {
const state = await runTerraformApply(import.meta.dir, {
agent_id: "foo",
folder: "/home/coder",
default: '["GO"]',
tooltip:
"You need to [Install Coder Desktop](https://coder.com/docs/user-guides/desktop#install-coder-desktop) to use this button.",
});
const coder_app = state.resources.find(
(res) => res.type === "coder_app" && res.name === "jetbrains",
);
expect(coder_app?.instances[0].attributes.tooltip).toBe(
"You need to [Install Coder Desktop](https://coder.com/docs/user-guides/desktop#install-coder-desktop) to use this button.",
);
});
it("should have null tooltip when not specified", async () => {
const state = await runTerraformApply(import.meta.dir, {
agent_id: "foo",
folder: "/home/coder",
default: '["GO"]',
});
const coder_app = state.resources.find(
(res) => res.type === "coder_app" && res.name === "jetbrains",
);
expect(coder_app?.instances[0].attributes.tooltip).toBeNull();
});
});
// URL Generation Tests
-7
View File
@@ -59,12 +59,6 @@ variable "coder_parameter_order" {
default = null
}
variable "tooltip" {
type = string
description = "Markdown text that is displayed when hovering over workspace apps."
default = null
}
variable "major_version" {
type = string
description = "The major version of the IDE. i.e. 2025.1"
@@ -238,7 +232,6 @@ resource "coder_app" "jetbrains" {
external = true
order = var.coder_app_order
group = var.group
tooltip = var.tooltip
url = join("", [
"jetbrains://gateway/coder?&workspace=", # requires 2.6.3+ version of Toolbox
data.coder_workspace.me.name,
+3 -4
View File
@@ -16,7 +16,7 @@ Install the JF CLI and authenticate package managers with Artifactory using OAut
module "jfrog" {
count = data.coder_workspace.me.start_count
source = "registry.coder.com/coder/jfrog-oauth/coder"
version = "1.2.0"
version = "1.1.0"
agent_id = coder_agent.example.id
jfrog_url = "https://example.jfrog.io"
username_field = "username" # If you are using GitHub to login to both Coder and Artifactory, use username_field = "username"
@@ -27,7 +27,6 @@ module "jfrog" {
pypi = ["pypi", "extra-index-pypi"]
docker = ["example-docker-staging.jfrog.io", "example-docker-production.jfrog.io"]
conda = ["conda", "conda-local"]
maven = ["maven", "maven-local"]
}
}
```
@@ -47,7 +46,7 @@ Configure the Python pip package manager to fetch packages from Artifactory whil
module "jfrog" {
count = data.coder_workspace.me.start_count
source = "registry.coder.com/coder/jfrog-oauth/coder"
version = "1.2.0"
version = "1.1.0"
agent_id = coder_agent.example.id
jfrog_url = "https://example.jfrog.io"
username_field = "email"
@@ -76,7 +75,7 @@ The [JFrog extension](https://open-vsx.org/extension/JFrog/jfrog-vscode-extensio
module "jfrog" {
count = data.coder_workspace.me.start_count
source = "registry.coder.com/coder/jfrog-oauth/coder"
version = "1.2.0"
version = "1.1.0"
agent_id = coder_agent.example.id
jfrog_url = "https://example.jfrog.io"
username_field = "username" # If you are using GitHub to login to both Coder and Artifactory, use username_field = "username"
@@ -24,10 +24,12 @@ describe("jfrog-oauth", async () => {
const fakeFrogUrl = "http://localhost:8081";
const user = "default";
testRequiredVariables<TestVariables>(import.meta.dir, {
agent_id: "some-agent-id",
jfrog_url: fakeFrogUrl,
package_managers: "{}",
it("can run apply with required variables", async () => {
testRequiredVariables<TestVariables>(import.meta.dir, {
agent_id: "some-agent-id",
jfrog_url: fakeFrogUrl,
package_managers: "{}",
});
});
it("generates an npmrc with scoped repos", async () => {
@@ -148,38 +150,4 @@ EOF`;
'if [ -z "YES" ]; then\n not_configured conda',
);
});
it("generates a maven settings.xml with multiple repos", async () => {
const state = await runTerraformApply<TestVariables>(import.meta.dir, {
agent_id: "some-agent-id",
jfrog_url: fakeFrogUrl,
package_managers: JSON.stringify({
maven: ["central", "snapshots", "local"],
}),
});
const coderScript = findResourceInstance(state, "coder_script");
expect(coderScript.script).toContain(
'jf mvnc --global --repo-resolve "central"',
);
expect(coderScript.script).toContain("<servers>");
expect(coderScript.script).toContain("<id>central</id>");
expect(coderScript.script).toContain("<id>snapshots</id>");
expect(coderScript.script).toContain("<id>local</id>");
expect(coderScript.script).toContain(
"<url>http://localhost:8081/artifactory/central</url>",
);
expect(coderScript.script).toContain(
"<url>http://localhost:8081/artifactory/snapshots</url>",
);
expect(coderScript.script).toContain(
"<url>http://localhost:8081/artifactory/local</url>",
);
expect(coderScript.script).toContain(
'if [ -z "YES" ]; then\n not_configured maven',
);
});
});
@@ -59,7 +59,6 @@ variable "package_managers" {
pypi = optional(list(string), [])
docker = optional(list(string), [])
conda = optional(list(string), [])
maven = optional(list(string), [])
})
description = <<-EOF
A map of package manager names to their respective artifactory repositories. Unused package managers can be omitted.
@@ -70,7 +69,6 @@ variable "package_managers" {
pypi = ["YOUR_PYPI_REPO_KEY", "ANOTHER_PYPI_REPO_KEY"]
docker = ["YOUR_DOCKER_REPO_KEY", "ANOTHER_DOCKER_REPO_KEY"]
conda = ["YOUR_CONDA_REPO_KEY", "ANOTHER_CONDA_REPO_KEY"]
maven = ["YOUR_MAVEN_REPO_KEY", "ANOTHER_MAVEN_REPO_KEY"]
}
EOF
}
@@ -105,9 +103,6 @@ locals {
conda_conf = templatefile(
"${path.module}/conda.conf.tftpl", merge(local.common_values, { REPOS = var.package_managers.conda })
)
maven_settings = templatefile(
"${path.module}/settings.xml.tftpl", merge(local.common_values, { REPOS = var.package_managers.maven })
)
}
data "coder_workspace" "me" {}
@@ -138,9 +133,6 @@ resource "coder_script" "jfrog" {
HAS_CONDA = length(var.package_managers.conda) == 0 ? "" : "YES"
CONDA_CONF = local.conda_conf
REPOSITORY_CONDA = try(element(var.package_managers.conda, 0), "")
HAS_MAVEN = length(var.package_managers.maven) == 0 ? "" : "YES"
MAVEN_SETTINGS = local.maven_settings
REPOSITORY_MAVEN = try(element(var.package_managers.maven, 0), "")
}
))
run_on_start = true
-14
View File
@@ -94,20 +94,6 @@ EOF
config_complete
fi
# Configure Maven to use the Artifactory "maven" repository.
if [ -z "${HAS_MAVEN}" ]; then
not_configured maven
else
echo "☕ Configuring maven..."
jf mvnc --global --repo-resolve "${REPOSITORY_MAVEN}"
# Create Maven config directory if it doesn't exist
mkdir -p ~/.m2
cat << EOF > ~/.m2/settings.xml
${MAVEN_SETTINGS}
EOF
config_complete
fi
# Install the JFrog vscode extension for code-server.
if [ "${CONFIGURE_CODE_SERVER}" == "true" ]; then
while ! [ -x /tmp/code-server/bin/code-server ]; do
@@ -1,55 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
%{ for REPO in REPOS ~}
<server>
<id>${REPO}</id>
<username>${ARTIFACTORY_USERNAME}</username>
<password>${ARTIFACTORY_ACCESS_TOKEN}</password>
</server>
%{ endfor ~}
</servers>
<profiles>
<profile>
<id>artifactory</id>
<repositories>
%{ for REPO in REPOS ~}
<repository>
<id>${REPO}</id>
<url>${JFROG_URL}/artifactory/${REPO}</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
%{ endfor ~}
</repositories>
<pluginRepositories>
%{ for REPO in REPOS ~}
<pluginRepository>
<id>${REPO}</id>
<url>${JFROG_URL}/artifactory/${REPO}</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
%{ endfor ~}
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>artifactory</activeProfile>
</activeProfiles>
</settings>
+5 -9
View File
@@ -13,7 +13,7 @@ Install the JF CLI and authenticate package managers with Artifactory using Arti
```tf
module "jfrog" {
source = "registry.coder.com/coder/jfrog-token/coder"
version = "1.2.0"
version = "1.1.0"
agent_id = coder_agent.example.id
jfrog_url = "https://XXXX.jfrog.io"
artifactory_access_token = var.artifactory_access_token
@@ -23,7 +23,6 @@ module "jfrog" {
pypi = ["pypi", "extra-index-pypi"]
docker = ["example-docker-staging.jfrog.io", "example-docker-production.jfrog.io"]
conda = ["conda", "conda-local"]
maven = ["maven", "maven-local"]
}
}
```
@@ -42,7 +41,7 @@ For detailed instructions, please see this [guide](https://coder.com/docs/v2/lat
```tf
module "jfrog" {
source = "registry.coder.com/coder/jfrog-token/coder"
version = "1.2.0"
version = "1.1.0"
agent_id = coder_agent.example.id
jfrog_url = "https://YYYY.jfrog.io"
artifactory_access_token = var.artifactory_access_token # An admin access token
@@ -51,19 +50,17 @@ module "jfrog" {
go = ["go-local"]
pypi = ["pypi-local"]
conda = ["conda-local"]
maven = ["maven-local"]
}
}
```
You should now be able to install packages from Artifactory using both the `jf npm`, `jf go`, `jf pip` and `npm`, `go`, `pip`, `conda`, `maven` commands.
You should now be able to install packages from Artifactory using both the `jf npm`, `jf go`, `jf pip` and `npm`, `go`, `pip`, `conda` commands.
```shell
jf npm install prettier
jf go get github.com/golang/example/hello
jf pip install requests
conda install numpy
mvn clean install
```
```shell
@@ -71,7 +68,6 @@ npm install prettier
go get github.com/golang/example/hello
pip install requests
conda install numpy
mvn clean install
```
### Configure code-server with JFrog extension
@@ -81,7 +77,7 @@ The [JFrog extension](https://open-vsx.org/extension/JFrog/jfrog-vscode-extensio
```tf
module "jfrog" {
source = "registry.coder.com/coder/jfrog-token/coder"
version = "1.2.0"
version = "1.1.0"
agent_id = coder_agent.example.id
jfrog_url = "https://XXXX.jfrog.io"
artifactory_access_token = var.artifactory_access_token
@@ -101,7 +97,7 @@ data "coder_workspace" "me" {}
module "jfrog" {
source = "registry.coder.com/coder/jfrog-token/coder"
version = "1.2.0"
version = "1.1.0"
agent_id = coder_agent.example.id
jfrog_url = "https://XXXX.jfrog.io"
artifactory_access_token = var.artifactory_access_token
@@ -55,11 +55,13 @@ describe("jfrog-token", async () => {
const user = "default";
const token = "xxx";
testRequiredVariables<TestVariables>(import.meta.dir, {
agent_id: "some-agent-id",
jfrog_url: fakeFrogUrl,
artifactory_access_token: "XXXX",
package_managers: "{}",
it("can run apply with required variables", async () => {
testRequiredVariables<TestVariables>(import.meta.dir, {
agent_id: "some-agent-id",
jfrog_url: fakeFrogUrl,
artifactory_access_token: "XXXX",
package_managers: "{}",
});
});
it("generates an npmrc with scoped repos", async () => {
@@ -185,39 +187,4 @@ EOF`;
'if [ -z "YES" ]; then\n not_configured conda',
);
});
it("generates a maven settings.xml with multiple repos", async () => {
const state = await runTerraformApply<TestVariables>(import.meta.dir, {
agent_id: "some-agent-id",
jfrog_url: fakeFrogUrl,
artifactory_access_token: "XXXX",
package_managers: JSON.stringify({
maven: ["central", "snapshots", "local"],
}),
});
const coderScript = findResourceInstance(state, "coder_script");
expect(coderScript.script).toContain(
'jf mvnc --global --repo-resolve "central"',
);
expect(coderScript.script).toContain("<servers>");
expect(coderScript.script).toContain("<id>central</id>");
expect(coderScript.script).toContain("<id>snapshots</id>");
expect(coderScript.script).toContain("<id>local</id>");
expect(coderScript.script).toContain(
`<url>${fakeFrogUrl}/artifactory/central</url>`,
);
expect(coderScript.script).toContain(
`<url>${fakeFrogUrl}/artifactory/snapshots</url>`,
);
expect(coderScript.script).toContain(
`<url>${fakeFrogUrl}/artifactory/local</url>`,
);
expect(coderScript.script).toContain(
'if [ -z "YES" ]; then\n not_configured maven',
);
});
});
@@ -92,7 +92,6 @@ variable "package_managers" {
pypi = optional(list(string), [])
docker = optional(list(string), [])
conda = optional(list(string), [])
maven = optional(list(string), [])
})
description = <<-EOF
A map of package manager names to their respective artifactory repositories. Unused package managers can be omitted.
@@ -103,7 +102,6 @@ variable "package_managers" {
pypi = ["YOUR_PYPI_REPO_KEY", "ANOTHER_PYPI_REPO_KEY"]
docker = ["YOUR_DOCKER_REPO_KEY", "ANOTHER_DOCKER_REPO_KEY"]
conda = ["YOUR_CONDA_REPO_KEY", "ANOTHER_CONDA_REPO_KEY"]
maven = ["YOUR_MAVEN_REPO_KEY", "ANOTHER_MAVEN_REPO_KEY"]
}
EOF
}
@@ -138,9 +136,6 @@ locals {
conda_conf = templatefile(
"${path.module}/conda.conf.tftpl", merge(local.common_values, { REPOS = var.package_managers.conda })
)
maven_settings = templatefile(
"${path.module}/settings.xml.tftpl", merge(local.common_values, { REPOS = var.package_managers.maven })
)
}
# Configure the Artifactory provider
@@ -184,9 +179,6 @@ resource "coder_script" "jfrog" {
HAS_CONDA = length(var.package_managers.conda) == 0 ? "" : "YES"
CONDA_CONF = local.conda_conf
REPOSITORY_CONDA = try(element(var.package_managers.conda, 0), "")
HAS_MAVEN = length(var.package_managers.maven) == 0 ? "" : "YES"
MAVEN_SETTINGS = local.maven_settings
REPOSITORY_MAVEN = try(element(var.package_managers.maven, 0), "")
}
))
run_on_start = true
-14
View File
@@ -93,20 +93,6 @@ EOF
config_complete
fi
# Configure Maven to use the Artifactory "maven" repository.
if [ -z "${HAS_MAVEN}" ]; then
not_configured maven
else
echo "☕ Configuring maven..."
jf mvnc --global --repo-resolve "${REPOSITORY_MAVEN}"
# Create Maven config directory if it doesn't exist
mkdir -p ~/.m2
cat << EOF > ~/.m2/settings.xml
${MAVEN_SETTINGS}
EOF
config_complete
fi
# Install the JFrog vscode extension for code-server.
if [ "${CONFIGURE_CODE_SERVER}" == "true" ]; then
while ! [ -x /tmp/code-server/bin/code-server ]; do
@@ -1,55 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
%{ for REPO in REPOS ~}
<server>
<id>${REPO}</id>
<username>${ARTIFACTORY_USERNAME}</username>
<password>${ARTIFACTORY_ACCESS_TOKEN}</password>
</server>
%{ endfor ~}
</servers>
<profiles>
<profile>
<id>artifactory</id>
<repositories>
%{ for REPO in REPOS ~}
<repository>
<id>${REPO}</id>
<url>${JFROG_URL}/artifactory/${REPO}</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
%{ endfor ~}
</repositories>
<pluginRepositories>
%{ for REPO in REPOS ~}
<pluginRepository>
<id>${REPO}</id>
<url>${JFROG_URL}/artifactory/${REPO}</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
%{ endfor ~}
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>artifactory</activeProfile>
</activeProfiles>
</settings>
+2 -3
View File
@@ -14,12 +14,11 @@ Automatically install [KasmVNC](https://kasmweb.com/kasmvnc) in a workspace, and
module "kasmvnc" {
count = data.coder_workspace.me.start_count
source = "registry.coder.com/coder/kasmvnc/coder"
version = "1.2.4"
version = "1.2.2"
agent_id = coder_agent.example.id
desktop_environment = "xfce"
subdomain = true
}
```
> [!IMPORTANT]
> This module only works on workspaces with a pre-installed desktop environment. As an example base image you can use [`codercom/example-desktop`](https://hub.docker.com/r/codercom/example-desktop) image.
> **Note:** This module only works on workspaces with a pre-installed desktop environment. As an example base image you can use `codercom/enterprise-desktop` image.
+8 -9
View File
@@ -60,9 +60,6 @@ install_deb() {
sudo apt-get -o DPkg::Lock::Timeout=300 -qq update
fi
echo "Installing required Perl DateTime module..."
DEBIAN_FRONTEND=noninteractive sudo apt-get -o DPkg::Lock::Timeout=300 install --yes -qq --no-install-recommends --no-install-suggests libdatetime-perl
DEBIAN_FRONTEND=noninteractive sudo apt-get -o DPkg::Lock::Timeout=300 install --yes -qq --no-install-recommends --no-install-suggests "$kasmdeb"
rm "$kasmdeb"
}
@@ -236,17 +233,19 @@ get_http_dir() {
# Check the system configuration path
if [[ -e /etc/kasmvnc/kasmvnc.yaml ]]; then
d=$(grep -E '^\s*httpd_directory:.*$' "/etc/kasmvnc/kasmvnc.yaml" | awk '{print $$2}')
if [[ -n "$d" && -d "$d" ]]; then
httpd_directory=$d
d=($(grep -E "^\s*httpd_directory:.*$" /etc/kasmvnc/kasmvnc.yaml))
# If this grep is successful, it will return:
# httpd_directory: /usr/share/kasmvnc/www
if [[ $${#d[@]} -eq 2 && -d "$${d[1]}" ]]; then
httpd_directory="$${d[1]}"
fi
fi
# Check the home directory for overriding values
if [[ -e "$HOME/.vnc/kasmvnc.yaml" ]]; then
d=$(grep -E '^\s*httpd_directory:.*$' "$HOME/.vnc/kasmvnc.yaml" | awk '{print $$2}')
if [[ -n "$d" && -d "$d" ]]; then
httpd_directory=$d
d=($(grep -E "^\s*httpd_directory:.*$" "$HOME/.vnc/kasmvnc.yaml"))
if [[ $${#d[@]} -eq 2 && -d "$${d[1]}" ]]; then
httpd_directory="$${d[1]}"
fi
fi
echo $httpd_directory
@@ -40,7 +40,7 @@ variable "use_kubeconfig" {
variable "namespace" {
type = string
default = "coder"
default = "default"
description = "The Kubernetes namespace to create workspaces in (must exist prior to creating workspaces). If the Coder host is itself running as a Pod on the same Kubernetes cluster as you are deploying workspaces to, set this to the same namespace."
}
@@ -62,7 +62,7 @@ data "coder_parameter" "cpu" {
display_name = "CPU"
description = "CPU limit (cores)."
default = "2"
icon = "/icon/memory.svg"
icon = "/emojis/1f5a5.png"
mutable = true
validation {
min = 1
@@ -161,8 +161,6 @@ locals {
# ENVBUILDER_GIT_URL and ENVBUILDER_CACHE_REPO will be overridden by the provider
# if the cache repo is enabled.
"ENVBUILDER_GIT_URL" : var.cache_repo == "" ? local.repo_url : "",
# Used for when SSH is an available authentication mechanism for git providers
"ENVBUILDER_GIT_SSH_PRIVATE_KEY_BASE64" : base64encode(try(data.coder_workspace_owner.me.ssh_private_key, "")),
# Use the docker gateway if the access URL is 127.0.0.1
"ENVBUILDER_INIT_SCRIPT" : replace(coder_agent.main.init_script, "/localhost|127\\.0\\.0\\.1/", "host.docker.internal"),
"ENVBUILDER_FALLBACK_IMAGE" : data.coder_parameter.fallback_image.value,
@@ -265,9 +263,8 @@ resource "kubernetes_deployment" "main" {
name = "dev"
image = var.cache_repo == "" ? local.devcontainer_builder_image : envbuilder_cached_image.cached.0.image
image_pull_policy = "Always"
security_context {
privileged = true
}
security_context {}
# Set the environment using cached_image.cached.0.env if the cache repo is enabled.
# Otherwise, use the local.envbuilder_env.
# You could alternatively write the environment variables to a ConfigMap or Secret
@@ -355,22 +352,21 @@ resource "coder_agent" "main" {
# if you don't want to display any information.
# For basic resources, you can use the `coder stat` command.
# If you need more control, you can write your own script.
# Note: May not work on AWS Linux Nodes See: https://github.com/coder/clistat/issues/17
# metadata {
# display_name = "CPU Usage"
# key = "0_cpu_usage"
# script = "coder stat cpu"
# interval = 10
# timeout = 1
# }
# Note: May not work on AWS Linux Nodes
# metadata {
# display_name = "RAM Usage"
# key = "1_ram_usage"
# script = "coder stat mem"
# interval = 10
# timeout = 1
# }
metadata {
display_name = "CPU Usage"
key = "0_cpu_usage"
script = "coder stat cpu"
interval = 10
timeout = 1
}
metadata {
display_name = "RAM Usage"
key = "1_ram_usage"
script = "coder stat mem"
interval = 10
timeout = 1
}
metadata {
display_name = "Workspaces Disk"
@@ -426,14 +422,15 @@ module "code-server" {
# This ensures that the latest non-breaking version of the module gets downloaded, you can also pin the module version to prevent breaking changes in production.
version = "~> 1.0"
agent_id = coder_agent.main.id
order = 1
agent_id = coder_agent.main.id
agent_name = "main"
order = 1
}
# See https://registry.coder.com/modules/coder/jetbrains
module "jetbrains" {
count = data.coder_workspace.me.start_count
source = "registry.coder.com/coder/jetbrains/coder"
source = "registry.coder.com/modules/coder/jetbrains/coder"
version = "~> 1.0"
agent_id = coder_agent.main.id
agent_name = "main"
-2
View File
@@ -19,5 +19,3 @@ participating in LFX CNCF programs, and helping the developer community grow.
## Modules
- **aws-ami-snapshot**: Create and manage AMI snapshots for Coder workspaces with restore capabilities
- [nexus-repository](./modules/nexus-repository/) - Configure package managers to use Sonatype Nexus Repository
- [auto-start-dev-server](modules/auto-start-dev-server/README.md) - Automatically detect and start development servers for various project types
@@ -1,151 +0,0 @@
---
display_name: Auto-Start Dev Servers
description: Automatically detect and start development servers for various project types
icon: ../../../../.icons/auto-dev-server.svg
verified: false
tags: [development, automation, servers]
---
# Auto-Start Development Servers
Automatically detect and start development servers for various project types when a workspace starts. This module scans your workspace for common project structures and starts the appropriate development servers in the background without manual intervention.
```tf
module "auto_start_dev_servers" {
source = "registry.coder.com/mavrickrishi/auto-start-dev-server/coder"
version = "1.0.1"
agent_id = coder_agent.main.id
}
```
## Features
- **Multi-language support**: Detects and starts servers for Node.js, Python (Django/Flask), Ruby (Rails), Java (Spring Boot), Go, PHP, Rust, and .NET projects
- **Smart script prioritization**: Prioritizes `dev` scripts over `start` scripts for better development experience
- **Intelligent frontend detection**: Automatically identifies frontend projects (React, Vue, Angular, Next.js, Nuxt, Svelte, Vite) and prioritizes them for preview apps
- **Devcontainer integration**: Respects custom start commands defined in `.devcontainer/devcontainer.json`
- **Configurable scanning**: Adjustable directory scan depth and project type toggles
- **Non-blocking startup**: Servers start in the background with configurable startup delay
- **Comprehensive logging**: All server output and detection results logged to a central file
- **Smart detection**: Uses project-specific files and configurations to identify project types
- **Integrated live preview**: Automatically creates a preview app for the primary frontend project
## Supported Project Types
| Framework/Language | Detection Files | Start Commands (in priority order) |
| ------------------ | -------------------------------------------- | ----------------------------------------------------- |
| **Node.js/npm** | `package.json` | `npm run dev`, `npm run serve`, `npm start` (or yarn) |
| **Ruby on Rails** | `Gemfile` with rails gem | `bundle exec rails server` |
| **Django** | `manage.py` | `python manage.py runserver` |
| **Flask** | `requirements.txt` with Flask | `python app.py/main.py/run.py` |
| **Spring Boot** | `pom.xml` or `build.gradle` with spring-boot | `mvn spring-boot:run`, `gradle bootRun` |
| **Go** | `go.mod` | `go run main.go` |
| **PHP** | `composer.json` | `php -S 0.0.0.0:8080` |
| **Rust** | `Cargo.toml` | `cargo run` |
| **.NET** | `*.csproj` | `dotnet run` |
## Examples
### Basic Usage
```tf
module "auto_start" {
source = "./modules/auto-start-dev-server"
version = "1.0.1"
agent_id = coder_agent.main.id
}
```
### Advanced Usage
```tf
module "auto_start_dev_servers" {
source = "./modules/auto-start-dev-server"
version = "1.0.1"
agent_id = coder_agent.main.id
# Optional: Configure which project types to detect
enable_npm = true
enable_rails = true
enable_django = true
enable_flask = true
enable_spring_boot = true
enable_go = true
enable_php = true
enable_rust = true
enable_dotnet = true
# Optional: Enable devcontainer.json integration
enable_devcontainer = true
# Optional: Workspace directory to scan (supports environment variables)
workspace_directory = "$HOME"
# Optional: Directory scan depth (1-5)
scan_depth = 2
# Optional: Startup delay in seconds
startup_delay = 10
# Optional: Log file path
log_path = "/tmp/dev-servers.log"
# Optional: Enable automatic preview app (default: true)
enable_preview_app = true
}
```
### Disable Preview App
```tf
module "auto_start" {
source = "./modules/auto-start-dev-server"
version = "1.0.1"
agent_id = coder_agent.main.id
# Disable automatic preview app creation
enable_preview_app = false
}
```
### Selective Project Types
```tf
module "auto_start" {
source = "./modules/auto-start-dev-server"
version = "1.0.1"
agent_id = coder_agent.main.id
# Only enable web development projects
enable_npm = true
enable_rails = true
enable_django = true
enable_flask = true
# Disable other project types
enable_spring_boot = false
enable_go = false
enable_php = false
enable_rust = false
enable_dotnet = false
}
```
### Deep Workspace Scanning
```tf
module "auto_start" {
source = "./modules/auto-start-dev-server"
version = "1.0.1"
agent_id = coder_agent.main.id
workspace_directory = "/workspaces"
scan_depth = 3
startup_delay = 5
log_path = "/var/log/dev-servers.log"
}
```
## License
This module is provided under the same license as the Coder Registry.
@@ -1,109 +0,0 @@
import { describe, expect, it } from "bun:test";
import {
runTerraformApply,
runTerraformInit,
testRequiredVariables,
} from "~test";
describe("auto-start-dev-server", async () => {
await runTerraformInit(import.meta.dir);
testRequiredVariables(import.meta.dir, {
agent_id: "test-agent-123",
});
it("validates scan_depth range", () => {
const t1 = async () => {
await runTerraformApply(import.meta.dir, {
agent_id: "test-agent-123",
scan_depth: "0",
});
};
expect(t1).toThrow("Scan depth must be between 1 and 5");
const t2 = async () => {
await runTerraformApply(import.meta.dir, {
agent_id: "test-agent-123",
scan_depth: "6",
});
};
expect(t2).toThrow("Scan depth must be between 1 and 5");
});
it("applies successfully with default values", async () => {
await runTerraformApply(import.meta.dir, {
agent_id: "test-agent-123",
});
});
it("applies successfully with all project types enabled", async () => {
await runTerraformApply(import.meta.dir, {
agent_id: "test-agent-123",
enable_npm: "true",
enable_rails: "true",
enable_django: "true",
enable_flask: "true",
enable_spring_boot: "true",
enable_go: "true",
enable_php: "true",
enable_rust: "true",
enable_dotnet: "true",
enable_devcontainer: "true",
});
});
it("applies successfully with all project types disabled", async () => {
await runTerraformApply(import.meta.dir, {
agent_id: "test-agent-123",
enable_npm: "false",
enable_rails: "false",
enable_django: "false",
enable_flask: "false",
enable_spring_boot: "false",
enable_go: "false",
enable_php: "false",
enable_rust: "false",
enable_dotnet: "false",
enable_devcontainer: "false",
});
});
it("applies successfully with custom configuration", async () => {
await runTerraformApply(import.meta.dir, {
agent_id: "test-agent-123",
workspace_directory: "/custom/workspace",
scan_depth: "3",
startup_delay: "5",
log_path: "/var/log/custom-dev-servers.log",
display_name: "Custom Dev Server Startup",
});
});
it("validates scan_depth boundary values", async () => {
// Test valid boundary values
await runTerraformApply(import.meta.dir, {
agent_id: "test-agent-123",
scan_depth: "1",
});
await runTerraformApply(import.meta.dir, {
agent_id: "test-agent-123",
scan_depth: "5",
});
});
it("applies with selective project type configuration", async () => {
await runTerraformApply(import.meta.dir, {
agent_id: "test-agent-123",
enable_npm: "true",
enable_django: "true",
enable_go: "true",
enable_rails: "false",
enable_flask: "false",
enable_spring_boot: "false",
enable_php: "false",
enable_rust: "false",
enable_dotnet: "false",
});
});
});
@@ -1,195 +0,0 @@
terraform {
required_version = ">= 1.0"
required_providers {
coder = {
source = "coder/coder"
version = ">= 2.5"
}
}
}
variable "agent_id" {
type = string
description = "The ID of a Coder agent."
}
variable "workspace_directory" {
type = string
description = "The directory to scan for development projects."
default = "$HOME"
}
variable "project_detection" {
type = bool
description = "Enable automatic project detection for all supported types. When true, all project types are detected unless individually disabled. When false, only explicitly enabled project types are detected."
default = true
}
variable "enable_npm" {
type = bool
description = "Enable auto-detection and startup of npm projects."
default = null
}
variable "enable_rails" {
type = bool
description = "Enable auto-detection and startup of Rails projects."
default = null
}
variable "enable_django" {
type = bool
description = "Enable auto-detection and startup of Django projects."
default = null
}
variable "enable_flask" {
type = bool
description = "Enable auto-detection and startup of Flask projects."
default = null
}
variable "enable_spring_boot" {
type = bool
description = "Enable auto-detection and startup of Spring Boot projects."
default = null
}
variable "enable_go" {
type = bool
description = "Enable auto-detection and startup of Go projects."
default = null
}
variable "enable_php" {
type = bool
description = "Enable auto-detection and startup of PHP projects."
default = null
}
variable "enable_rust" {
type = bool
description = "Enable auto-detection and startup of Rust projects."
default = null
}
variable "enable_dotnet" {
type = bool
description = "Enable auto-detection and startup of .NET projects."
default = null
}
variable "enable_devcontainer" {
type = bool
description = "Enable integration with devcontainer.json configuration."
default = null
}
variable "log_path" {
type = string
description = "The path to log development server output to."
default = "/tmp/dev-servers.log"
}
variable "scan_depth" {
type = number
description = "Maximum directory depth to scan for projects (1-5)."
default = 2
validation {
condition = var.scan_depth >= 1 && var.scan_depth <= 5
error_message = "Scan depth must be between 1 and 5."
}
}
variable "startup_delay" {
type = number
description = "Delay in seconds before starting dev servers (allows other setup to complete)."
default = 10
}
variable "display_name" {
type = string
description = "Display name for the auto-start dev server script."
default = "Auto-Start Dev Servers"
}
variable "enable_preview_app" {
type = bool
description = "Enable automatic creation of a preview app for the first detected project."
default = true
}
# Read the detected port from the file written by the script
locals {
detected_port = var.enable_preview_app ? try(tonumber(trimspace(file("/tmp/detected-port.txt"))), 3000) : 3000
# Attempt to read project information for better preview naming
detected_projects = try(jsondecode(file("/tmp/detected-projects.json")), [])
preview_project = length(local.detected_projects) > 0 ? local.detected_projects[0] : null
}
resource "coder_script" "auto_start_dev_server" {
agent_id = var.agent_id
display_name = var.display_name
icon = "/icon/auto-dev-server.svg"
script = templatefile("${path.module}/run.sh", {
WORKSPACE_DIR = var.workspace_directory
ENABLE_NPM = coalesce(var.enable_npm, var.project_detection)
ENABLE_RAILS = coalesce(var.enable_rails, var.project_detection)
ENABLE_DJANGO = coalesce(var.enable_django, var.project_detection)
ENABLE_FLASK = coalesce(var.enable_flask, var.project_detection)
ENABLE_SPRING_BOOT = coalesce(var.enable_spring_boot, var.project_detection)
ENABLE_GO = coalesce(var.enable_go, var.project_detection)
ENABLE_PHP = coalesce(var.enable_php, var.project_detection)
ENABLE_RUST = coalesce(var.enable_rust, var.project_detection)
ENABLE_DOTNET = coalesce(var.enable_dotnet, var.project_detection)
ENABLE_DEVCONTAINER = coalesce(var.enable_devcontainer, var.project_detection)
LOG_PATH = var.log_path
SCAN_DEPTH = var.scan_depth
STARTUP_DELAY = var.startup_delay
})
run_on_start = true
}
# Create preview app for first detected project
resource "coder_app" "preview" {
count = var.enable_preview_app ? 1 : 0
agent_id = var.agent_id
slug = "dev-preview"
display_name = "Live Preview"
url = "http://localhost:${local.detected_port}"
icon = "/icon/auto-dev-server.svg"
subdomain = true
share = "owner"
}
output "log_path" {
value = var.log_path
description = "Path to the log file for dev server output"
}
# Example output values for common port mappings
output "common_ports" {
value = {
nodejs = 3000
rails = 3000
django = 8000
flask = 5000
spring = 8080
go = 8080
php = 8080
rust = 8000
dotnet = 5000
}
description = "Common default ports for different project types"
}
output "preview_url" {
value = var.enable_preview_app ? try(coder_app.preview[0].url, null) : null
description = "URL of the live preview app (if enabled)"
}
output "detected_port" {
value = local.detected_port
description = "Port of the first detected development server"
}
@@ -1,468 +0,0 @@
#!/usr/bin/env bash
set -euo pipefail
# Color codes for output
BOLD='\033[0;1m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
RED='\033[0;31m'
RESET='\033[0m'
echo -e "$${BOLD}🚀 Auto-Start Development Servers$${RESET}"
echo "Workspace Directory: ${WORKSPACE_DIR}"
echo "Log Path: ${LOG_PATH}"
echo "Scan Depth: ${SCAN_DEPTH}"
# Wait for startup delay to allow other setup to complete
if [ "${STARTUP_DELAY}" -gt 0 ]; then
echo -e "$${YELLOW}⏳ Waiting ${STARTUP_DELAY} seconds for system initialization...$${RESET}"
sleep "${STARTUP_DELAY}"
fi
# Initialize log file
echo "=== Auto-Start Dev Servers Log ===" > "${LOG_PATH}"
echo "Started at: $(date)" >> "${LOG_PATH}"
# Initialize detected projects JSON file
DETECTED_PROJECTS_FILE="/tmp/detected-projects.json"
echo '[]' > "$DETECTED_PROJECTS_FILE"
# Initialize detected port file for preview app
DETECTED_PORT_FILE="/tmp/detected-port.txt"
FIRST_PORT_DETECTED=false
FRONTEND_PROJECT_DETECTED=false
# Function to log messages
log_message() {
echo -e "$1"
echo "$1" >> "${LOG_PATH}"
}
# Function to determine if a project is likely a frontend project
is_frontend_project() {
local project_dir="$1"
local project_type="$2"
# Check for common frontend indicators
if [ "$project_type" = "nodejs" ]; then
# Check package.json for frontend dependencies
if [ -f "$project_dir/package.json" ] && command -v jq &> /dev/null; then
# Check for common frontend frameworks
local has_react=$(jq '.dependencies.react // .devDependencies.react // empty' "$project_dir/package.json")
local has_vue=$(jq '.dependencies.vue // .devDependencies.vue // empty' "$project_dir/package.json")
local has_angular=$(jq '.dependencies["@angular/core"] // .devDependencies["@angular/core"] // empty' "$project_dir/package.json")
local has_next=$(jq '.dependencies.next // .devDependencies.next // empty' "$project_dir/package.json")
local has_nuxt=$(jq '.dependencies.nuxt // .devDependencies.nuxt // empty' "$project_dir/package.json")
local has_svelte=$(jq '.dependencies.svelte // .devDependencies.svelte // empty' "$project_dir/package.json")
local has_vite=$(jq '.dependencies.vite // .devDependencies.vite // empty' "$project_dir/package.json")
if [ -n "$has_react" ] || [ -n "$has_vue" ] || [ -n "$has_angular" ] \
|| [ -n "$has_next" ] || [ -n "$has_nuxt" ] || [ -n "$has_svelte" ] \
|| [ -n "$has_vite" ]; then
return 0 # It's a frontend project
fi
fi
# Check for common frontend directory structures
if [ -d "$project_dir/src/components" ] || [ -d "$project_dir/components" ] \
|| [ -d "$project_dir/pages" ] || [ -d "$project_dir/views" ] \
|| [ -f "$project_dir/index.html" ] || [ -f "$project_dir/public/index.html" ]; then
return 0 # It's likely a frontend project
fi
fi
# Rails projects with webpack/webpacker are frontend-enabled
if [ "$project_type" = "rails" ]; then
if [ -f "$project_dir/config/webpacker.yml" ] || [ -f "$project_dir/webpack.config.js" ]; then
return 0
fi
fi
# Django projects with static/templates are frontend-enabled
if [ "$project_type" = "django" ]; then
if [ -d "$project_dir/static" ] || [ -d "$project_dir/templates" ]; then
return 0
fi
fi
return 1 # Not a frontend project
}
# Function to add detected project to JSON
add_detected_project() {
local project_dir="$1"
local project_type="$2"
local port="$3"
local command="$4"
# Check if this is a frontend project
local is_frontend=false
if is_frontend_project "$project_dir" "$project_type"; then
is_frontend=true
log_message "$${BLUE}🎨 Detected frontend project at $project_dir$${RESET}"
fi
# Prioritize frontend projects for the preview app
# Set port if: 1) No port set yet, OR 2) This is frontend and no frontend detected yet
if [ "$FIRST_PORT_DETECTED" = false ] || ([ "$is_frontend" = true ] && [ "$FRONTEND_PROJECT_DETECTED" = false ]); then
echo "$port" > "$DETECTED_PORT_FILE"
FIRST_PORT_DETECTED=true
if [ "$is_frontend" = true ]; then
FRONTEND_PROJECT_DETECTED=true
log_message "$${BLUE}🎯 Frontend project detected - Preview app will be available on port $port$${RESET}"
else
log_message "$${BLUE}🎯 Project detected - Preview app will be available on port $port$${RESET}"
fi
fi
# Create JSON entry for this project
local project_json=$(jq -n \
--arg dir "$project_dir" \
--arg type "$project_type" \
--arg port "$port" \
--arg cmd "$command" \
--arg frontend "$is_frontend" \
'{"directory": $dir, "type": $type, "port": $port, "command": $cmd, "is_frontend": ($frontend == "true")}')
# Append to the detected projects file
jq ". += [$project_json]" "$DETECTED_PROJECTS_FILE" > "$DETECTED_PROJECTS_FILE.tmp" \
&& mv "$DETECTED_PROJECTS_FILE.tmp" "$DETECTED_PROJECTS_FILE"
}
# Function to detect and start npm/yarn projects
detect_npm_projects() {
if [ "${ENABLE_NPM}" != "true" ]; then
return
fi
log_message "$${BLUE}🔍 Scanning for Node.js/npm projects...$${RESET}"
# Use find with maxdepth to respect scan depth
while IFS= read -r -d '' package_json; do
project_dir=$(dirname "$package_json")
log_message "$${GREEN}📦 Found Node.js project: $project_dir$${RESET}"
cd "$project_dir"
# Check package.json for start script
if [ -f "package.json" ] && command -v jq &> /dev/null; then
start_script=$(jq -r '.scripts.start // empty' package.json)
dev_script=$(jq -r '.scripts.dev // empty' package.json)
serve_script=$(jq -r '.scripts.serve // empty' package.json)
# Determine port (check for common port configurations)
local project_port=3000
if [ -n "$dev_script" ] && echo "$dev_script" | grep -q "\-\-port"; then
project_port=$(echo "$dev_script" | grep -oE "\-\-port[[:space:]]+[0-9]+" | grep -oE "[0-9]+$" || echo "3000")
fi
# Use yarn if yarn.lock exists
local pkg_manager="npm"
local cmd_prefix=""
if [ -f "yarn.lock" ] && command -v yarn &> /dev/null; then
pkg_manager="yarn"
cmd_prefix=""
else
cmd_prefix="run "
fi
# Prioritize scripts: 'dev' > 'serve' > 'start' for development environments
if [ -n "$dev_script" ]; then
if [ "$pkg_manager" = "yarn" ]; then
log_message "$${GREEN}🟢 Starting project with 'yarn dev' in $project_dir$${RESET}"
nohup yarn dev >> "${LOG_PATH}" 2>&1 &
add_detected_project "$project_dir" "nodejs" "$project_port" "yarn dev"
else
log_message "$${GREEN}🟢 Starting project with 'npm run dev' in $project_dir$${RESET}"
nohup npm run dev >> "${LOG_PATH}" 2>&1 &
add_detected_project "$project_dir" "nodejs" "$project_port" "npm run dev"
fi
elif [ -n "$serve_script" ]; then
if [ "$pkg_manager" = "yarn" ]; then
log_message "$${GREEN}🟢 Starting project with 'yarn serve' in $project_dir$${RESET}"
nohup yarn serve >> "${LOG_PATH}" 2>&1 &
add_detected_project "$project_dir" "nodejs" "$project_port" "yarn serve"
else
log_message "$${GREEN}🟢 Starting project with 'npm run serve' in $project_dir$${RESET}"
nohup npm run serve >> "${LOG_PATH}" 2>&1 &
add_detected_project "$project_dir" "nodejs" "$project_port" "npm run serve"
fi
elif [ -n "$start_script" ]; then
if [ "$pkg_manager" = "yarn" ]; then
log_message "$${GREEN}🟢 Starting project with 'yarn start' in $project_dir$${RESET}"
nohup yarn start >> "${LOG_PATH}" 2>&1 &
add_detected_project "$project_dir" "nodejs" "$project_port" "yarn start"
else
log_message "$${GREEN}🟢 Starting project with 'npm start' in $project_dir$${RESET}"
nohup npm start >> "${LOG_PATH}" 2>&1 &
add_detected_project "$project_dir" "nodejs" "$project_port" "npm start"
fi
fi
fi
done < <(find "${WORKSPACE_DIR}" -maxdepth "${SCAN_DEPTH}" -name "package.json" -type f -print0)
}
# Function to detect and start Rails projects
detect_rails_projects() {
if [ "${ENABLE_RAILS}" != "true" ]; then
return
fi
log_message "$${BLUE}🔍 Scanning for Ruby on Rails projects...$${RESET}"
while IFS= read -r -d '' gemfile; do
project_dir=$(dirname "$gemfile")
log_message "$${GREEN}💎 Found Rails project: $project_dir$${RESET}"
cd "$project_dir"
# Check if it's actually a Rails project
if grep -q "gem ['\"]rails['\"]" Gemfile 2> /dev/null; then
log_message "$${GREEN}🟢 Starting Rails server in $project_dir$${RESET}"
nohup bundle exec rails server >> "${LOG_PATH}" 2>&1 &
add_detected_project "$project_dir" "rails" "3000" "bundle exec rails server"
fi
done < <(find "${WORKSPACE_DIR}" -maxdepth "${SCAN_DEPTH}" -name "Gemfile" -type f -print0)
}
# Function to detect and start Django projects
detect_django_projects() {
if [ "${ENABLE_DJANGO}" != "true" ]; then
return
fi
log_message "$${BLUE}🔍 Scanning for Django projects...$${RESET}"
while IFS= read -r -d '' manage_py; do
project_dir=$(dirname "$manage_py")
log_message "$${GREEN}🐍 Found Django project: $project_dir$${RESET}"
cd "$project_dir"
log_message "$${GREEN}🟢 Starting Django development server in $project_dir$${RESET}"
nohup python manage.py runserver 0.0.0.0:8000 >> "${LOG_PATH}" 2>&1 &
add_detected_project "$project_dir" "django" "8000" "python manage.py runserver"
done < <(find "${WORKSPACE_DIR}" -maxdepth "${SCAN_DEPTH}" -name "manage.py" -type f -print0)
}
# Function to detect and start Flask projects
detect_flask_projects() {
if [ "${ENABLE_FLASK}" != "true" ]; then
return
fi
log_message "$${BLUE}🔍 Scanning for Flask projects...$${RESET}"
while IFS= read -r -d '' requirements_txt; do
project_dir=$(dirname "$requirements_txt")
# Check if Flask is in requirements
if grep -q -i "flask" "$requirements_txt" 2> /dev/null; then
log_message "$${GREEN}🌶️ Found Flask project: $project_dir$${RESET}"
cd "$project_dir"
# Look for common Flask app files
for app_file in app.py main.py run.py; do
if [ -f "$app_file" ]; then
log_message "$${GREEN}🟢 Starting Flask application ($app_file) in $project_dir$${RESET}"
export FLASK_ENV=development
nohup python "$app_file" >> "${LOG_PATH}" 2>&1 &
add_detected_project "$project_dir" "flask" "5000" "python $app_file"
break
fi
done
fi
done < <(find "${WORKSPACE_DIR}" -maxdepth "${SCAN_DEPTH}" -name "requirements.txt" -type f -print0)
}
# Function to detect and start Spring Boot projects
detect_spring_boot_projects() {
if [ "${ENABLE_SPRING_BOOT}" != "true" ]; then
return
fi
log_message "$${BLUE}🔍 Scanning for Spring Boot projects...$${RESET}"
# Maven projects
while IFS= read -r -d '' pom_xml; do
project_dir=$(dirname "$pom_xml")
# Check if it's a Spring Boot project
if grep -q "spring-boot" "$pom_xml" 2> /dev/null; then
log_message "$${GREEN}🍃 Found Spring Boot Maven project: $project_dir$${RESET}"
cd "$project_dir"
if command -v ./mvnw &> /dev/null; then
log_message "$${GREEN}🟢 Starting Spring Boot application with Maven wrapper in $project_dir$${RESET}"
nohup ./mvnw spring-boot:run >> "${LOG_PATH}" 2>&1 &
add_detected_project "$project_dir" "spring-boot" "8080" "./mvnw spring-boot:run"
elif command -v mvn &> /dev/null; then
log_message "$${GREEN}🟢 Starting Spring Boot application with Maven in $project_dir$${RESET}"
nohup mvn spring-boot:run >> "${LOG_PATH}" 2>&1 &
add_detected_project "$project_dir" "spring-boot" "8080" "mvn spring-boot:run"
fi
fi
done < <(find "${WORKSPACE_DIR}" -maxdepth "${SCAN_DEPTH}" -name "pom.xml" -type f -print0)
# Gradle projects
while IFS= read -r -d '' build_gradle; do
project_dir=$(dirname "$build_gradle")
# Check if it's a Spring Boot project
if grep -q "spring-boot" "$build_gradle" 2> /dev/null; then
log_message "$${GREEN}🍃 Found Spring Boot Gradle project: $project_dir$${RESET}"
cd "$project_dir"
if command -v ./gradlew &> /dev/null; then
log_message "$${GREEN}🟢 Starting Spring Boot application with Gradle wrapper in $project_dir$${RESET}"
nohup ./gradlew bootRun >> "${LOG_PATH}" 2>&1 &
add_detected_project "$project_dir" "spring-boot" "8080" "./gradlew bootRun"
elif command -v gradle &> /dev/null; then
log_message "$${GREEN}🟢 Starting Spring Boot application with Gradle in $project_dir$${RESET}"
nohup gradle bootRun >> "${LOG_PATH}" 2>&1 &
add_detected_project "$project_dir" "spring-boot" "8080" "gradle bootRun"
fi
fi
done < <(find "${WORKSPACE_DIR}" -maxdepth "${SCAN_DEPTH}" -name "build.gradle" -type f -print0)
}
# Function to detect and start Go projects
detect_go_projects() {
if [ "${ENABLE_GO}" != "true" ]; then
return
fi
log_message "$${BLUE}🔍 Scanning for Go projects...$${RESET}"
while IFS= read -r -d '' go_mod; do
project_dir=$(dirname "$go_mod")
log_message "$${GREEN}🐹 Found Go project: $project_dir$${RESET}"
cd "$project_dir"
# Look for main.go or check if there's a main function
if [ -f "main.go" ]; then
log_message "$${GREEN}🟢 Starting Go application in $project_dir$${RESET}"
nohup go run main.go >> "${LOG_PATH}" 2>&1 &
add_detected_project "$project_dir" "go" "8080" "go run main.go"
elif [ -f "cmd/main.go" ]; then
log_message "$${GREEN}🟢 Starting Go application (cmd/main.go) in $project_dir$${RESET}"
nohup go run cmd/main.go >> "${LOG_PATH}" 2>&1 &
add_detected_project "$project_dir" "go" "8080" "go run cmd/main.go"
fi
done < <(find "${WORKSPACE_DIR}" -maxdepth "${SCAN_DEPTH}" -name "go.mod" -type f -print0)
}
# Function to detect and start PHP projects
detect_php_projects() {
if [ "${ENABLE_PHP}" != "true" ]; then
return
fi
log_message "$${BLUE}🔍 Scanning for PHP projects...$${RESET}"
while IFS= read -r -d '' composer_json; do
project_dir=$(dirname "$composer_json")
log_message "$${GREEN}🐘 Found PHP project: $project_dir$${RESET}"
cd "$project_dir"
# Look for common PHP entry points
for entry_file in index.php public/index.php; do
if [ -f "$entry_file" ]; then
log_message "$${GREEN}🟢 Starting PHP development server in $project_dir$${RESET}"
nohup php -S 0.0.0.0:8080 -t "$(dirname "$entry_file")" >> "${LOG_PATH}" 2>&1 &
add_detected_project "$project_dir" "php" "8080" "php -S 0.0.0.0:8080"
break
fi
done
done < <(find "${WORKSPACE_DIR}" -maxdepth "${SCAN_DEPTH}" -name "composer.json" -type f -print0)
}
# Function to detect and start Rust projects
detect_rust_projects() {
if [ "${ENABLE_RUST}" != "true" ]; then
return
fi
log_message "$${BLUE}🔍 Scanning for Rust projects...$${RESET}"
while IFS= read -r -d '' cargo_toml; do
project_dir=$(dirname "$cargo_toml")
log_message "$${GREEN}🦀 Found Rust project: $project_dir$${RESET}"
cd "$project_dir"
# Check if it's a binary project (has [[bin]] or default main.rs)
if grep -q "\[\[bin\]\]" Cargo.toml 2> /dev/null || [ -f "src/main.rs" ]; then
log_message "$${GREEN}🟢 Starting Rust application in $project_dir$${RESET}"
nohup cargo run >> "${LOG_PATH}" 2>&1 &
add_detected_project "$project_dir" "rust" "8000" "cargo run"
fi
done < <(find "${WORKSPACE_DIR}" -maxdepth "${SCAN_DEPTH}" -name "Cargo.toml" -type f -print0)
}
# Function to detect and start .NET projects
detect_dotnet_projects() {
if [ "${ENABLE_DOTNET}" != "true" ]; then
return
fi
log_message "$${BLUE}🔍 Scanning for .NET projects...$${RESET}"
while IFS= read -r -d '' csproj; do
project_dir=$(dirname "$csproj")
log_message "$${GREEN}🔷 Found .NET project: $project_dir$${RESET}"
cd "$project_dir"
log_message "$${GREEN}🟢 Starting .NET application in $project_dir$${RESET}"
nohup dotnet run >> "${LOG_PATH}" 2>&1 &
add_detected_project "$project_dir" "dotnet" "5000" "dotnet run"
done < <(find "${WORKSPACE_DIR}" -maxdepth "${SCAN_DEPTH}" -name "*.csproj" -type f -print0)
}
log_message "Starting auto-detection of development projects..."
# Expand workspace directory if it contains variables
WORKSPACE_DIR=$(eval echo "${WORKSPACE_DIR}")
# Check if workspace directory exists
if [ ! -d "$WORKSPACE_DIR" ]; then
log_message "$${RED}❌ Workspace directory does not exist: $WORKSPACE_DIR$${RESET}"
exit 1
fi
cd "$WORKSPACE_DIR"
# Run all detection functions
detect_npm_projects
detect_rails_projects
detect_django_projects
detect_flask_projects
detect_spring_boot_projects
detect_go_projects
detect_php_projects
detect_rust_projects
detect_dotnet_projects
log_message "$${GREEN}✅ Auto-start scan completed!$${RESET}"
log_message "$${YELLOW}💡 Check running processes with 'ps aux | grep -E \"(npm|rails|python|java|go|php|cargo|dotnet)\"'$${RESET}"
log_message "$${YELLOW}💡 View logs: tail -f ${LOG_PATH}$${RESET}"
# Set default port if no projects were detected
if [ "$FIRST_PORT_DETECTED" = false ]; then
echo "3000" > "$DETECTED_PORT_FILE"
log_message "$${YELLOW}⚠️ No projects detected - Preview app will default to port 3000$${RESET}"
fi
@@ -1,149 +0,0 @@
---
display_name: Nexus Repository
description: Configure package managers to use Sonatype Nexus Repository for Maven, npm, PyPI, and Docker registries.
icon: ../../../../.icons/nexus-repository.svg
verified: false
tags: [integration, nexus-repository, maven, npm, pypi, docker]
---
# Sonatype Nexus Repository
Configure package managers (Maven, npm, Go, PyPI, Docker) to use [Sonatype Nexus Repository](https://help.sonatype.com/en/sonatype-nexus-repository.html) with API token authentication. This module provides secure credential handling, multiple repository support per package manager, and flexible username configuration.
```tf
module "nexus_repository" {
source = "registry.coder.com/mavrickrishi/nexus-repository/coder"
version = "1.0.1"
agent_id = coder_agent.example.id
nexus_url = "https://nexus.example.com"
nexus_password = var.nexus_api_token
package_managers = {
maven = ["maven-public", "maven-releases"]
npm = ["npm-public", "@scoped:npm-private"]
go = ["go-public", "go-private"]
pypi = ["pypi-public", "pypi-private"]
docker = ["docker-public", "docker-private"]
}
}
```
## Requirements
- Nexus Repository Manager 3.x
- Valid API token or user credentials
- Package managers installed on the workspace (Maven, npm, Go, pip, Docker as needed)
> [!NOTE]
> This module configures package managers but does not install them. You need to handle the installation of Maven, npm, Go, Python pip, and Docker yourself.
## Examples
### Configure Maven to use Nexus repositories
```tf
module "nexus_repository" {
source = "registry.coder.com/mavrickrishi/nexus-repository/coder"
version = "1.0.1"
agent_id = coder_agent.example.id
nexus_url = "https://nexus.example.com"
nexus_password = var.nexus_api_token
package_managers = {
maven = ["maven-public", "maven-releases", "maven-snapshots"]
}
}
```
### Configure npm with scoped packages
```tf
module "nexus_repository" {
source = "registry.coder.com/mavrickrishi/nexus-repository/coder"
version = "1.0.1"
agent_id = coder_agent.example.id
nexus_url = "https://nexus.example.com"
nexus_password = var.nexus_api_token
package_managers = {
npm = ["npm-public", "@mycompany:npm-private"]
}
}
```
### Configure Go module proxy
```tf
module "nexus_repository" {
source = "registry.coder.com/mavrickrishi/nexus-repository/coder"
version = "1.0.1"
agent_id = coder_agent.example.id
nexus_url = "https://nexus.example.com"
nexus_password = var.nexus_api_token
package_managers = {
go = ["go-public", "go-private"]
}
}
```
### Configure Python PyPI repositories
```tf
module "nexus_repository" {
source = "registry.coder.com/mavrickrishi/nexus-repository/coder"
version = "1.0.1"
agent_id = coder_agent.example.id
nexus_url = "https://nexus.example.com"
nexus_password = var.nexus_api_token
package_managers = {
pypi = ["pypi-public", "pypi-private"]
}
}
```
### Configure Docker registries
```tf
module "nexus_repository" {
source = "registry.coder.com/mavrickrishi/nexus-repository/coder"
version = "1.0.1"
agent_id = coder_agent.example.id
nexus_url = "https://nexus.example.com"
nexus_password = var.nexus_api_token
package_managers = {
docker = ["docker-public", "docker-private"]
}
}
```
### Use custom username
```tf
module "nexus_repository" {
source = "registry.coder.com/mavrickrishi/nexus-repository/coder"
version = "1.0.1"
agent_id = coder_agent.example.id
nexus_url = "https://nexus.example.com"
nexus_username = "custom-user"
nexus_password = var.nexus_api_token
package_managers = {
maven = ["maven-public"]
}
}
```
### Complete configuration for all package managers
```tf
module "nexus_repository" {
source = "registry.coder.com/mavrickrishi/nexus-repository/coder"
version = "1.0.1"
agent_id = coder_agent.example.id
nexus_url = "https://nexus.example.com"
nexus_password = var.nexus_api_token
package_managers = {
maven = ["maven-public", "maven-releases"]
npm = ["npm-public", "@company:npm-private"]
go = ["go-public", "go-private"]
pypi = ["pypi-public", "pypi-private"]
docker = ["docker-public", "docker-private"]
}
}
```
@@ -1,147 +0,0 @@
import { describe, expect, it } from "bun:test";
import {
executeScriptInContainer,
runTerraformApply,
runTerraformInit,
testRequiredVariables,
} from "~test";
describe("nexus-repository", async () => {
await runTerraformInit(import.meta.dir);
testRequiredVariables(import.meta.dir, {
agent_id: "test-agent",
nexus_url: "https://nexus.example.com",
nexus_password: "test-password",
});
it("configures Maven settings", async () => {
const state = await runTerraformApply(import.meta.dir, {
agent_id: "test-agent",
nexus_url: "https://nexus.example.com",
nexus_password: "test-token",
package_managers: JSON.stringify({
maven: ["maven-public"],
}),
});
const output = await executeScriptInContainer(state, "ubuntu:20.04");
expect(output.stdout.join("\n")).toContain("☕ Configuring Maven...");
expect(output.stdout.join("\n")).toContain("🥳 Configuration complete!");
});
it("configures npm registry", async () => {
const state = await runTerraformApply(import.meta.dir, {
agent_id: "test-agent",
nexus_url: "https://nexus.example.com",
nexus_password: "test-token",
package_managers: JSON.stringify({
npm: ["npm-public"],
}),
});
const output = await executeScriptInContainer(state, "ubuntu:20.04");
expect(output.stdout.join("\n")).toContain("📦 Configuring npm...");
expect(output.stdout.join("\n")).toContain("🥳 Configuration complete!");
});
it("configures PyPI repository", async () => {
const state = await runTerraformApply(import.meta.dir, {
agent_id: "test-agent",
nexus_url: "https://nexus.example.com",
nexus_password: "test-token",
package_managers: JSON.stringify({
pypi: ["pypi-public"],
}),
});
const output = await executeScriptInContainer(state, "ubuntu:20.04");
expect(output.stdout.join("\n")).toContain("🐍 Configuring pip...");
expect(output.stdout.join("\n")).toContain("🥳 Configuration complete!");
});
it("configures multiple package managers", async () => {
const state = await runTerraformApply(import.meta.dir, {
agent_id: "test-agent",
nexus_url: "https://nexus.example.com",
nexus_password: "test-token",
package_managers: JSON.stringify({
maven: ["maven-public"],
npm: ["npm-public"],
pypi: ["pypi-public"],
}),
});
const output = await executeScriptInContainer(state, "ubuntu:20.04");
expect(output.stdout.join("\n")).toContain("☕ Configuring Maven...");
expect(output.stdout.join("\n")).toContain("📦 Configuring npm...");
expect(output.stdout.join("\n")).toContain("🐍 Configuring pip...");
expect(output.stdout.join("\n")).toContain(
"✅ Nexus repository configuration completed!",
);
});
it("handles empty package managers", async () => {
const state = await runTerraformApply(import.meta.dir, {
agent_id: "test-agent",
nexus_url: "https://nexus.example.com",
nexus_password: "test-token",
package_managers: JSON.stringify({}),
});
const output = await executeScriptInContainer(state, "ubuntu:20.04");
expect(output.stdout.join("\n")).toContain(
"🤔 no maven repository is set, skipping maven configuration.",
);
expect(output.stdout.join("\n")).toContain(
"🤔 no npm repository is set, skipping npm configuration.",
);
expect(output.stdout.join("\n")).toContain(
"🤔 no pypi repository is set, skipping pypi configuration.",
);
expect(output.stdout.join("\n")).toContain(
"🤔 no docker repository is set, skipping docker configuration.",
);
});
it("configures Go module proxy", async () => {
const state = await runTerraformApply(import.meta.dir, {
agent_id: "test-agent",
nexus_url: "https://nexus.example.com",
nexus_password: "test-token",
package_managers: JSON.stringify({
go: ["go-public", "go-private"],
}),
});
const output = await executeScriptInContainer(state, "ubuntu:20.04");
expect(output.stdout.join("\n")).toContain("🐹 Configuring Go...");
expect(output.stdout.join("\n")).toContain(
"Go proxy configured via GOPROXY environment variable",
);
expect(output.stdout.join("\n")).toContain("🥳 Configuration complete!");
});
it("validates nexus_url format", async () => {
await expect(
runTerraformApply(import.meta.dir, {
agent_id: "test-agent",
nexus_url: "invalid-url",
nexus_password: "test-token",
package_managers: JSON.stringify({}),
}),
).rejects.toThrow();
});
it("validates username_field values", async () => {
await expect(
runTerraformApply(import.meta.dir, {
agent_id: "test-agent",
nexus_url: "https://nexus.example.com",
nexus_password: "test-token",
username_field: "invalid",
package_managers: JSON.stringify({}),
}),
).rejects.toThrow();
});
});
@@ -1,137 +0,0 @@
terraform {
required_version = ">= 1.0"
required_providers {
coder = {
source = "coder/coder"
version = ">= 2.5"
}
}
}
variable "nexus_url" {
type = string
description = "The base URL of your Nexus repository manager (e.g. https://nexus.example.com)"
validation {
condition = can(regex("^(https|http)://", var.nexus_url))
error_message = "nexus_url must be a valid URL starting with either 'https://' or 'http://'"
}
}
variable "nexus_username" {
type = string
description = "Custom username for Nexus authentication. If not provided, defaults to the Coder username based on the username_field setting"
default = null
}
variable "nexus_password" {
type = string
description = "API token or password for Nexus authentication. This value is sensitive and should be stored securely"
sensitive = true
}
variable "agent_id" {
type = string
description = "The ID of a Coder agent."
}
variable "package_managers" {
type = object({
maven = optional(list(string), [])
npm = optional(list(string), [])
go = optional(list(string), [])
pypi = optional(list(string), [])
docker = optional(list(string), [])
})
default = {
maven = []
npm = []
go = []
pypi = []
docker = []
}
description = <<-EOF
Configuration for package managers. Each key maps to a list of Nexus repository names:
- maven: List of Maven repository names
- npm: List of npm repository names (supports scoped packages with "@scope:repo-name")
- go: List of Go proxy repository names
- pypi: List of PyPI repository names
- docker: List of Docker registry names
Unused package managers can be omitted.
Example:
{
maven = ["maven-public", "maven-releases"]
npm = ["npm-public", "@scoped:npm-private"]
go = ["go-public", "go-private"]
pypi = ["pypi-public", "pypi-private"]
docker = ["docker-public", "docker-private"]
}
EOF
}
variable "username_field" {
type = string
description = "Field to use for username (\"username\" or \"email\"). Defaults to \"username\". Only used when nexus_username is not provided"
default = "username"
validation {
condition = can(regex("^(email|username)$", var.username_field))
error_message = "username_field must be either 'email' or 'username'"
}
}
data "coder_workspace" "me" {}
data "coder_workspace_owner" "me" {}
locals {
username = coalesce(var.nexus_username, var.username_field == "email" ? data.coder_workspace_owner.me.email : data.coder_workspace_owner.me.name)
nexus_host = split("/", replace(replace(var.nexus_url, "https://", ""), "http://", ""))[0]
}
locals {
# Get first repository name or use default
maven_repo = length(var.package_managers.maven) > 0 ? var.package_managers.maven[0] : "maven-public"
npm_repo = length(var.package_managers.npm) > 0 ? var.package_managers.npm[0] : "npm-public"
go_repo = length(var.package_managers.go) > 0 ? var.package_managers.go[0] : "go-public"
pypi_repo = length(var.package_managers.pypi) > 0 ? var.package_managers.pypi[0] : "pypi-public"
npmrc = <<-EOF
registry=${var.nexus_url}/repository/${local.npm_repo}/
//${local.nexus_host}/repository/${local.npm_repo}/:username=${local.username}
//${local.nexus_host}/repository/${local.npm_repo}/:_password=${base64encode(var.nexus_password)}
//${local.nexus_host}/repository/${local.npm_repo}/:always-auth=true
EOF
}
resource "coder_script" "nexus" {
agent_id = var.agent_id
display_name = "nexus-repository"
icon = "/icon/nexus-repository.svg"
script = templatefile("${path.module}/run.sh", {
NEXUS_URL = var.nexus_url
NEXUS_HOST = local.nexus_host
NEXUS_USERNAME = local.username
NEXUS_PASSWORD = var.nexus_password
HAS_MAVEN = length(var.package_managers.maven) == 0 ? "" : "YES"
MAVEN_REPO = local.maven_repo
HAS_NPM = length(var.package_managers.npm) == 0 ? "" : "YES"
NPMRC = local.npmrc
HAS_GO = length(var.package_managers.go) == 0 ? "" : "YES"
GO_REPO = local.go_repo
HAS_PYPI = length(var.package_managers.pypi) == 0 ? "" : "YES"
PYPI_REPO = local.pypi_repo
HAS_DOCKER = length(var.package_managers.docker) == 0 ? "" : "YES"
REGISTER_DOCKER = join("\n ", formatlist("register_docker \"%s\"", var.package_managers.docker))
})
run_on_start = true
}
resource "coder_env" "goproxy" {
count = length(var.package_managers.go) == 0 ? 0 : 1
agent_id = var.agent_id
name = "GOPROXY"
value = join(",", [
for repo in var.package_managers.go :
"https://${local.username}:${var.nexus_password}@${local.nexus_host}/repository/${repo}"
])
}
@@ -1,105 +0,0 @@
#!/usr/bin/env bash
not_configured() {
type=$1
echo "🤔 no $type repository is set, skipping $type configuration."
}
config_complete() {
echo "🥳 Configuration complete!"
}
register_docker() {
repo=$1
echo -n "${NEXUS_PASSWORD}" | docker login "${NEXUS_HOST}/repository/$${repo}" --username "${NEXUS_USERNAME}" --password-stdin
}
echo "🚀 Configuring Nexus repository access..."
# Configure Maven
if [ -n "${HAS_MAVEN}" ]; then
echo "☕ Configuring Maven..."
mkdir -p ~/.m2
cat > ~/.m2/settings.xml << 'EOF'
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0">
<servers>
<server>
<id>nexus</id>
<username>${NEXUS_USERNAME}</username>
<password>${NEXUS_PASSWORD}</password>
</server>
</servers>
<mirrors>
<mirror>
<id>nexus-mirror</id>
<mirrorOf>*</mirrorOf>
<url>${NEXUS_URL}/repository/${MAVEN_REPO}</url>
</mirror>
</mirrors>
</settings>
EOF
config_complete
else
not_configured maven
fi
# Configure npm
if [ -n "${HAS_NPM}" ]; then
echo "📦 Configuring npm..."
cat > ~/.npmrc << 'EOF'
${NPMRC}
EOF
config_complete
else
not_configured npm
fi
# Configure Go
if [ -n "${HAS_GO}" ]; then
echo "🐹 Configuring Go..."
# Go configuration is handled via GOPROXY environment variable
# which is set by the Terraform configuration
echo "Go proxy configured via GOPROXY environment variable"
config_complete
else
not_configured go
fi
# Configure pip
if [ -n "${HAS_PYPI}" ]; then
echo "🐍 Configuring pip..."
mkdir -p ~/.pip
# Create .netrc file for secure credential storage
cat > ~/.netrc << EOF
machine ${NEXUS_HOST}
login ${NEXUS_USERNAME}
password ${NEXUS_PASSWORD}
EOF
chmod 600 ~/.netrc
# Update pip.conf to use index-url without embedded credentials
cat > ~/.pip/pip.conf << 'EOF'
[global]
index-url = https://${NEXUS_HOST}/repository/${PYPI_REPO}/simple
EOF
config_complete
else
not_configured pypi
fi
# Configure Docker
if [ -n "${HAS_DOCKER}" ]; then
if command -v docker > /dev/null 2>&1; then
echo "🐳 Configuring Docker credentials..."
mkdir -p ~/.docker
${REGISTER_DOCKER}
config_complete
else
echo "🤔 Docker is not installed, skipping Docker configuration."
fi
else
not_configured docker
fi
echo "✅ Nexus repository configuration completed!"