fix: render base variables into templates instead of tfvars (DEVEX-287) (#26436)

Part of the Template Builder wizard PR stack.

## Problem

The kubernetes base template used Terraform `variable` blocks and
`var.*` references for `use_kubeconfig` and `namespace`, but the
composed tar bundle never included a `.tfvars` file. This caused
`terraform plan` to fail with "required template variables need values:
namespace".

## Fix

Base templates now use Go template variables (`{{ .Variables.* }}`) just
like module templates do. Values are validated, HCL-quoted, and rendered
directly into the output HCL.

Also adds explicit "variable is required" validation to both
`mergeBaseVariables` and `mergeModuleVariables`, replacing the previous
reliance on `missingkey=error` at render time for clearer error
messages.

---
> [!NOTE]
> Generated by Coder Agents on behalf of @jeremyruppel
This commit is contained in:
Jeremy Ruppel
2026-06-23 11:26:38 -04:00
committed by GitHub
parent 2f6f8b9520
commit 7ea5d48296
7 changed files with 126 additions and 61 deletions
+4
View File
@@ -58,6 +58,10 @@ func TestRenderBaseTemplate(t *testing.T) {
renderCtx := templatebuilder.BaseRenderContext{
ContainerImage: "custom/image:latest",
ImageOptions: imageOpts,
Variables: map[string]string{
"namespace": `"test-ns"`,
"use_kubeconfig": "false",
},
}
out, err := templatebuilder.RenderBaseTemplate("kubernetes", "main.tf.tmpl", renderCtx)
require.NoError(t, err)