Skip to content

Commit 96993eb

Browse files
authored
fix: provider: coder_workspace_owner: avoid setting null values (#232)
* chore: add coder_workspace_owner to TestProviderEmpty, rm unused struct * fix: do not set null values
1 parent eb43b9f commit 96993eb

File tree

2 files changed

+10
-24
lines changed

2 files changed

+10
-24
lines changed

provider/provider_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ func TestProviderEmpty(t *testing.T) {
3333
provider "coder" {}
3434
data "coder_provisioner" "me" {}
3535
data "coder_workspace" "me" {}
36+
data "coder_workspace_owner" "me" {}
3637
data "coder_external_auth" "git" {
3738
id = "git"
3839
}

provider/workspace_owner.go

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,62 +11,47 @@ import (
1111
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1212
)
1313

14-
type Role struct {
15-
Name string `json:"name"`
16-
DisplayName string `json:"display-name"`
17-
}
18-
1914
func workspaceOwnerDataSource() *schema.Resource {
2015
return &schema.Resource{
2116
Description: "Use this data source to fetch information about the workspace owner.",
2217
ReadContext: func(ctx context.Context, rd *schema.ResourceData, i interface{}) diag.Diagnostics {
23-
if idStr, ok := os.LookupEnv("CODER_WORKSPACE_OWNER_ID"); ok {
18+
if idStr := os.Getenv("CODER_WORKSPACE_OWNER_ID"); idStr != "" {
2419
rd.SetId(idStr)
2520
} else {
2621
rd.SetId(uuid.NewString())
2722
}
2823

29-
if username, ok := os.LookupEnv("CODER_WORKSPACE_OWNER"); ok {
24+
if username := os.Getenv("CODER_WORKSPACE_OWNER"); username != "" {
3025
_ = rd.Set("name", username)
3126
} else {
3227
_ = rd.Set("name", "default")
3328
}
3429

35-
if fullname, ok := os.LookupEnv("CODER_WORKSPACE_OWNER_NAME"); ok {
30+
if fullname := os.Getenv("CODER_WORKSPACE_OWNER_NAME"); fullname != "" {
3631
_ = rd.Set("full_name", fullname)
3732
} else { // compat: field can be blank, fill in default
3833
_ = rd.Set("full_name", "default")
3934
}
4035

41-
if email, ok := os.LookupEnv("CODER_WORKSPACE_OWNER_EMAIL"); ok {
36+
if email := os.Getenv("CODER_WORKSPACE_OWNER_EMAIL"); email != "" {
4237
_ = rd.Set("email", email)
4338
} else {
4439
_ = rd.Set("email", "default@example.com")
4540
}
4641

47-
if sshPubKey, ok := os.LookupEnv("CODER_WORKSPACE_OWNER_SSH_PUBLIC_KEY"); ok {
48-
_ = rd.Set("ssh_public_key", sshPubKey)
49-
}
50-
51-
if sshPrivKey, ok := os.LookupEnv("CODER_WORKSPACE_OWNER_SSH_PRIVATE_KEY"); ok {
52-
_ = rd.Set("ssh_private_key", sshPrivKey)
53-
}
42+
_ = rd.Set("ssh_public_key", os.Getenv("CODER_WORKSPACE_OWNER_SSH_PUBLIC_KEY"))
43+
_ = rd.Set("ssh_private_key", os.Getenv("CODER_WORKSPACE_OWNER_SSH_PRIVATE_KEY"))
5444

5545
var groups []string
5646
if groupsRaw, ok := os.LookupEnv("CODER_WORKSPACE_OWNER_GROUPS"); ok {
5747
if err := json.NewDecoder(strings.NewReader(groupsRaw)).Decode(&groups); err != nil {
5848
return diag.Errorf("invalid user groups: %s", err.Error())
5949
}
60-
_ = rd.Set("groups", groups)
61-
}
62-
63-
if tok, ok := os.LookupEnv("CODER_WORKSPACE_OWNER_SESSION_TOKEN"); ok {
64-
_ = rd.Set("session_token", tok)
6550
}
51+
_ = rd.Set("groups", groups)
6652

67-
if tok, ok := os.LookupEnv("CODER_WORKSPACE_OWNER_OIDC_ACCESS_TOKEN"); ok {
68-
_ = rd.Set("oidc_access_token", tok)
69-
}
53+
_ = rd.Set("session_token", os.Getenv("CODER_WORKSPACE_OWNER_SESSION_TOKEN"))
54+
_ = rd.Set("oidc_access_token", os.Getenv("CODER_WORKSPACE_OWNER_OIDC_ACCESS_TOKEN"))
7055

7156
return nil
7257
},

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy