templatebuilder

package
v2.36.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 25, 2026 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BaseExtraFiles

func BaseExtraFiles(exampleID string) map[string][]byte

BaseExtraFiles returns the non-template, non-manifest files embedded in the base template directory (e.g. cloud-init .tftpl files). Returns nil if the base is unknown or has no extra files.

func BasePrerequisites

func BasePrerequisites(exampleID string) string

BasePrerequisites returns the prerequisites section extracted from the base template README. Returns an empty string if the base is unknown or has no prerequisites markers.

func BaseReadme

func BaseReadme(exampleID string) string

BaseReadme returns the full README.md content for a base template. Returns an empty string if the base is unknown or has no README.

func BaseTemplateFS

func BaseTemplateFS(exampleID string) (fs.FS, error)

BaseTemplateFS returns a filesystem rooted at the given base template directory within the embedded bases catalog. Returns an error if exampleID is not a known base template.

func BaseTemplateIDs

func BaseTemplateIDs() []string

BaseTemplateIDs returns the set of known base template example IDs.

func BundleTar

func BundleTar(result *ComposeResult) ([]byte, error)

BundleTar packages the compose result into a tar archive suitable for the Coder file store.

func ClassifyProvisionerError

func ClassifyProvisionerError(jobError string, logs []string) string

ClassifyProvisionerError inspects a provisioner job error and its log lines, returning a user-friendly message for known failure modes. For unrecognized errors, the raw jobError is returned with relevant log context appended so the user can diagnose the failure.

func ExtractAgentResourceName

func ExtractAgentResourceName(hcl []byte) (string, error)

ExtractAgentResourceName finds the coder_agent resource declaration in rendered HCL and returns the reference form to use in module templates. When the agent uses count or for_each, the returned name includes an index suffix (e.g. "dev[0]") so that module templates can reference it as coder_agent.<name>.id. Returns an error unless exactly one coder_agent resource is found; the builder only supports single-agent templates. The input is expected to be rendered output from our own curated base templates, not arbitrary user HCL.

func ExtractPrerequisites

func ExtractPrerequisites(readme string) string

ExtractPrerequisites returns the content between the prerequisites comment markers in a README body. Returns an empty string when either marker is absent.

func ModuleTemplateFS

func ModuleTemplateFS(moduleID string) (fs.FS, error)

ModuleTemplateFS returns an fs.FS rooted at the embedded directory for the given module ID, providing access to its .tf.tmpl file.

func RenderBaseTemplate

func RenderBaseTemplate(exampleID, templatePath string, renderCtx BaseRenderContext) ([]byte, error)

RenderBaseTemplate executes a pre-parsed .tf.tmpl template for the given base, applying the provided render context. Templates are parsed once at first access via sync.OnceValues, so parse errors surface early instead of at render time.

func RenderModuleTemplate

func RenderModuleTemplate(fsys fs.FS, templatePath string, renderCtx ModuleRenderContext) ([]byte, error)

RenderModuleTemplate parses and executes a module .tf.tmpl file from the given filesystem, applying the provided render context.

Types

type BaseDefaultContext

type BaseDefaultContext struct {
	ContainerImage string `json:"container_image,omitempty"`
}

BaseDefaultContext holds default render values stored in base.json.

type BaseManifest

type BaseManifest struct {
	ID             string             `json:"id"`
	DisplayName    string             `json:"display_name"`
	OS             string             `json:"os"`
	DefaultContext BaseDefaultContext `json:"default_context"`
	Variables      []ModuleVariable   `json:"variables"`
}

BaseManifest is the on-disk schema for a base.json file.

type BaseOS

type BaseOS string

BaseOS enumerates operating systems for base template filtering.

const (
	BaseOSLinux   BaseOS = "linux"
	BaseOSWindows BaseOS = "windows"
)

func BaseTemplateOS

func BaseTemplateOS(exampleID string) BaseOS

BaseTemplateOS resolves the OS for a given example ID. Returns empty string if the example is not a known base template.

type BaseRenderContext

type BaseRenderContext struct {
	ContainerImage string
	ImageOptions   []ImageOption
	Variables      map[string]string
}

BaseRenderContext is the data passed to base template .tf.tmpl files.

func DefaultBaseRenderContext

func DefaultBaseRenderContext(exampleID string) BaseRenderContext

