Skip to content

Commit bca0f02

Browse files
authored
fix: User resource and service context fixes (#76)
1 parent 3c796d1 commit bca0f02

File tree

9 files changed

+281
-271
lines changed

9 files changed

+281
-271
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @pluralsh/server

docs/resources/user.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ user resource
1818
### Required
1919

2020
- `email` (String) Email address of this user.
21+
22+
### Optional
23+
2124
- `name` (String) Name of this user.
2225

2326
### Read-Only

example/user/main.tf

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,22 @@ resource "plural_user" "spiderman" {
2525
# data "plural_group" "avengers" {
2626
# name = "avengers"
2727
# }
28-
29-
resource "plural_group" "avengers" {
30-
name = "avengers"
31-
description = "avengers group"
32-
}
33-
34-
resource "plural_group_member" "spiderman" {
35-
user_id = plural_user.spiderman.id
36-
group_id = plural_group.avengers.id
37-
}
38-
39-
resource "plural_group_member" "duplicate" {
40-
user_id = plural_user.spiderman.id
41-
group_id = plural_group.avengers.id
42-
}
43-
28+
#
29+
# resource "plural_group" "avengers" {
30+
# name = "avengers"
31+
# description = "avengers group"
32+
# }
33+
#
34+
# resource "plural_group_member" "spiderman" {
35+
# user_id = plural_user.spiderman.id
36+
# group_id = plural_group.avengers.id
37+
# }
38+
#
39+
# resource "plural_group_member" "duplicate" {
40+
# user_id = plural_user.spiderman.id
41+
# group_id = plural_group.avengers.id
42+
# }
43+
#
4444
# resource "plural_rbac" "rbac" {
4545
# service_id = "624bff88-05e3-45f6-bc3b-44708594e28e"
4646
# bindings = {

go.mod

Lines changed: 75 additions & 75 deletions
Large diffs are not rendered by default.

go.sum

Lines changed: 172 additions & 176 deletions
Large diffs are not rendered by default.

internal/datasource/service_context.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ func (d *serviceContextDataSource) Read(ctx context.Context, req datasource.Read
7676
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to read service context, got error: %s", err))
7777
return
7878
}
79+
if response.ServiceContext == nil {
80+
resp.Diagnostics.AddError("Client Error", "Unable to find service context, got no error")
81+
return
82+
}
7983

8084
data.From(response.ServiceContext, ctx, resp.Diagnostics)
8185
resp.Diagnostics.Append(resp.State.Set(ctx, data)...)

internal/model/pr_automation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ func (pra *PRAutomation) From(response *gqlclient.PrAutomationFragment) {
1717
pra.Id = types.StringValue(response.ID)
1818
pra.Name = types.StringValue(response.Name)
1919
pra.Message = types.StringValue(response.Message)
20-
pra.Identifier = types.StringValue(response.Identifier)
20+
pra.Identifier = types.StringPointerValue(response.Identifier)
2121
pra.Title = types.StringValue(response.Title)
2222
}

internal/resource/service_context.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ func (r *ServiceContextResource) Read(ctx context.Context, req resource.ReadRequ
112112
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to read service context, got error: %s", err))
113113
return
114114
}
115+
if response.ServiceContext == nil {
116+
resp.Diagnostics.AddError("Client Error", "Unable to find service context, got no error")
117+
return
118+
}
115119

116120
data.From(response.ServiceContext, ctx, resp.Diagnostics)
117121
resp.Diagnostics.Append(resp.State.Set(ctx, data)...)

internal/resource/user.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ func (r *UserResource) Schema(_ context.Context, _ resource.SchemaRequest, resp
4747
"name": schema.StringAttribute{
4848
Description: "Name of this user.",
4949
MarkdownDescription: "Name of this user.",
50-
Required: true,
50+
Optional: true,
51+
Computed: true,
52+
PlanModifiers: []planmodifier.String{stringplanmodifier.UseStateForUnknown()},
5153
},
5254
"email": schema.StringAttribute{
5355
MarkdownDescription: "Email address of this user.",
@@ -87,13 +89,13 @@ func (r *UserResource) Create(ctx context.Context, req resource.CreateRequest, r
8789
return
8890
}
8991

90-
response, err := r.client.CreateUser(ctx, data.Attributes())
92+
response, err := r.client.UpsertUser(ctx, data.Attributes())
9193
if err != nil {
9294
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to create user, got error: %s", err))
9395
return
9496
}
9597

96-
data.From(response.CreateUser)
98+
data.From(response.UpsertUser)
9799
resp.Diagnostics.Append(resp.State.Set(ctx, data)...)
98100
}
99101

0 commit comments

Comments
 (0)