Skip to content

fix(ci): validate templates and fix tests#948

Merged
phorcys420 merged 3 commits into
mainfrom
phorcys/fix-templates
Jul 8, 2026
Merged

fix(ci): validate templates and fix tests#948
phorcys420 merged 3 commits into
mainfrom
phorcys/fix-templates

Conversation

@phorcys420

Copy link
Copy Markdown
Member

Problem

Terraform templates (registry/**/templates/**) were never validated by ./scripts/terraform_validate.sh. Only modules were detected and checked, so broken template configs could merge undetected.

Changes

  • scripts/terraform_validate.sh

    • Consumes a new TEMPLATE_CHANGED_FILES env var alongside MODULE_CHANGED_FILES.
    • Changed-file parser now matches (modules|templates)/, so a changed file like registry/coder/templates/docker/main.tf resolves to its template directory and gets terraform validate + the snake_case variable-name check.
    • On a shared-infra change, the whole-registry glob now includes both */modules/* and */templates/*.
    • Skip logic only bails when both module and template change lists are empty.
    • Prunes .terraform/ from the snake_case find. Validating templates runs terraform init, which downloads child modules into .terraform/; without the prune, the check flagged variables in third-party module source (e.g. code-server's machine-settings).
  • .github/workflows/ci.yaml

    • Adds a templates: registry/**/templates/** paths-filter.
    • Passes TEMPLATE_CHANGED_FILES into the "Run Terraform Validate" step.

Validation

  • bash -n and shellcheck --severity=warning (the level CI enforces) are clean.
  • Functionally tested detection for template-only, combined module+template, no-change, and shared-infra scenarios.
  • Ran SHARED_CHANGED=true ./scripts/terraform_validate.sh against the full registry to confirm templates are now exercised. This surfaced pre-existing template breakages (unrelated to this PR) — e.g. agent_name unsupported args and malformed jetbrains module source addresses across several coder/* templates — which are exactly the failures this validation is meant to catch going forward.

Note

This PR only wires up validation; it does not fix the individual broken templates it now surfaces. Those can be addressed in follow-up PRs.

Generated with Mux.

Templates under registry/**/templates/** were previously ignored by the
Terraform validation script. Detect and validate them alongside modules:

- terraform_validate.sh now consumes TEMPLATE_CHANGED_FILES and, on a
  shared-infra change, validates both modules and templates.
- CI adds a 'templates' paths-filter and passes TEMPLATE_CHANGED_FILES to
  the Run Terraform Validate step.
Validating templates runs 'terraform init', which populates .terraform/
with downloaded child modules. The snake_case variable-name check used a
plain 'find ... -name *.tf' that recursed into those directories and
flagged variables in third-party module code (e.g. code-server's
'machine-settings'). Prune .terraform/ so only first-party source is
checked.
@phorcys420 phorcys420 marked this pull request as draft July 8, 2026 13:55
The container-based tests share the ubuntu:20.04 image. Pulling it lazily
on the first test could exceed the 5000ms per-test timeout (the Maven test
timed out while the image downloaded). Add a beforeAll that pulls the image
once up front and route all tests through a shared TEST_IMAGE constant.
@phorcys420 phorcys420 changed the title Validate templates in terraform_validate.sh fix(ci): validate templates and v Jul 8, 2026
@phorcys420 phorcys420 changed the title fix(ci): validate templates and v fix(ci): validate templates and fix tests Jul 8, 2026
@phorcys420 phorcys420 marked this pull request as ready for review July 8, 2026 14:18
@phorcys420 phorcys420 enabled auto-merge (squash) July 8, 2026 14:19
@phorcys420 phorcys420 merged commit c50cf64 into main Jul 8, 2026
6 checks passed
@phorcys420 phorcys420 deleted the phorcys/fix-templates branch July 8, 2026 14:36
phorcys420 added a commit that referenced this pull request Jul 8, 2026
## Problem

Now that `scripts/terraform_validate.sh` validates templates (from
#948), running `terraform validate` across the registry surfaces
pre-existing breakages in **14 `coder/*` templates**. This PR fixes all
of them so they pass validation.

## Fixes

**Unsupported `agent_name` argument** (dominant issue)
- Removed `agent_name` from `code-server` / `windows_rdp` module calls
and from `coder_app` / `coder_env` / `coder_script` /
`coder_agent_instance` resources. Only the `jetbrains` and `filebrowser`
modules actually declare an `agent_name` variable, so those usages are
left intact.

**Invalid `jetbrains` module source**
- `registry.coder.com/modules/coder/jetbrains/coder` (5 components —
invalid) → `registry.coder.com/coder/jetbrains/coder`.

**windows_rdp stray argument**
- Removed `resource_id = null` (no longer a supported argument).

**aws-devcontainer region module**
- Replaced the raw `source =
"https://registry.coder.com/modules/aws-region"` URL with the proper
registry source `registry.coder.com/coder/aws-region/coder` + `version =
"~> 1.0"`.

**gcp-devcontainer agent reference**
- Fixed module calls referencing the non-existent `coder_agent.main`;
the agent in that template is `coder_agent.dev` (count-based), so they
now use `coder_agent.dev[0].id`.

**incus provider schema drift**
- `incus_volume` → `incus_storage_volume`
- `incus_cached_image` → `incus_image` (object-form `source_image = {
remote, name }`)
- Dropped the unsupported `incus_instance_file` resource; the agent
token is now delivered via cloud-init `write_files` (consistent with how
the init script and systemd units are already delivered).
- Moved instance `limits` into `config` (`limits.cpu` / `limits.memory`)
and updated `coder_metadata` references accordingly.

## Validation

All 14 previously-failing templates now pass `terraform validate`:

```
aws-devcontainer, aws-linux, azure-linux, azure-windows, digitalocean-linux,
docker, docker-devcontainer, gcp-devcontainer, gcp-linux, gcp-vm-container,
kubernetes, nomad-docker, scratch, incus  → all Success
```

`terraform fmt` / prettier applied. No `.terraform` artifacts or
lockfiles committed.

> [!NOTE]
> Changes are confined to template `main.tf` files. The incus rework in
particular adapts to the current `lxc/incus` provider schema; the
token-via-cloud-init approach matches the sibling `bpmct/incus-*`
templates.

Generated with [Mux](https://mux.coder.com/).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants