-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create access group and access group project data source and resource (…
…#237) * Create access group and access group project * Update data_source_access_group_project_test.go * Update resource_access_group.go * Update resource_access_group_project.go * Update data_source_access_group_test.go * Update resource_access_group_project_test.go * Update data_source_access_group_project_test.go * fix a few more tests * Update resource_access_group_project_test.go * generate docs * Update resource_access_group_project_test.go * update docs * Update resource_access_group_project_test.go * move CheckDestroy
- Loading branch information
1 parent
247b116
commit aec74a0
Showing
17 changed files
with
1,658 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
package client | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform-plugin-log/tflog" | ||
) | ||
|
||
type AccessGroup struct { | ||
ID string `json:"accessGroupId"` | ||
TeamID string `json:"teamId"` | ||
Name string `json:"name"` | ||
} | ||
|
||
type GetAccessGroupRequest struct { | ||
AccessGroupID string | ||
TeamID string | ||
} | ||
|
||
func (c *Client) GetAccessGroup(ctx context.Context, req GetAccessGroupRequest) (r AccessGroup, err error) { | ||
url := fmt.Sprintf("%s/v1/access-groups/%s", c.baseURL, req.AccessGroupID) | ||
if c.teamID(req.TeamID) != "" { | ||
url = fmt.Sprintf("%s?teamId=%s", url, c.teamID(req.TeamID)) | ||
} | ||
tflog.Info(ctx, "getting access group", map[string]interface{}{ | ||
"url": url, | ||
}) | ||
err = c.doRequest(clientRequest{ | ||
ctx: ctx, | ||
method: "GET", | ||
url: url, | ||
body: "", | ||
}, &r) | ||
if err != nil { | ||
return r, fmt.Errorf("unable to get access group: %w", err) | ||
} | ||
|
||
r.TeamID = c.teamID(req.TeamID) | ||
return r, err | ||
} | ||
|
||
type CreateAccessGroupRequest struct { | ||
TeamID string | ||
Name string | ||
} | ||
|
||
func (c *Client) CreateAccessGroup(ctx context.Context, req CreateAccessGroupRequest) (r AccessGroup, err error) { | ||
url := fmt.Sprintf("%s/v1/access-groups", c.baseURL) | ||
if c.teamID(req.TeamID) != "" { | ||
url = fmt.Sprintf("%s?teamId=%s", url, c.teamID(req.TeamID)) | ||
} | ||
payload := string(mustMarshal( | ||
struct { | ||
Name string `json:"name"` | ||
}{ | ||
Name: req.Name, | ||
}, | ||
)) | ||
tflog.Info(ctx, "creating access group", map[string]interface{}{ | ||
"url": url, | ||
"payload": payload, | ||
}) | ||
err = c.doRequest(clientRequest{ | ||
ctx: ctx, | ||
method: "POST", | ||
url: url, | ||
body: payload, | ||
}, &r) | ||
if err != nil { | ||
return r, err | ||
} | ||
r.TeamID = c.teamID(req.TeamID) | ||
return r, err | ||
} | ||
|
||
type UpdateAccessGroupRequest struct { | ||
AccessGroupID string | ||
TeamID string | ||
Name string | ||
} | ||
|
||
func (c *Client) UpdateAccessGroup(ctx context.Context, req UpdateAccessGroupRequest) (r AccessGroup, err error) { | ||
url := fmt.Sprintf("%s/v1/access-groups/%s", c.baseURL, req.AccessGroupID) | ||
if c.teamID(req.TeamID) != "" { | ||
url = fmt.Sprintf("%s?teamId=%s", url, c.teamID(req.TeamID)) | ||
} | ||
payload := string(mustMarshal( | ||
struct { | ||
Name string `json:"name"` | ||
}{ | ||
Name: req.Name, | ||
}, | ||
)) | ||
tflog.Info(ctx, "updating access group", map[string]interface{}{ | ||
"url": url, | ||
"payload": payload, | ||
}) | ||
err = c.doRequest(clientRequest{ | ||
ctx: ctx, | ||
method: "POST", | ||
url: url, | ||
body: payload, | ||
}, &r) | ||
if err != nil { | ||
return r, err | ||
} | ||
r.TeamID = c.teamID(req.TeamID) | ||
return r, err | ||
} | ||
|
||
type DeleteAccessGroupRequest struct { | ||
AccessGroupID string | ||
TeamID string | ||
} | ||
|
||
func (c *Client) DeleteAccessGroup(ctx context.Context, req DeleteAccessGroupRequest) error { | ||
url := fmt.Sprintf("%s/v1/access-groups/%s", c.baseURL, req.AccessGroupID) | ||
if c.teamID(req.TeamID) != "" { | ||
url = fmt.Sprintf("%s?teamId=%s", url, c.teamID(req.TeamID)) | ||
} | ||
tflog.Info(ctx, "deleting access group", map[string]interface{}{ | ||
"url": url, | ||
}) | ||
return c.doRequest(clientRequest{ | ||
ctx: ctx, | ||
method: "DELETE", | ||
url: url, | ||
body: "", | ||
}, nil) | ||
} |
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,138 @@ | ||
package client | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform-plugin-log/tflog" | ||
) | ||
|
||
type AccessGroupProject struct { | ||
TeamID string `json:"teamId"` | ||
AccessGroupID string `json:"accessGroupId"` | ||
ProjectID string `json:"projectId"` | ||
Role string `json:"role"` | ||
} | ||
|
||
type CreateAccessGroupProjectRequest struct { | ||
TeamID string | ||
AccessGroupID string | ||
ProjectID string | ||
Role string | ||
} | ||
|
||
func (c *Client) CreateAccessGroupProject(ctx context.Context, req CreateAccessGroupProjectRequest) (r AccessGroupProject, err error) { | ||
url := fmt.Sprintf("%s/v1/access-groups/%s/projects", c.baseURL, req.AccessGroupID) | ||
if c.teamID(req.TeamID) != "" { | ||
url = fmt.Sprintf("%s?teamId=%s", url, c.teamID(req.TeamID)) | ||
} | ||
payload := string(mustMarshal( | ||
struct { | ||
Role string `json:"role"` | ||
ProjectID string `json:"projectId"` | ||
}{ | ||
Role: req.Role, | ||
ProjectID: req.ProjectID, | ||
}, | ||
)) | ||
tflog.Info(ctx, "creating access group project", map[string]interface{}{ | ||
"url": url, | ||
"payload": payload, | ||
}) | ||
err = c.doRequest(clientRequest{ | ||
ctx: ctx, | ||
method: "POST", | ||
url: url, | ||
body: payload, | ||
}, &r) | ||
if err != nil { | ||
return r, err | ||
} | ||
r.TeamID = c.teamID(req.TeamID) | ||
return r, err | ||
} | ||
|
||
type GetAccessGroupProjectRequest struct { | ||
TeamID string | ||
AccessGroupID string | ||
ProjectID string | ||
} | ||
|
||
func (c *Client) GetAccessGroupProject(ctx context.Context, req GetAccessGroupProjectRequest) (r AccessGroupProject, err error) { | ||
url := fmt.Sprintf("%s/v1/access-groups/%s/projects/%s", c.baseURL, req.AccessGroupID, req.ProjectID) | ||
if c.teamID(req.TeamID) != "" { | ||
url = fmt.Sprintf("%s?teamId=%s", url, c.teamID(req.TeamID)) | ||
} | ||
tflog.Info(ctx, "getting access group project", map[string]interface{}{ | ||
"url": url, | ||
}) | ||
err = c.doRequest(clientRequest{ | ||
ctx: ctx, | ||
method: "GET", | ||
url: url, | ||
}, &r) | ||
|
||
if err != nil { | ||
return r, fmt.Errorf("unable to get access group project: %w", err) | ||
} | ||
|
||
return r, err | ||
} | ||
|
||
type UpdateAccessGroupProjectRequest struct { | ||
TeamID string | ||
AccessGroupID string | ||
ProjectID string | ||
Role string | ||
} | ||
|
||
func (c *Client) UpdateAccessGroupProject(ctx context.Context, req UpdateAccessGroupProjectRequest) (r AccessGroupProject, err error) { | ||
url := fmt.Sprintf("%s/v1/access-groups/%s/projects/%s", c.baseURL, req.AccessGroupID, req.ProjectID) | ||
if c.teamID(req.TeamID) != "" { | ||
url = fmt.Sprintf("%s?teamId=%s", url, c.teamID(req.TeamID)) | ||
} | ||
payload := string(mustMarshal( | ||
struct { | ||
Role string `json:"role"` | ||
}{ | ||
Role: req.Role, | ||
}, | ||
)) | ||
tflog.Info(ctx, "updating access group project", map[string]interface{}{ | ||
"url": url, | ||
"payload": payload, | ||
}) | ||
err = c.doRequest(clientRequest{ | ||
ctx: ctx, | ||
method: "PATCH", | ||
url: url, | ||
body: payload, | ||
}, &r) | ||
if err != nil { | ||
return r, err | ||
} | ||
r.TeamID = c.teamID(req.TeamID) | ||
return r, err | ||
} | ||
|
||
type DeleteAccessGroupProjectRequest struct { | ||
TeamID string | ||
AccessGroupID string | ||
ProjectID string | ||
} | ||
|
||
func (c *Client) DeleteAccessGroupProject(ctx context.Context, req DeleteAccessGroupProjectRequest) error { | ||
url := fmt.Sprintf("%s/v1/access-groups/%s/projects/%s", c.baseURL, req.AccessGroupID, req.ProjectID) | ||
if c.teamID(req.TeamID) != "" { | ||
url = fmt.Sprintf("%s?teamId=%s", url, c.teamID(req.TeamID)) | ||
} | ||
tflog.Info(ctx, "deleting access group project", map[string]interface{}{ | ||
"url": url, | ||
}) | ||
return c.doRequest(clientRequest{ | ||
ctx: ctx, | ||
method: "DELETE", | ||
url: url, | ||
body: "", | ||
}, nil) | ||
} |
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,31 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "vercel_access_group Data Source - terraform-provider-vercel" | ||
subcategory: "" | ||
description: |- | ||
Provides information about an existing Access Group. | ||
For more detailed information, please see the Vercel documentation https://vercel.com/docs/accounts/team-members-and-roles/access-groups. | ||
--- | ||
|
||
# vercel_access_group (Data Source) | ||
|
||
Provides information about an existing Access Group. | ||
|
||
For more detailed information, please see the [Vercel documentation](https://vercel.com/docs/accounts/team-members-and-roles/access-groups). | ||
|
||
|
||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `id` (String) The Access Group ID to be retrieved. | ||
|
||
### Optional | ||
|
||
- `team_id` (String) The ID of the team the Access Group should exist under. Required when configuring a team resource if a default team has not been set in the provider. | ||
|
||
### Read-Only | ||
|
||
- `name` (String) The name of the Access Group. |
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,32 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "vercel_access_group_project Data Source - terraform-provider-vercel" | ||
subcategory: "" | ||
description: |- | ||
Provides information about an existing Access Group Project Assignment. | ||
For more detailed information, please see the Vercel documentation https://vercel.com/docs/accounts/team-members-and-roles/access-groups. | ||
--- | ||
|
||
# vercel_access_group_project (Data Source) | ||
|
||
Provides information about an existing Access Group Project Assignment. | ||
|
||
For more detailed information, please see the [Vercel documentation](https://vercel.com/docs/accounts/team-members-and-roles/access-groups). | ||
|
||
|
||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `access_group_id` (String) The Access Group ID. | ||
- `project_id` (String) The Project ID. | ||
|
||
### Optional | ||
|
||
- `team_id` (String) The ID of the team the Access Group Project should exist under. Required when configuring a team resource if a default team has not been set in the provider. | ||
|
||
### Read-Only | ||
|
||
- `role` (String) The Access Group Project Role. |
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,34 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "vercel_access_group Resource - terraform-provider-vercel" | ||
subcategory: "" | ||
description: |- | ||
Provides an Access Group Resource. | ||
Access Groups provide a way to manage groups of Vercel users across projects on your team. They are a set of project role assignations, a combination of Vercel users and the projects they work on. | ||
For more detailed information, please see the Vercel documentation https://vercel.com/docs/accounts/team-members-and-roles/access-groups. | ||
--- | ||
|
||
# vercel_access_group (Resource) | ||
|
||
Provides an Access Group Resource. | ||
|
||
Access Groups provide a way to manage groups of Vercel users across projects on your team. They are a set of project role assignations, a combination of Vercel users and the projects they work on. | ||
|
||
For more detailed information, please see the [Vercel documentation](https://vercel.com/docs/accounts/team-members-and-roles/access-groups). | ||
|
||
|
||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `name` (String) The name of the Access Group | ||
|
||
### Optional | ||
|
||
- `team_id` (String) The ID of the team the Access Group should exist under. Required when configuring a team resource if a default team has not been set in the provider. | ||
|
||
### Read-Only | ||
|
||
- `id` (String) The ID of the Access Group. |
Oops, something went wrong.