DefaultBaseRenderContext returns the render context that produces the canonical default output for a base template.

type ComposeModule

type ComposeModule struct {
	ID string
	// Variables maps variable names to HCL literal values for
	// non-sensitive, non-computed variables.
	Variables map[string]string
}

ComposeModule identifies a module to include and the variable values to render into its module block.

type ComposeRequest

type ComposeRequest struct {
	BaseTemplateID string
	// BaseVariableValues maps base template variable names to their
	// user-supplied values.
	BaseVariableValues map[string]string
	// RegistryURL is the module registry base URL from the deployment
	// config (CODER_TEMPLATE_BUILDER_REGISTRY_URL).
	RegistryURL string
	Modules     []ComposeModule
}

ComposeRequest describes which base template and modules to render.

type ComposeResult

type ComposeResult struct {
	// MainTF is the rendered base template.
	MainTF []byte
	// ModulesTF is the concatenated rendered module blocks. Empty when
	// no modules are selected.
	ModulesTF []byte
	// Readme is the full README.md content from the base template.
	// Empty when the base has no README.
	Readme []byte
	// ExtraFiles holds non-template files from the base directory
	// (e.g. cloud-init .tftpl files). Keys are paths relative to the
	// base directory.
	ExtraFiles map[string][]byte
}

ComposeResult holds the rendered Terraform files ready for bundling.

func Compose

func Compose(req ComposeRequest) (*ComposeResult, error)

Compose renders a base template and selected modules into Terraform source files. It extracts the coder_agent resource name from the rendered base HCL and wires it into each module block.

type ImageOption

type ImageOption struct {
	Name  string
	Value string
}

ImageOption represents a container image choice for base template parameters.

type ModuleManifest

type ModuleManifest struct {
	ID            string           `json:"id"`
	DisplayName   string           `json:"display_name"`
	Description   string           `json:"description"`
	Icon          string           `json:"icon"`
	Category      string           `json:"category"`
	Tags          []string         `json:"tags"`
	CompatibleOS  []string         `json:"compatible_os"`
	ConflictsWith []string         `json:"conflicts_with"`
	Namespace     string           `json:"namespace"`
	PinnedVersion string           `json:"pinned_version"`
	Variables     []ModuleVariable `json:"variables"`
}

ModuleManifest represents a module.json file from the bundled catalog. This is the on-disk schema; codersdk.TemplateBuilderModule is the API type.

func LoadModules

func LoadModules() ([]ModuleManifest, error)

LoadModules returns all module manifests from the embedded catalog. Results are cached after the first call, including errors. Each call returns a fresh slice so callers can filter or sort without corrupting the cache.

func (ModuleManifest) CompatibleWithOS

func (m ModuleManifest) CompatibleWithOS(os string) bool

CompatibleWithOS reports whether the module is compatible with the given OS. Modules with an empty CompatibleOS list are compatible with all platforms.

func (ModuleManifest) ToSDK

ToSDK converts a ModuleManifest to the API response type. PinnedVersion is mapped to Version; tags are not part of the API surface. Computed variables are excluded from the output.

type ModuleRenderContext

type ModuleRenderContext struct {
	// RegistryBase is the module registry URL from the deployment config
	// (CODER_TEMPLATE_BUILDER_REGISTRY_URL).
	RegistryBase string
	// PinnedVersion is the module version from the catalog manifest.
	PinnedVersion string
	// AgentResourceName is the Terraform resource name of the coder_agent
	// declared in the base template (e.g. "main" or "dev").
	AgentResourceName string
	// Variables maps variable names to their HCL expressions.
	Variables map[string]string
}

ModuleRenderContext is the data passed to module .tf.tmpl files.

type ModuleVariable

type ModuleVariable struct {
	Name        string          `json:"name"`
	Type        string          `json:"type"`
	Description string          `json:"description"`
	Default     json.RawMessage `json:"default,omitempty"`
	Required    bool            `json:"required"`
	Sensitive   bool            `json:"sensitive"`
	Computed    bool            `json:"computed"`
}

ModuleVariable represents a variable declaration within a module manifest.

func BaseVariables

func BaseVariables(exampleID string) []ModuleVariable

BaseVariables returns the user-facing variables for a given base template ID. Computed variables are excluded. Returns nil if the base is unknown or has no variables.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL