Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(coderd): declare project_id variable in GCP template builder bases - #27015

Merged
jeremyruppel merged 2 commits into
mainfrom
fix/template-builder-gcp-project-id
Jul 6, 2026
Merged

fix(coderd): declare project_id variable in GCP template builder bases#27015
jeremyruppel merged 2 commits into
mainfrom
fix/template-builder-gcp-project-id

Conversation

@jeremyruppel

Copy link
Copy Markdown
Contributor

Summary

GCP base templates (gcp-linux, gcp-windows) in the Template Builder had a Terraform variable "project_id" with no default, but their base.json manifests didn't declare it. The UI never prompted for it, so the provisioner import always failed with:

required template variables need values: project_id

Changes

  • Add project_id as a required variable in both GCP base.json manifests
  • Convert templates from raw Terraform variable blocks to Go template injection ({{ .Variables.project_id }}), matching the existing kubernetes pattern
  • Fix DefaultBaseRenderContext to supply a "REQUIRED" placeholder for required variables without defaults (previously rendered as <no value>)
  • Replace duplicate test subtests with proper GCP coverage including a missing-variable error case
Implementation plan

Root cause

The GCP base templates contained variable "project_id" {} (no default = required) in their .tf.tmpl files, but the base.json manifests had an empty variables array. The Template Builder UI (BaseTemplateParametersStep) is data-driven from base.json, so it never showed a field for project_id. The composed Terraform output still contained the required variable, causing the provisioner import to fail.

Fix approach

Follow the pattern established by the kubernetes base template:

  1. Declare variables in base.json so the UI prompts for them
  2. Use Go template syntax ({{ .Variables.project_id }}) to inject values at compose time
  3. Remove raw Terraform variable blocks from the template since the value is now baked in

Files changed

File Change
bases/gcp-linux/base.json Added project_id as a required variable
bases/gcp-windows/base.json Added project_id as a required variable
bases/gcp-linux/main.tf.tmpl Removed Terraform variable block, use Go template injection
bases/gcp-windows/main.tf.tmpl Same
bases.go DefaultBaseRenderContext supplies placeholder for required vars without defaults
compose_test.go Replaced duplicate subtests with proper GCP tests
templatebuilder_handler_test.go Updated gcp-windows spec to expect project_id variable
Golden files Regenerated

🤖 Generated by Coder Agents on behalf of @jeremyruppel

…templates

GCP base templates (gcp-linux, gcp-windows) had a Terraform
variable "project_id" with no default, but the base.json manifests
did not declare it. The Template Builder UI never prompted for it,
so the provisioner import failed with "required template variables
need values: project_id".

Add project_id to both GCP base.json manifests as a required
variable, and convert the templates from raw Terraform variable
blocks to Go template injection (matching the kubernetes pattern).

Also fix DefaultBaseRenderContext to supply a placeholder for
required variables without defaults, preventing <no value> in
rendered output.
@jeremyruppel jeremyruppel changed the title fix(coderd/templatebuilder): declare project_id variable in GCP base templates fix(coderd): declare project_id variable in GCP template builder bases Jul 6, 2026
@jeremyruppel
jeremyruppel marked this pull request as ready for review July 6, 2026 18:21

@aslilac aslilac left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little torn about getting rid of the variable here. I wonder how often people actually change the values of template variables after they've created the template. inlining the value is probably fine, but...

  • is there a way we could just fill in the template variable value and leave the tf as it is?
  • if not, are there any other base templates that need the same treatment? I know our starter kubernetes template also has a few variables

Comment thread coderd/templatebuilder/bases.go Outdated
Comment thread coderd/templatebuilder/bases/gcp-linux/main.tf.tmpl
provider "coder" {}

variable "project_id" {
description = "Which Google Compute Project should your workspace live in?"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still learning and trying to form and idea so please indulge me.

base.json is for the template builder UI, right? It declares the UI fields. The template builder compose takes the user input + main.tf.tmpl and I suppose generates a .tf file that is then used by the provisioner to instantiate a "template version". I can't figure out though how do you link the project_id if you removed it in this file.

Comment thread coderd/templatebuilder/bases.go Outdated
- Remove placeholder injection from DefaultBaseRenderContext. Required
  variables with no default are no longer silently filled with
  "REQUIRED". The compose path validates via mergeBaseVariables.
- Add testRenderContext helper in tests that supplies deterministic
  test values for required variables from base metadata.
- Keep the Terraform variable block in GCP templates with a default
  injected from the Go template. This preserves the variable in the
  rendered Terraform so users can override it after template creation.
- Update compose test assertions to match the new output format.
@jeremyruppel
jeremyruppel merged commit 581f906 into main Jul 6, 2026
28 of 29 checks passed
@jeremyruppel
jeremyruppel deleted the fix/template-builder-gcp-project-id branch July 6, 2026 20:48
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 6, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants