Skip to content

Commit aec74a0

Browse files
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
1 parent 247b116 commit aec74a0

17 files changed

+1658
-0
lines changed

client/access_group.go

+131
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
package client
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/hashicorp/terraform-plugin-log/tflog"
8+
)
9+
10+
type AccessGroup struct {
11+
ID string `json:"accessGroupId"`
12+
TeamID string `json:"teamId"`
13+
Name string `json:"name"`
14+
}
15+
16+
type GetAccessGroupRequest struct {
17+
AccessGroupID string
18+
TeamID string
19+
}
20+
21+
func (c *Client) GetAccessGroup(ctx context.Context, req GetAccessGroupRequest) (r AccessGroup, err error) {
22+
url := fmt.Sprintf("%s/v1/access-groups/%s", c.baseURL, req.AccessGroupID)
23+
if c.teamID(req.TeamID) != "" {
24+
url = fmt.Sprintf("%s?teamId=%s", url, c.teamID(req.TeamID))
25+
}
26+
tflog.Info(ctx, "getting access group", map[string]interface{}{
27+
"url": url,
28+
})
29+
err = c.doRequest(clientRequest{
30+
ctx: ctx,
31+
method: "GET",
32+
url: url,
33+
body: "",
34+
}, &r)
35+
if err != nil {
36+
return r, fmt.Errorf("unable to get access group: %w", err)
37+
}
38+
39+
r.TeamID = c.teamID(req.TeamID)
40+
return r, err
41+
}
42+
43+
type CreateAccessGroupRequest struct {
44+
TeamID string
45+
Name string
46+
}
47+
48+
func (c *Client) CreateAccessGroup(ctx context.Context, req CreateAccessGroupRequest) (r AccessGroup, err error) {
49+
url := fmt.Sprintf("%s/v1/access-groups", c.baseURL)
50+
if c.teamID(req.TeamID) != "" {
51+
url = fmt.Sprintf("%s?teamId=%s", url, c.teamID(req.TeamID))
52+
}
53+
payload := string(mustMarshal(
54+
struct {
55+
Name string `json:"name"`
56+
}{
57+
Name: req.Name,
58+
},
59+
))
60+
tflog.Info(ctx, "creating access group", map[string]interface{}{
61+
"url": url,
62+
"payload": payload,
63+
})
64+
err = c.doRequest(clientRequest{
65+
ctx: ctx,
66+
method: "POST",
67+
url: url,
68+
body: payload,
69+
}, &r)
70+
if err != nil {
71+
return r, err
72+
}
73+
r.TeamID = c.teamID(req.TeamID)
74+
return r, err
75+
}
76+
77+
type UpdateAccessGroupRequest struct {
78+
AccessGroupID string
79+
TeamID string
80+
Name string
81+
}
82+
83+
func (c *Client) UpdateAccessGroup(ctx context.Context, req UpdateAccessGroupRequest) (r AccessGroup, err error) {
84+
url := fmt.Sprintf("%s/v1/access-groups/%s", c.baseURL, req.AccessGroupID)
85+
if c.teamID(req.TeamID) != "" {
86+
url = fmt.Sprintf("%s?teamId=%s", url, c.teamID(req.TeamID))
87+
}
88+
payload := string(mustMarshal(
89+
struct {
90+
Name string `json:"name"`
91+
}{
92+
Name: req.Name,
93+
},
94+
))
95+
tflog.Info(ctx, "updating access group", map[string]interface{}{
96+
"url": url,
97+
"payload": payload,
98+
})
99+
err = c.doRequest(clientRequest{
100+
ctx: ctx,
101+
method: "POST",
102+
url: url,
103+
body: payload,
104+
}, &r)
105+
if err != nil {
106+
return r, err
107+
}
108+
r.TeamID = c.teamID(req.TeamID)
109+
return r, err
110+
}
111+
112+
type DeleteAccessGroupRequest struct {
113+
AccessGroupID string
114+
TeamID string
115+
}
116+
117+
func (c *Client) DeleteAccessGroup(ctx context.Context, req DeleteAccessGroupRequest) error {
118+
url := fmt.Sprintf("%s/v1/access-groups/%s", c.baseURL, req.AccessGroupID)
119+
if c.teamID(req.TeamID) != "" {
120+
url = fmt.Sprintf("%s?teamId=%s", url, c.teamID(req.TeamID))
121+
}
122+
tflog.Info(ctx, "deleting access group", map[string]interface{}{
123+
"url": url,
124+
})
125+
return c.doRequest(clientRequest{
126+
ctx: ctx,
127+
method: "DELETE",
128+
url: url,
129+
body: "",
130+
}, nil)
131+
}

client/access_group_project.go

+138
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
package client
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/hashicorp/terraform-plugin-log/tflog"
8+
)
9+
10+
type AccessGroupProject struct {
11+
TeamID string `json:"teamId"`
12+
AccessGroupID string `json:"accessGroupId"`
13+
ProjectID string `json:"projectId"`
14+
Role string `json:"role"`
15+
}
16+
17+
type CreateAccessGroupProjectRequest struct {
18+
TeamID string
19+
AccessGroupID string
20+
ProjectID string
21+
Role string
22+
}
23+
24+
func (c *Client) CreateAccessGroupProject(ctx context.Context, req CreateAccessGroupProjectRequest) (r AccessGroupProject, err error) {
25+
url := fmt.Sprintf("%s/v1/access-groups/%s/projects", c.baseURL, req.AccessGroupID)
26+
if c.teamID(req.TeamID) != "" {
27+
url = fmt.Sprintf("%s?teamId=%s", url, c.teamID(req.TeamID))
28+
}
29+
payload := string(mustMarshal(
30+
struct {
31+
Role string `json:"role"`
32+
ProjectID string `json:"projectId"`
33+
}{
34+
Role: req.Role,
35+
ProjectID: req.ProjectID,
36+
},
37+
))
38+
tflog.Info(ctx, "creating access group project", map[string]interface{}{
39+
"url": url,
40+
"payload": payload,
41+
})
42+
err = c.doRequest(clientRequest{
43+
ctx: ctx,
44+
method: "POST",
45+
url: url,
46+
body: payload,
47+
}, &r)
48+
if err != nil {
49+
return r, err
50+
}
51+
r.TeamID = c.teamID(req.TeamID)
52+
return r, err
53+
}
54+
55+
type GetAccessGroupProjectRequest struct {
56+
TeamID string
57+
AccessGroupID string
58+
ProjectID string
59+
}
60+
61+
func (c *Client) GetAccessGroupProject(ctx context.Context, req GetAccessGroupProjectRequest) (r AccessGroupProject, err error) {
62+
url := fmt.Sprintf("%s/v1/access-groups/%s/projects/%s", c.baseURL, req.AccessGroupID, req.ProjectID)
63+
if c.teamID(req.TeamID) != "" {
64+
url = fmt.Sprintf("%s?teamId=%s", url, c.teamID(req.TeamID))
65+
}
66+
tflog.Info(ctx, "getting access group project", map[string]interface{}{
67+
"url": url,
68+
})
69+
err = c.doRequest(clientRequest{
70+
ctx: ctx,
71+
method: "GET",
72+
url: url,
73+
}, &r)
74+
75+
if err != nil {
76+
return r, fmt.Errorf("unable to get access group project: %w", err)
77+
}
78+
79+
return r, err
80+
}
81+
82+
type UpdateAccessGroupProjectRequest struct {
83+
TeamID string
84+
AccessGroupID string
85+
ProjectID string
86+
Role string
87+
}
88+
89+
func (c *Client) UpdateAccessGroupProject(ctx context.Context, req UpdateAccessGroupProjectRequest) (r AccessGroupProject, err error) {
90+
url := fmt.Sprintf("%s/v1/access-groups/%s/projects/%s", c.baseURL, req.AccessGroupID, req.ProjectID)
91+
if c.teamID(req.TeamID) != "" {
92+
url = fmt.Sprintf("%s?teamId=%s", url, c.teamID(req.TeamID))
93+
}
94+
payload := string(mustMarshal(
95+
struct {
96+
Role string `json:"role"`
97+
}{
98+
Role: req.Role,
99+
},
100+
))
101+
tflog.Info(ctx, "updating access group project", map[string]interface{}{
102+
"url": url,
103+
"payload": payload,
104+
})
105+
err = c.doRequest(clientRequest{
106+
ctx: ctx,
107+
method: "PATCH",
108+
url: url,
109+
body: payload,
110+
}, &r)
111+
if err != nil {
112+
return r, err
113+
}
114+
r.TeamID = c.teamID(req.TeamID)
115+
return r, err
116+
}
117+
118+
type DeleteAccessGroupProjectRequest struct {
119+
TeamID string
120+
AccessGroupID string
121+
ProjectID string
122+
}
123+
124+
func (c *Client) DeleteAccessGroupProject(ctx context.Context, req DeleteAccessGroupProjectRequest) error {
125+
url := fmt.Sprintf("%s/v1/access-groups/%s/projects/%s", c.baseURL, req.AccessGroupID, req.ProjectID)
126+
if c.teamID(req.TeamID) != "" {
127+
url = fmt.Sprintf("%s?teamId=%s", url, c.teamID(req.TeamID))
128+
}
129+
tflog.Info(ctx, "deleting access group project", map[string]interface{}{
130+
"url": url,
131+
})
132+
return c.doRequest(clientRequest{
133+
ctx: ctx,
134+
method: "DELETE",
135+
url: url,
136+
body: "",
137+
}, nil)
138+
}

docs/data-sources/access_group.md

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "vercel_access_group Data Source - terraform-provider-vercel"
4+
subcategory: ""
5+
description: |-
6+
Provides information about an existing Access Group.
7+
For more detailed information, please see the Vercel documentation https://vercel.com/docs/accounts/team-members-and-roles/access-groups.
8+
---
9+
10+
# vercel_access_group (Data Source)
11+
12+
Provides information about an existing Access Group.
13+
14+
For more detailed information, please see the [Vercel documentation](https://vercel.com/docs/accounts/team-members-and-roles/access-groups).
15+
16+
17+
18+
<!-- schema generated by tfplugindocs -->
19+
## Schema
20+
21+
### Required
22+
23+
- `id` (String) The Access Group ID to be retrieved.
24+
25+
### Optional
26+
27+
- `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.
28+
29+
### Read-Only
30+
31+
- `name` (String) The name of the Access Group.
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "vercel_access_group_project Data Source - terraform-provider-vercel"
4+
subcategory: ""
5+
description: |-
6+
Provides information about an existing Access Group Project Assignment.
7+
For more detailed information, please see the Vercel documentation https://vercel.com/docs/accounts/team-members-and-roles/access-groups.
8+
---
9+
10+
# vercel_access_group_project (Data Source)
11+
12+
Provides information about an existing Access Group Project Assignment.
13+
14+
For more detailed information, please see the [Vercel documentation](https://vercel.com/docs/accounts/team-members-and-roles/access-groups).
15+
16+
17+
18+
<!-- schema generated by tfplugindocs -->
19+
## Schema
20+
21+
### Required
22+
23+
- `access_group_id` (String) The Access Group ID.
24+
- `project_id` (String) The Project ID.
25+
26+
### Optional
27+
28+
- `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.
29+
30+
### Read-Only
31+
32+
- `role` (String) The Access Group Project Role.

docs/resources/access_group.md

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "vercel_access_group Resource - terraform-provider-vercel"
4+
subcategory: ""
5+
description: |-
6+
Provides an Access Group Resource.
7+
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.
8+
For more detailed information, please see the Vercel documentation https://vercel.com/docs/accounts/team-members-and-roles/access-groups.
9+
---
10+
11+
# vercel_access_group (Resource)
12+
13+
Provides an Access Group Resource.
14+
15+
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.
16+
17+
For more detailed information, please see the [Vercel documentation](https://vercel.com/docs/accounts/team-members-and-roles/access-groups).
18+
19+
20+
21+
<!-- schema generated by tfplugindocs -->
22+
## Schema
23+
24+
### Required
25+
26+
- `name` (String) The name of the Access Group
27+
28+
### Optional
29+
30+
- `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.
31+
32+
### Read-Only
33+
34+
- `id` (String) The ID of the Access Group.

0 commit comments

Comments
 (0)