fix(coderd): declare project_id variable in GCP template builder bases - #27015
Conversation
…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.
aslilac
left a comment
There was a problem hiding this comment.
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
| provider "coder" {} | ||
|
|
||
| variable "project_id" { | ||
| description = "Which Google Compute Project should your workspace live in?" |
There was a problem hiding this comment.
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.
- 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.
Summary
GCP base templates (
gcp-linux,gcp-windows) in the Template Builder had a Terraformvariable "project_id"with no default, but theirbase.jsonmanifests didn't declare it. The UI never prompted for it, so the provisioner import always failed with:Changes
project_idas a required variable in both GCPbase.jsonmanifests{{ .Variables.project_id }}), matching the existing kubernetes patternDefaultBaseRenderContextto supply a"REQUIRED"placeholder for required variables without defaults (previously rendered as<no value>)Implementation plan
Root cause
The GCP base templates contained
variable "project_id" {}(no default = required) in their.tf.tmplfiles, but thebase.jsonmanifests had an emptyvariablesarray. The Template Builder UI (BaseTemplateParametersStep) is data-driven frombase.json, so it never showed a field forproject_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:
base.jsonso the UI prompts for them{{ .Variables.project_id }}) to inject values at compose timevariableblocks from the template since the value is now baked inFiles changed
bases/gcp-linux/base.jsonproject_idas a required variablebases/gcp-windows/base.jsonproject_idas a required variablebases/gcp-linux/main.tf.tmplbases/gcp-windows/main.tf.tmplbases.goDefaultBaseRenderContextsupplies placeholder for required vars without defaultscompose_test.gotemplatebuilder_handler_test.gogcp-windowsspec to expectproject_idvariable