mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
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:
@@ -174,9 +174,24 @@ func DefaultBaseRenderContext(exampleID string) BaseRenderContext {
|
||||
if err != nil || bases[exampleID] == nil {
|
||||
return BaseRenderContext{}
|
||||
}
|
||||
dc := bases[exampleID].Manifest.DefaultContext
|
||||
base := bases[exampleID]
|
||||
dc := base.Manifest.DefaultContext
|
||||
|
||||
// Populate Variables from manifest defaults so that Go template
|
||||
// rendering succeeds even without caller-supplied values.
|
||||
vars := make(map[string]string, len(base.Manifest.Variables))
|
||||
for _, v := range base.Manifest.Variables {
|
||||
if v.Computed || v.Sensitive {
|
||||
continue
|
||||
}
|
||||
if len(v.Default) > 0 && isSimpleJSONValue(v.Default) {
|
||||
vars[v.Name] = string(v.Default)
|
||||
}
|
||||
}
|
||||
|
||||
return BaseRenderContext{
|
||||
ContainerImage: dc.ContainerImage,
|
||||
Variables: vars,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user