Skip to content

feat: Expose owner and workspace IDs to "coder_workspace" #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions docs/data-sources/workspace.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,12 @@ resource "kubernetes_pod" "dev" {
<!-- schema generated by tfplugindocs -->
## Schema

### Optional

- `id` (String) The ID of this resource.

### Read-Only

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

Expand Down
21 changes: 20 additions & 1 deletion internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ func New() *schema.Provider {
"coder_workspace": {
Description: "Use this data source to get information for the active workspace build.",
ReadContext: func(c context.Context, rd *schema.ResourceData, i interface{}) diag.Diagnostics {
rd.SetId(uuid.NewString())
transition := os.Getenv("CODER_WORKSPACE_TRANSITION")
if transition == "" {
// Default to start!
Expand All @@ -75,11 +74,21 @@ func New() *schema.Provider {
owner = "default"
}
_ = rd.Set("owner", owner)
ownerID := os.Getenv("CODER_WORKSPACE_OWNER_ID")
if ownerID == "" {
ownerID = uuid.Nil.String()
}
_ = rd.Set("owner_id", ownerID)
name := os.Getenv("CODER_WORKSPACE_NAME")
if name == "" {
name = "default"
}
rd.Set("name", name)
id := os.Getenv("CODER_WORKSPACE_ID")
if id == "" {
id = uuid.NewString()
}
rd.SetId(id)
return nil
},
Schema: map[string]*schema.Schema{
Expand All @@ -98,6 +107,16 @@ func New() *schema.Provider {
Computed: true,
Description: "Username of the workspace owner.",
},
"owner_id": {
Type: schema.TypeString,
Computed: true,
Description: "UUID of the workspace owner.",
},
"id": {
Type: schema.TypeString,
Computed: true,
Description: "UUID of the workspace.",
},
"name": {
Type: schema.TypeString,
Computed: true,
Expand Down