🌐 US-Proxy
class="logged-out env-production page-responsive" style="word-wrap: break-word;" >
Skip to content

feat(coderd/templatebuilder): add exampleID->OS map and base template .tf.tmpl files - #26115

Merged
jeremyruppel merged 3 commits into
mainfrom
jeremy/devex-273-be-exampleid-os-map-base-template-tftmpl-files-docker-k8s
Jun 12, 2026
Merged

feat(coderd/templatebuilder): add exampleID->OS map and base template .tf.tmpl files#26115
jeremyruppel merged 3 commits into
mainfrom
jeremy/devex-273-be-exampleid-os-map-base-template-tftmpl-files-docker-k8s

Conversation

@jeremyruppel

@jeremyruppel jeremyruppel commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Add the bundled exampleID -> OS Go map for Docker, Kubernetes, and AWS EC2 Linux base templates. Create .tf.tmpl Go template files for each within coderd/templatebuilder/bases/, along with BaseRenderContext and RenderBaseTemplate rendering helpers.

The .tf.tmpl files are independent copies of the example templates with module blocks (code-server, jetbrains) removed, since the template builder composes modules separately into modules.tf. When ImageOptions is provided, the container image field references the Terraform parameter; otherwise it uses the hardcoded value via Go template whitespace control ({{-).

Golden file snapshot tests verify rendered output stability with an -update flag for regeneration.

Depends on #25909

Note

This PR was authored by Coder Agents on behalf of @jeremyruppel.

@linear-code

linear-code Bot commented Jun 5, 2026

Copy link
Copy Markdown

DEVEX-273

Comment on lines +15 to +16
# Last updated 2023-03-14
# aws ec2 describe-regions | jq -r '[.Regions[].RegionName] | sort'

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I saw this comment and I'm honestly not sure if we should remove it or update it

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Seems like maybe it was meant to replace the hard coded list of aws regions below?

@jeremyruppel
jeremyruppel marked this pull request as ready for review June 5, 2026 21:30
@jeremyruppel
jeremyruppel force-pushed the jeremy/devex-273-be-exampleid-os-map-base-template-tftmpl-files-docker-k8s branch from dc0261b to 4a8bb2a Compare June 9, 2026 22:06
@jeremyruppel
jeremyruppel force-pushed the jeremy/devex-272-be-module-catalog-structure-goembed-wiring branch from 7bead3b to 09a6bf6 Compare June 9, 2026 22:06
Base automatically changed from jeremy/devex-272-be-module-catalog-structure-goembed-wiring to main June 12, 2026 13:40
… .tf.tmpl files

Add the bundled exampleID to OS map for Docker, Kubernetes, and AWS EC2
Linux base templates. Create .tf.tmpl Go template files for each base
template within coderd/templatebuilder/bases/, along with BaseRenderContext
and RenderBaseTemplate rendering helpers.

The .tf.tmpl files are independent copies of the example templates with
module blocks (code-server, jetbrains) removed, since the template builder
composes modules separately into modules.tf. Golden file snapshot tests
verify rendered output stability.

No changes to the existing examples/ directory or create-from-example path.
- Fix image parameter not consumed: when ImageOptions is set, the
  docker_container and kubernetes_deployment image fields now reference
  data.coder_parameter.container_image.value instead of the hardcoded
  Go template variable.
- Validate exampleID in BaseTemplateFS against known base templates,
  returning a clear error for unknown IDs.
- Unexport baseTemplates map to prevent mutation; add BaseTemplateIDs()
  accessor. Store DefaultContext on BaseTemplate struct to consolidate
  the map and switch into a single data source.
- Remove unused BaseOSWindows constant (can be re-added when needed).
- Rename ctx parameter to renderCtx to avoid shadowing context.Context.
- Add comment documenting Variables field as reserved for DEVEX-277.
- Add Kubernetes WithImageOptions test for parity with Docker.
- Add BaseTemplateFS validation test for unknown IDs.
- Add AllBaseTemplatesHaveDefaults test to catch forgotten entries.

@zenithwolf1000 zenithwolf1000 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Potential optimization, but lgtm otherwise

Comment on lines +15 to +16
# Last updated 2023-03-14
# aws ec2 describe-regions | jq -r '[.Regions[].RegionName] | sort'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Seems like maybe it was meant to replace the hard coded list of aws regions below?

Comment thread coderd/templatebuilder/render.go Outdated
…e.json and pre-parse templates

Replace the hardcoded baseTemplates map with data-driven base.json
manifests in each bases/{id}/ directory, following the same pattern
used by the module catalog (catalog.go). Templates are pre-parsed
at first access via sync.OnceValues, so parse errors surface early
instead of at render time.

- Add base.json to docker, kubernetes, and aws-linux base directories
- Parse and validate manifests with DisallowUnknownFields at load time
- Pre-parse all .tf.tmpl files into *template.Template objects
- Change RenderBaseTemplate to use cached templates (no per-call I/O)
- Add bases_internal_test.go with parsing and validation tests
Comment thread coderd/templatebuilder/bases.go Outdated
Comment on lines -28 to -47
// baseTemplates is the canonical map of example IDs to their metadata.
// Maintained manually because TemplateExample.Tags are freeform and
// container/Kubernetes templates carry no OS tag.
// Do not mutate this map; use the exported accessors to read from it.
var baseTemplates = map[string]BaseTemplate{
"docker": {
OS: BaseOSLinux,
DefaultContext: BaseRenderContext{
ContainerImage: "codercom/enterprise-base:ubuntu",
},
},
"kubernetes": {
OS: BaseOSLinux,
DefaultContext: BaseRenderContext{
ContainerImage: "codercom/enterprise-base:ubuntu",
},
},
"aws-linux": {
OS: BaseOSLinux,
},

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

now that we're embedding .tf.tmpls, we also need to embed a little metadata, so that's what the new json files are for

@jeremyruppel
jeremyruppel merged commit 71957a2 into main Jun 12, 2026
29 checks passed
@jeremyruppel
jeremyruppel deleted the jeremy/devex-273-be-exampleid-os-map-base-template-tftmpl-files-docker-k8s branch June 12, 2026 21:12
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 12, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants