Skip to content

Commit c6b112d

Browse files
committed
feat: Expose owner and workspace IDs to "coder_workspace"
This allows for simpler persistence of resources that shouldn't be deleted when a user changes their name.
1 parent 7e3d827 commit c6b112d

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

docs/data-sources/workspace.md

+2-4
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,12 @@ resource "kubernetes_pod" "dev" {
2424
<!-- schema generated by tfplugindocs -->
2525
## Schema
2626

27-
### Optional
28-
29-
- `id` (String) The ID of this resource.
30-
3127
### Read-Only
3228

29+
- `id` (String) UUID of the workspace.
3330
- `name` (String) Name of the workspace.
3431
- `owner` (String) Username of the workspace owner.
32+
- `owner_id` (String) UUID of the workspace owner.
3533
- `start_count` (Number) A computed count based on "transition" state. If "start", count will equal 1.
3634
- `transition` (String) Either "start" or "stop". Use this to start/stop resources with "count".
3735

internal/provider/provider.go

+20
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,21 @@ func New() *schema.Provider {
7575
owner = "default"
7676
}
7777
_ = rd.Set("owner", owner)
78+
ownerID := os.Getenv("CODER_WORKSPACE_OWNER_ID")
79+
if ownerID == "" {
80+
ownerID = uuid.Nil.String()
81+
}
82+
_ = rd.Set("owner_id", ownerID)
7883
name := os.Getenv("CODER_WORKSPACE_NAME")
7984
if name == "" {
8085
name = "default"
8186
}
8287
rd.Set("name", name)
88+
id := os.Getenv("CODER_WORKSPACE_ID")
89+
if id == "" {
90+
id = uuid.Nil.String()
91+
}
92+
_ = rd.Set("id", id)
8393
return nil
8494
},
8595
Schema: map[string]*schema.Schema{
@@ -98,6 +108,16 @@ func New() *schema.Provider {
98108
Computed: true,
99109
Description: "Username of the workspace owner.",
100110
},
111+
"owner_id": {
112+
Type: schema.TypeString,
113+
Computed: true,
114+
Description: "UUID of the workspace owner.",
115+
},
116+
"id": {
117+
Type: schema.TypeString,
118+
Computed: true,
119+
Description: "UUID of the workspace.",
120+
},
101121
"name": {
102122
Type: schema.TypeString,
103123
Computed: true,

0 commit comments

Comments
 (0)