-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
30 changed files
with
1,182 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
package client | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform-plugin-log/tflog" | ||
) | ||
|
||
type ProjectRole struct { | ||
ProjectID string `json:"projectId"` | ||
Role string `json:"role"` | ||
} | ||
|
||
type TeamMemberInviteRequest struct { | ||
UserID string `json:"uid,omitempty"` | ||
Email string `json:"email,omitempty"` | ||
Role string `json:"role,omitempty"` | ||
Projects []ProjectRole `json:"projects,omitempty"` | ||
AccessGroups []string `json:"accessGroups,omitempty"` | ||
TeamID string `json:"-"` | ||
} | ||
|
||
func (c *Client) InviteTeamMember(ctx context.Context, request TeamMemberInviteRequest) error { | ||
url := fmt.Sprintf("%s/v1/teams/%s/members", c.baseURL, request.TeamID) | ||
tflog.Info(ctx, "inviting user", map[string]interface{}{ | ||
"url": url, | ||
"user": request.UserID, | ||
"email": request.Email, | ||
"role": request.Role, | ||
}) | ||
|
||
err := c.doRequest(clientRequest{ | ||
ctx: ctx, | ||
method: "POST", | ||
url: url, | ||
body: string(mustMarshal(request)), | ||
}, nil) | ||
return err | ||
} | ||
|
||
type TeamMemberRemoveRequest struct { | ||
UserID string | ||
TeamID string | ||
} | ||
|
||
func (c *Client) RemoveTeamMember(ctx context.Context, request TeamMemberRemoveRequest) error { | ||
url := fmt.Sprintf("%s/v2/teams/%s/members/%s", c.baseURL, request.TeamID, request.UserID) | ||
tflog.Info(ctx, "removing user", map[string]interface{}{ | ||
"url": url, | ||
"user": request.UserID, | ||
}) | ||
err := c.doRequest(clientRequest{ | ||
ctx: ctx, | ||
method: "DELETE", | ||
url: url, | ||
body: "", | ||
}, nil) | ||
return err | ||
} | ||
|
||
type TeamMemberUpdateRequest struct { | ||
UserID string `json:"-"` | ||
Role string `json:"role"` | ||
TeamID string `json:"-"` | ||
Projects []ProjectRole `json:"projects,omitempty"` | ||
AccessGroupsToAdd []string `json:"accessGroupsToAdd,omitempty"` | ||
AccessGroupsToRemove []string `json:"accessGroupsToRemove,omitempty"` | ||
} | ||
|
||
func (c *Client) UpdateTeamMember(ctx context.Context, request TeamMemberUpdateRequest) error { | ||
url := fmt.Sprintf("%s/v1/teams/%s/members/%s", c.baseURL, request.TeamID, request.UserID) | ||
tflog.Info(ctx, "updating team member", map[string]interface{}{ | ||
"url": url, | ||
"user": request.UserID, | ||
"role": request.Role, | ||
}) | ||
err := c.doRequest(clientRequest{ | ||
ctx: ctx, | ||
method: "PATCH", | ||
url: url, | ||
body: string(mustMarshal(request)), | ||
}, nil) | ||
return err | ||
} | ||
|
||
type GetTeamMemberRequest struct { | ||
TeamID string | ||
UserID string | ||
} | ||
|
||
type TeamMember struct { | ||
Confirmed bool `json:"confirmed"` | ||
Role string `json:"role"` | ||
UserID string `json:"uid"` | ||
Projects []ProjectRole `json:"projects"` | ||
AccessGroups []struct { | ||
ID string `json:"id"` | ||
Name string `json:"name"` | ||
} `json:"accessGroups"` | ||
} | ||
|
||
func (c *Client) GetTeamMember(ctx context.Context, request GetTeamMemberRequest) (TeamMember, error) { | ||
url := fmt.Sprintf("%s/v2/teams/%s/members?limit=1&filterByUserIds=%s", c.baseURL, request.TeamID, request.UserID) | ||
tflog.Info(ctx, "getting team member", map[string]interface{}{ | ||
"url": url, | ||
}) | ||
|
||
var response struct { | ||
Members []TeamMember `json:"members"` | ||
} | ||
err := c.doRequest(clientRequest{ | ||
ctx: ctx, | ||
method: "GET", | ||
url: url, | ||
body: "", | ||
}, &response) | ||
if err != nil { | ||
return TeamMember{}, err | ||
} | ||
if len(response.Members) == 0 { | ||
return TeamMember{}, APIError{ | ||
StatusCode: 404, | ||
Message: "Team member not found", | ||
Code: "not_found", | ||
} | ||
} | ||
|
||
// Now look up the projects for the member, but only if we need to. | ||
if !response.Members[0].Confirmed { | ||
return response.Members[0], nil | ||
} | ||
url = fmt.Sprintf("%s/v1/teams/%s/members/%s/projects?limit=100", c.baseURL, request.TeamID, request.UserID) | ||
var response2 struct { | ||
Projects []ProjectRole `json:"projects"` | ||
} | ||
err = c.doRequest(clientRequest{ | ||
ctx: ctx, | ||
method: "GET", | ||
url: url, | ||
body: "", | ||
}, &response2) | ||
if err != nil { | ||
return TeamMember{}, err | ||
} | ||
response.Members[0].Projects = response2.Projects | ||
return response.Members[0], err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "vercel_team_member Data Source - terraform-provider-vercel" | ||
subcategory: "" | ||
description: |- | ||
Provider a datasource for managing a team member. | ||
--- | ||
|
||
# vercel_team_member (Data Source) | ||
|
||
Provider a datasource for managing a team member. | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
data "vercel_team_member" "example" { | ||
user_id = "uuuuuuuuuuuuuuuuuuuuuuuuuu" | ||
team_id = "team_xxxxxxxxxxxxxxxxxxxxxxxx" | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `team_id` (String) The ID of the existing Vercel Team. | ||
- `user_id` (String) The ID of the existing Vercel Team Member. | ||
|
||
### Read-Only | ||
|
||
- `access_groups` (Set of String) If access groups are enabled on the team, and the user is a CONTRIBUTOR, `projects`, `access_groups` or both must be specified. A set of access groups IDs that the user should be granted access to. | ||
- `id` (String) The ID of this resource. | ||
- `projects` (Attributes Set) If access groups are enabled on the team, and the user is a CONTRIBUTOR, `projects`, `access_groups` or both must be specified. A set of projects that the user should be granted access to, along with their role in each project. (see [below for nested schema](#nestedatt--projects)) | ||
- `role` (String) The role that the user should have in the project. One of 'MEMBER', 'OWNER', 'VIEWER', 'DEVELOPER', 'BILLING' or 'CONTRIBUTOR'. Depending on your Team's plan, some of these roles may be unavailable. | ||
|
||
<a id="nestedatt--projects"></a> | ||
### Nested Schema for `projects` | ||
|
||
Required: | ||
|
||
- `project_id` (String) The ID of the project that the user should be granted access to. | ||
- `role` (String) The role that the user should have in the project. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "vercel_team_member Resource - terraform-provider-vercel" | ||
subcategory: "" | ||
description: |- | ||
Provider a resource for managing a team member. | ||
--- | ||
|
||
# vercel_team_member (Resource) | ||
|
||
Provider a resource for managing a team member. | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
resource "vercel_team_member" "example" { | ||
team_id = "team_xxxxxxxxxxxxxxxxxxxxxxxx" | ||
user_id = "uuuuuuuuuuuuuuuuuuuuuuuuuu" | ||
role = "MEMBER" | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `role` (String) The role that the user should have in the project. One of 'MEMBER', 'OWNER', 'VIEWER', 'DEVELOPER', 'BILLING' or 'CONTRIBUTOR'. Depending on your Team's plan, some of these roles may be unavailable. | ||
- `team_id` (String) The ID of the existing Vercel Team. | ||
- `user_id` (String) The ID of the user to add to the team. | ||
|
||
### Optional | ||
|
||
- `access_groups` (Set of String) If access groups are enabled on the team, and the user is a CONTRIBUTOR, `projects`, `access_groups` or both must be specified. A set of access groups IDs that the user should be granted access to. | ||
- `projects` (Attributes Set) If access groups are enabled on the team, and the user is a CONTRIBUTOR, `projects`, `access_groups` or both must be specified. A set of projects that the user should be granted access to, along with their role in each project. (see [below for nested schema](#nestedatt--projects)) | ||
|
||
<a id="nestedatt--projects"></a> | ||
### Nested Schema for `projects` | ||
|
||
Required: | ||
|
||
- `project_id` (String) The ID of the project that the user should be granted access to. | ||
- `role` (String) The role that the user should have in the project. | ||
|
||
## Import | ||
|
||
Import is supported using the following syntax: | ||
|
||
```shell | ||
# To import, use the team_id and user_id. | ||
terraform import vercel_access_group.example team_xxxxxxxxxxxxxxxxxxxxxxxx/uuuuuuuuuuuuuuuuuuuuuuuuuu | ||
``` |
Oops, something went wrong.