Skip to content

Commit 987edd9

Browse files
feat(devcontainer): add optional name attribute to prevent sub-agent name collisions
When using for_each or count with coder_devcontainer, all instances share the same Terraform block name, causing sub-agent name collisions. This change adds an optional 'name' attribute that allows overriding the sub-agent name. When set, this name takes precedence over the Terraform block name. Fixes #503
1 parent e533b99 commit 987edd9

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

provider/devcontainer.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ func devcontainerResource() *schema.Resource {
3232
ForceNew: true,
3333
Required: true,
3434
},
35+
"name": {
36+
Type: schema.TypeString,
37+
Description: "A custom name for the sub-agent. If not set, the Terraform block name is used. Required when using `for_each` or `count` to avoid name collisions.",
38+
ForceNew: true,
39+
Optional: true,
40+
},
3541
"workspace_folder": {
3642
Type: schema.TypeString,
3743
Description: "The workspace folder to for the Dev Container.",

provider/devcontainer_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,32 @@ func TestDevcontainerNoWorkspaceFolder(t *testing.T) {
105105
}},
106106
})
107107
}
108+
109+
func TestDevcontainerWithName(t *testing.T) {
110+
t.Parallel()
111+
112+
resource.Test(t, resource.TestCase{
113+
ProviderFactories: coderFactory(),
114+
IsUnitTest: true,
115+
Steps: []resource.TestStep{{
116+
Config: `
117+
provider "coder" {
118+
}
119+
resource "coder_devcontainer" "example" {
120+
agent_id = "king"
121+
name = "my-custom-name"
122+
workspace_folder = "/workspace"
123+
config_path = "/workspace/devcontainer.json"
124+
}
125+
`,
126+
Check: func(state *terraform.State) error {
127+
require.Len(t, state.Modules, 1)
128+
require.Len(t, state.Modules[0].Resources, 1)
129+
script := state.Modules[0].Resources["coder_devcontainer.example"]
130+
require.NotNil(t, script)
131+
require.Equal(t, "my-custom-name", script.Primary.Attributes["name"])
132+
return nil
133+
},
134+
}},
135+
})
136+
}

0 commit comments

Comments
 (0)