Skip to content

Commit 70429e2

Browse files
PLAT-7380 Add singlestoredb_user resource and singlestoredb_users datasource (#57)
* PLAT-7380 Add singlestoredb_user resource and singlestoredb_users datasource * Add search by email. Update docs. * Refactor user resource to handle send/revoke invitation and remove user * Update documantation * Fix docs
1 parent 0b6ac27 commit 70429e2

File tree

17 files changed

+1223
-4
lines changed

17 files changed

+1223
-4
lines changed

docs/data-sources/user.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "singlestoredb_user Data Source - terraform-provider-singlestoredb"
4+
subcategory: ""
5+
description: |-
6+
Retrieve a specific user using its ID or email with this data source.
7+
---
8+
9+
# singlestoredb_user (Data Source)
10+
11+
Retrieve a specific user using its ID or email with this data source.
12+
13+
## Example Usage
14+
15+
```terraform
16+
provider "singlestoredb" {
17+
// The SingleStoreDB Terraform provider uses the SINGLESTOREDB_API_KEY environment variable for authentication.
18+
// Please set this environment variable with your SingleStore Management API key.
19+
// You can generate this key from the SingleStore Portal at https://portal.singlestore.com/organizations/org-id/api-keys.
20+
}
21+
22+
data "singlestoredb_user" "this" {
23+
id = "9e481f02-7e4c-478a-98b9-df2c712bed4c" # Replace with the actual ID of the user.
24+
}
25+
26+
output "this_user" {
27+
value = data.singlestoredb_user.this
28+
}
29+
```
30+
31+
<!-- schema generated by tfplugindocs -->
32+
## Schema
33+
34+
### Optional
35+
36+
- `email` (String) The email address of the user.
37+
- `id` (String) The unique identifier of the user.
38+
39+
### Read-Only
40+
41+
- `first_name` (String) The first name of the user.
42+
- `last_name` (String) The last name of the user.
43+
44+

docs/data-sources/users.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "singlestoredb_users Data Source - terraform-provider-singlestoredb"
4+
subcategory: ""
5+
description: |-
6+
This data source provides a list of users that the current user has access to.
7+
---
8+
9+
# singlestoredb_users (Data Source)
10+
11+
This data source provides a list of users that the current user has access to.
12+
13+
## Example Usage
14+
15+
```terraform
16+
provider "singlestoredb" {
17+
// The SingleStoreDB Terraform provider uses the SINGLESTOREDB_API_KEY environment variable for authentication.
18+
// Please set this environment variable with your SingleStore Management API key.
19+
// You can generate this key from the SingleStore Portal at https://portal.singlestore.com/organizations/org-id/api-keys.
20+
}
21+
22+
data "singlestoredb_users" "all" {
23+
}
24+
25+
output "all_users" {
26+
value = data.singlestoredb_users.all
27+
}
28+
```
29+
30+
<!-- schema generated by tfplugindocs -->
31+
## Schema
32+
33+
### Read-Only
34+
35+
- `id` (String) The ID of this resource.
36+
- `users` (Attributes List) (see [below for nested schema](#nestedatt--users))
37+
38+
<a id="nestedatt--users"></a>
39+
### Nested Schema for `users`
40+
41+
Optional:
42+
43+
- `email` (String) The email address of the user.
44+
- `id` (String) The unique identifier of the user.
45+
46+
Read-Only:
47+
48+
- `first_name` (String) The first name of the user.
49+
- `last_name` (String) The last name of the user.
50+
51+

docs/resources/user.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "singlestoredb_user Resource - terraform-provider-singlestoredb"
4+
subcategory: ""
5+
description: |-
6+
The 'apply' action sends a user an invitation to join the organization. The 'destroy' action removes a user from the organization and revokes their pending invitation(s). The 'update' action is not supported for this resource.
7+
---
8+
9+
# singlestoredb_user (Resource)
10+
11+
The 'apply' action sends a user an invitation to join the organization. The 'destroy' action removes a user from the organization and revokes their pending invitation(s). The 'update' action is not supported for this resource.
12+
13+
## Example Usage
14+
15+
```terraform
16+
provider "singlestoredb" {
17+
// The SingleStoreDB Terraform provider uses the SINGLESTOREDB_API_KEY environment variable for authentication.
18+
// Please set this environment variable with your SingleStore Management API key.
19+
// You can generate this key from the SingleStore Portal at https://portal.singlestore.com/organizations/org-id/api-keys.
20+
}
21+
22+
resource "singlestoredb_user" "this" {
23+
24+
}
25+
26+
output "singlestoredb_user_this" {
27+
value = singlestoredb_user.this
28+
}
29+
```
30+
31+
<!-- schema generated by tfplugindocs -->
32+
## Schema
33+
34+
### Required
35+
36+
- `email` (String) The email address of the user.
37+
38+
### Optional
39+
40+
- `teams` (List of String) A list of user teams associated with the invitation.
41+
42+
### Read-Only
43+
44+
- `created_at` (String) The timestamp when the invitation was created, in ISO 8601 format.
45+
- `id` (String) The unique identifier of the invitation.
46+
- `state` (String) The state of the invitation. Possible values are Pending, Accepted, Refused, or Revoked.
47+
- `user_id` (String) The unique identifier of the user. It is set when the user accepts the invitation.
48+
49+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
provider "singlestoredb" {
2+
// The SingleStoreDB Terraform provider uses the SINGLESTOREDB_API_KEY environment variable for authentication.
3+
// Please set this environment variable with your SingleStore Management API key.
4+
// You can generate this key from the SingleStore Portal at https://portal.singlestore.com/organizations/org-id/api-keys.
5+
}
6+
7+
data "singlestoredb_user" "this" {
8+
id = "9e481f02-7e4c-478a-98b9-df2c712bed4c" # Replace with the actual ID of the user.
9+
}
10+
11+
output "this_user" {
12+
value = data.singlestoredb_user.this
13+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
provider "singlestoredb" {
2+
// The SingleStoreDB Terraform provider uses the SINGLESTOREDB_API_KEY environment variable for authentication.
3+
// Please set this environment variable with your SingleStore Management API key.
4+
// You can generate this key from the SingleStore Portal at https://portal.singlestore.com/organizations/org-id/api-keys.
5+
}
6+
7+
data "singlestoredb_users" "all" {
8+
}
9+
10+
output "all_users" {
11+
value = data.singlestoredb_users.all
12+
}

examples/embed.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ var (
2020
WorkspacesGetDataSource = mustRead("data-sources/singlestoredb_workspace/data-source.tf")
2121
WorkspaceGroupsResource = mustRead("resources/singlestoredb_workspace_group/resource.tf")
2222
WorkspacesResource = mustRead("resources/singlestoredb_workspace/resource.tf")
23+
UserGetDataSource = mustRead("data-sources/singlestoredb_user/data-source.tf")
24+
UserResource = mustRead("resources/singlestoredb_user/resource.tf")
25+
UserListDataSource = mustRead("data-sources/singlestoredb_users/data-source.tf")
2326
InvitationsGetDataSource = mustRead("data-sources/singlestoredb_invitation/data-source.tf")
2427
InvitationsListDataSource = mustRead("data-sources/singlestoredb_invitations/data-source.tf")
2528
)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
provider "singlestoredb" {
2+
// The SingleStoreDB Terraform provider uses the SINGLESTOREDB_API_KEY environment variable for authentication.
3+
// Please set this environment variable with your SingleStore Management API key.
4+
// You can generate this key from the SingleStore Portal at https://portal.singlestore.com/organizations/org-id/api-keys.
5+
}
6+
7+
resource "singlestoredb_user" "this" {
8+
9+
}
10+
11+
output "singlestoredb_user_this" {
12+
value = singlestoredb_user.this
13+
}

internal/provider/privateconnections/resource_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ func TestCRUDPrivateConnection(t *testing.T) {
292292
},
293293
{
294294
Config: testutil.UpdatableConfig(examples.PrivateConnectionsResource).
295-
WitPrivateConnectionResource("this")("allow_list", cty.StringVal(updateAllowedList)).
295+
WithPrivateConnectionResource("this")("allow_list", cty.StringVal(updateAllowedList)).
296296
String(),
297297
Check: resource.ComposeAggregateTestCheckFunc(
298298
resource.TestCheckResourceAttr("singlestoredb_private_connection.this", config.IDAttribute, privateConnectionID.String()),
@@ -348,7 +348,7 @@ func TestPrivateConnectionResourceIntegration(t *testing.T) {
348348
},
349349
{
350350
Config: testutil.UpdatableConfig(examples.PrivateConnectionsResource).
351-
WitPrivateConnectionResource("this")("allow_list", cty.StringVal(updateAllowedList)).
351+
WithPrivateConnectionResource("this")("allow_list", cty.StringVal(updateAllowedList)).
352352
String(),
353353
Check: resource.ComposeAggregateTestCheckFunc(
354354
resource.TestCheckResourceAttrSet("singlestoredb_private_connection.this", config.IDAttribute),

internal/provider/provider.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/singlestore-labs/terraform-provider-singlestoredb/internal/provider/privateconnections"
1919
"github.com/singlestore-labs/terraform-provider-singlestoredb/internal/provider/regions"
2020
regions_v2 "github.com/singlestore-labs/terraform-provider-singlestoredb/internal/provider/regionsv2"
21+
"github.com/singlestore-labs/terraform-provider-singlestoredb/internal/provider/users"
2122
"github.com/singlestore-labs/terraform-provider-singlestoredb/internal/provider/util"
2223
"github.com/singlestore-labs/terraform-provider-singlestoredb/internal/provider/workspacegroups"
2324
"github.com/singlestore-labs/terraform-provider-singlestoredb/internal/provider/workspaces"
@@ -163,6 +164,8 @@ func (p *singlestoreProvider) DataSources(_ context.Context) []func() datasource
163164
workspaces.NewDataSourceGet,
164165
privateconnections.NewDataSourceList,
165166
privateconnections.NewDataSourceGet,
167+
users.NewDataSourceGet,
168+
users.NewDataSourceList,
166169
invitations.NewDataSourceList,
167170
invitations.NewDataSourceGet,
168171
}
@@ -174,6 +177,7 @@ func (p *singlestoreProvider) Resources(_ context.Context) []func() resource.Res
174177
workspacegroups.NewResource,
175178
workspaces.NewResource,
176179
privateconnections.NewResource,
180+
users.NewResource,
177181
}
178182
}
179183

internal/provider/testutil/updatableconfig.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/singlestore-labs/terraform-provider-singlestoredb/internal/provider/config"
1010
"github.com/singlestore-labs/terraform-provider-singlestoredb/internal/provider/invitations"
1111
"github.com/singlestore-labs/terraform-provider-singlestoredb/internal/provider/privateconnections"
12+
"github.com/singlestore-labs/terraform-provider-singlestoredb/internal/provider/users"
1213
"github.com/singlestore-labs/terraform-provider-singlestoredb/internal/provider/workspacegroups"
1314
"github.com/singlestore-labs/terraform-provider-singlestoredb/internal/provider/workspaces"
1415
"github.com/zclconf/go-cty/cty"
@@ -29,6 +30,14 @@ func (uc UpdatableConfig) WithPrivateConnectionListDataSource(privateConnectionL
2930
return withAttribute(uc, config.DataSourceTypeName, []string{dataSourceTypeName(privateconnections.DataSourceListName), privateConnectionListName})
3031
}
3132

33+
func (uc UpdatableConfig) WithUserGetDataSource(userName string) AttributeSetter {
34+
return withAttribute(uc, config.DataSourceTypeName, []string{dataSourceTypeName(users.DataSourceGetName), userName})
35+
}
36+
37+
func (uc UpdatableConfig) WithUserListDataSource(userListName string) AttributeSetter {
38+
return withAttribute(uc, config.DataSourceTypeName, []string{dataSourceTypeName(users.DataSourceListName), userListName})
39+
}
40+
3241
func (uc UpdatableConfig) WithWorkspaceGroupGetDataSource(workspaceGroupName string) AttributeSetter {
3342
return withAttribute(uc, config.DataSourceTypeName, []string{dataSourceTypeName(workspacegroups.DataSourceGetName), workspaceGroupName})
3443
}
@@ -49,10 +58,14 @@ func (uc UpdatableConfig) WithWorkspaceGroupResource(workspaceGroupName string)
4958
return withAttribute(uc, config.ResourceTypeName, []string{resourceTypeName(workspacegroups.ResourceName), workspaceGroupName})
5059
}
5160

52-
func (uc UpdatableConfig) WitPrivateConnectionResource(privateConnectionName string) AttributeSetter {
61+
func (uc UpdatableConfig) WithPrivateConnectionResource(privateConnectionName string) AttributeSetter {
5362
return withAttribute(uc, config.ResourceTypeName, []string{resourceTypeName(privateconnections.ResourceName), privateConnectionName})
5463
}
5564

65+
func (uc UpdatableConfig) WithUserResource(userName string) AttributeSetter {
66+
return withAttribute(uc, config.ResourceTypeName, []string{resourceTypeName(users.ResourceName), userName})
67+
}
68+
5669
func (uc UpdatableConfig) WithInvitationGetDataSource(invitationName string) AttributeSetter {
5770
return withAttribute(uc, config.DataSourceTypeName, []string{dataSourceTypeName(invitations.DataSourceGetName), invitationName})
5871
}

0 commit comments

Comments
 (0)