diff --git a/docs/data-sources/workspace.md b/docs/data-sources/workspace.md index 311ff59d..e7b20e84 100644 --- a/docs/data-sources/workspace.md +++ b/docs/data-sources/workspace.md @@ -24,14 +24,12 @@ resource "kubernetes_pod" "dev" { ## 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". diff --git a/internal/provider/provider.go b/internal/provider/provider.go index e0cfb47f..15adec70 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -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! @@ -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{ @@ -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,