Skip to content

Commit b6966bf

Browse files
feat: add subagent_id attribute to coder_devcontainer resource (#474)
Add computed `subagent_id` attribute to `coder_devcontainer` resource
1 parent c9f205f commit b6966bf

3 files changed

Lines changed: 19 additions & 0 deletions

File tree

docs/resources/devcontainer.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ Define a Dev Container the agent should know of and attempt to autostart.
3030
### Read-Only
3131

3232
- `id` (String) The ID of this resource.
33+
- `subagent_id` (String) The ID of the subagent created for this Dev Container.

provider/devcontainer.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ func devcontainerResource() *schema.Resource {
1717
CreateContext: func(_ context.Context, rd *schema.ResourceData, _ interface{}) diag.Diagnostics {
1818
rd.SetId(uuid.NewString())
1919

20+
if err := rd.Set("subagent_id", uuid.NewString()); err != nil {
21+
return diag.FromErr(err)
22+
}
23+
2024
return nil
2125
},
2226
ReadContext: schema.NoopContext,
@@ -41,6 +45,11 @@ func devcontainerResource() *schema.Resource {
4145
ForceNew: true,
4246
Optional: true,
4347
},
48+
"subagent_id": {
49+
Type: schema.TypeString,
50+
Description: "The ID of the subagent created for this Dev Container.",
51+
Computed: true,
52+
},
4453
},
4554
}
4655
}

provider/devcontainer_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"regexp"
55
"testing"
66

7+
"github.com/google/uuid"
78
"github.com/stretchr/testify/require"
89

910
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
@@ -39,6 +40,10 @@ func TestDevcontainer(t *testing.T) {
3940
} {
4041
require.Equal(t, expected, script.Primary.Attributes[key])
4142
}
43+
subagentID := script.Primary.Attributes["subagent_id"]
44+
require.NotEmpty(t, subagentID)
45+
_, err := uuid.Parse(subagentID)
46+
require.NoError(t, err, "subagent_id should be a valid UUID")
4247
return nil
4348
},
4449
}},
@@ -72,6 +77,10 @@ func TestDevcontainerNoConfigPath(t *testing.T) {
7277
} {
7378
require.Equal(t, expected, script.Primary.Attributes[key])
7479
}
80+
subagentID := script.Primary.Attributes["subagent_id"]
81+
require.NotEmpty(t, subagentID)
82+
_, err := uuid.Parse(subagentID)
83+
require.NoError(t, err, "subagent_id should be a valid UUID")
7584
return nil
7685
},
7786
}},

0 commit comments

Comments
 (0)