mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix(coderd/templatebuilder): fix archive bundling for nested static files and counted agents (#26901)
Fixes two template builder bugs that caused AWS EC2 (Linux) template imports to fail: 1. **Missing directory entries in tar archive**: `BundleTar` wrote static files with nested paths (e.g. `cloud-init/cloud-config.yaml.tftpl`) without emitting `TypeDir` entries for parent directories. The provisioner's archive extractor requires explicit directory entries and failed with "no such file or directory". 2. **Incorrect agent reference for counted resources**: `ExtractAgentResourceName` returned `dev` for the AWS Linux base template, but the agent uses `count = data.coder_workspace.me.start_count`, so module templates need `coder_agent.dev[0].id`. The function now detects `count`/`for_each` and appends `[0]`. > [!NOTE] > Generated by Coder Agents (on behalf of @jeremyruppel)
This commit is contained in:
@@ -215,7 +215,28 @@ func TestExtractAgentResourceName(t *testing.T) {
|
||||
|
||||
name, err := templatebuilder.ExtractAgentResourceName(rendered)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "dev", name)
|
||||
require.Equal(t, "dev[0]", name, "counted agent should include index")
|
||||
})
|
||||
|
||||
t.Run("CountedAgent", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
hcl := []byte(`resource "coder_agent" "myagent" {
|
||||
count = data.coder_workspace.me.start_count
|
||||
arch = "amd64"
|
||||
}`)
|
||||
name, err := templatebuilder.ExtractAgentResourceName(hcl)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "myagent[0]", name)
|
||||
})
|
||||
|
||||
t.Run("UncountedAgent", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
hcl := []byte(`resource "coder_agent" "main" {
|
||||
arch = "amd64"
|
||||
}`)
|
||||
name, err := templatebuilder.ExtractAgentResourceName(hcl)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "main", name)
|
||||
})
|
||||
|
||||
t.Run("NoAgent", func(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user