Files
coder/docs/tutorials/testing-templates.md
T
Nick Vigilante f3fd4c4a77 docs: remove invalid --yes flag from coder template version promote (#28084)
## What

Remove the invalid `--yes` flag from the `coder template version
promote` command in the CI/CD publishing example.

## Why

`docs/tutorials/testing-templates.md` documents, in the GitHub Actions
"Promote template version" step:

```
coder template version promote --template=$TEMPLATE_NAME --template-version=... --yes
```

The `promote` subcommand has no `--yes`/confirmation flag, so the
command exits with `unknown flag: --yes` and breaks the documented CI
workflow. This is a golden-path (automation) breaker.

Verified against the generated reference
`docs/reference/cli/templates_versions_promote.md` (flags are only
`--template`, `--template-version`, `-O/--org`), and reproduced against
a live deployment during the runtime drift sweep. The command is
non-interactive, so no confirmation flag is needed.

## Change

Single line: drop ` --yes`.

Linear:
[DOCS-640](https://linear.app/codercom/issue/DOCS-640/docs-remove-invalid-yes-flag-from-coder-template-version-promote)

> This PR was created with AI assistance (Coder Agents).
2026-08-14 09:41:43 -07:00

4.1 KiB

Test and Publish Coder Templates Through CI/CD

November 15, 2024

Overview

This guide demonstrates how to test and publish Coder templates in a Continuous Integration (CI) pipeline using the coder/setup-action. This workflow ensures your templates are validated, tested, and promoted seamlessly.

Prerequisites

  • Install and configure Coder CLI in your environment.
  • Install Terraform CLI in your CI environment.
  • Create a headless user with the user roles and permissions to manage templates and run workspaces.

Creating the headless user

Warning

Creating users with --login-type none is deprecated. For Premium deployments, use service accounts instead. For OSS deployments, use a regular account with password, GitHub, or OIDC authentication.

For Premium deployments, create a service account:

coder users create \
  --username machine-user \
  --service-account

coder tokens create --user machine-user --lifetime 8760h
# Copy the token and store it in a secret in your CI environment with the name `CODER_SESSION_TOKEN`

For OSS deployments, create a regular user:

coder users create \
  --username machine-user \
  --email machine-user@example.com \
  --login-type password

coder tokens create --user machine-user --lifetime 8760h
# Copy the token and store it in a secret in your CI environment with the name `CODER_SESSION_TOKEN`

Example GitHub Action Workflow

This example workflow tests and publishes a template using GitHub Actions.

The workflow:

  1. Validates the Terraform template.
  2. Pushes the template to Coder without activating it.
  3. Tests the template by creating a workspace.
  4. Promotes the template version to active upon successful workspace creation.

Workflow File

Save the following workflow file as .github/workflows/publish-template.yaml in your repository:

name: Test and Publish Coder Template

on:
  push:
    branches:
      - main
  workflow_dispatch:

jobs:
  test-and-publish:
    runs-on: ubuntu-latest
    env:
      TEMPLATE_NAME: "my-template"
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Set up Terraform
        uses: hashicorp/setup-terraform@v2
        with:
          terraform_version: latest

      - name: Set up Coder CLI
        uses: coder/setup-action@v1
        with:
          access_url: "https://coder.example.com"
          coder_session_token: ${{ secrets.CODER_SESSION_TOKEN }}

      - name: Validate Terraform template
        run: terraform validate

      - name: Get short commit SHA to use as template version name
        id: name
        run: echo "version_name=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT"

      - name: Get latest commit title to use as template version description
        id: message
        run:
          echo "pr_title=$(git log --format=%s -n 1 ${{ github.sha }})" >>
          $GITHUB_OUTPUT

      - name: Push template to Coder
        run: |
          coder templates push $TEMPLATE_NAME --activate=false --name ${{ steps.name.outputs.version_name }} --message "${{ steps.message.outputs.pr_title }}" --yes

      - name: Create a test workspace and run some example commands
        run: |
          coder create -t $TEMPLATE_NAME --template-version ${{ steps.name.outputs.version_name }} test-${{ steps.name.outputs.version_name }} --yes
          # run some example commands
          coder ssh test-${{ steps.name.outputs.version_name }} -- make build

      - name: Delete the test workspace
        if: always()
        run: coder delete test-${{ steps.name.outputs.version_name }} --yes

      - name: Promote template version
        if: success()
        run: |
          coder template version promote --template=$TEMPLATE_NAME --template-version=${{ steps.name.outputs.version_name }}