这是indexloc提供的服务,不要输入任何密码
Skip to content

Add team config resource for managing team settings #224

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 93 additions & 34 deletions client/team.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,48 +11,69 @@ import (
type TeamCreateRequest struct {
Slug string `json:"slug"`
Name string `json:"name"`
Plan string `json:"plan"`
}

// Team is the information returned by the vercel api when a team is created.
type Team struct {
ID string `json:"id"`
SensitiveEnvironmentVariablePolicy *string `json:"sensitiveEnvironmentVariablePolicy"`
type SamlConnection struct {
Status string `json:"status"`
}

// CreateTeam creates a team within vercel.
func (c *Client) CreateTeam(ctx context.Context, request TeamCreateRequest) (r Team, err error) {
url := fmt.Sprintf("%s/v1/teams", c.baseURL)
type SamlDirectory struct {
Type string `json:"type"`
State string `json:"state"`
}

payload := string(mustMarshal(request))
tflog.Info(ctx, "creating team", map[string]interface{}{
"url": url,
"payload": payload,
})
err = c.doRequest(clientRequest{
ctx: ctx,
method: "POST",
url: url,
body: payload,
}, &r)
return r, err
type SamlConfig struct {
Connection *SamlConnection `json:"connection"`
Directory *SamlDirectory `json:"directory"`
Enforced bool `json:"enforced,omitempty"`
Roles map[string]string `json:"roles,omitempty"`
}

// DeleteTeam deletes an existing team within vercel.
func (c *Client) DeleteTeam(ctx context.Context, teamID string) error {
url := fmt.Sprintf("%s/v1/teams/%s", c.baseURL, teamID)
tflog.Info(ctx, "deleting team", map[string]interface{}{
"url": url,
})
return c.doRequest(clientRequest{
ctx: ctx,
method: "DELETE",
url: url,
body: "",
}, nil)
type TaxID struct {
Type string `json:"type"`
ID string `json:"id"`
}

type Address struct {
Line1 *string `json:"line1"`
Line2 *string `json:"line2"`
PostalCode *string `json:"postalCode"`
City *string `json:"city"`
Country *string `json:"country"`
State *string `json:"state"`
}

type RemoteCaching struct {
Enabled *bool `json:"enabled"`
}

type SpacesConfig struct {
Enabled bool `json:"enabled"`
}

// Team is the information returned by the vercel api when a team is created.
type Team struct {
ID string `json:"id"`
Name string `json:"name"`
Avatar *string `json:"avatar"` // hash of uploaded image
Description *string `json:"description"`
Slug string `json:"slug"`
SensitiveEnvironmentVariablePolicy *string `json:"sensitiveEnvironmentVariablePolicy"`
EmailDomain *string `json:"emailDomain"`
Saml *SamlConfig `json:"saml"`
InviteCode *string `json:"inviteCode"`
PreviewDeploymentSuffix *string `json:"previewDeploymentSuffix"`
RemoteCaching *RemoteCaching `json:"remoteCaching"`
EnablePreviewFeedback *string `json:"enablePreviewFeedback"`
EnableProductionFeedback *string `json:"enableProductionFeedback"`
Spaces *SpacesConfig `json:"spaces"`
HideIPAddresses *bool `json:"hideIpAddresses"`
HideIPAddressesInLogDrains *bool `json:"hideIpAddressesInLogDrains,omitempty"`
}

// GetTeam returns information about an existing team within vercel.
func (c *Client) GetTeam(ctx context.Context, idOrSlug string) (r Team, err error) {
func (c *Client) GetTeam(ctx context.Context, idOrSlug string) (t Team, err error) {
url := fmt.Sprintf("%s/v2/teams/%s", c.baseURL, idOrSlug)
tflog.Info(ctx, "getting team", map[string]interface{}{
"url": url,
Expand All @@ -62,6 +83,44 @@ func (c *Client) GetTeam(ctx context.Context, idOrSlug string) (r Team, err erro
method: "GET",
url: url,
body: "",
}, &r)
return r, err
}, &t)
return t, err
}

type UpdateSamlConfig struct {
Enforced bool `json:"enforced"`
Roles map[string]string `json:"roles"`
}

type UpdateTeamRequest struct {
TeamID string `json:"-"`
Avatar string `json:"avatar,omitempty"`
Description string `json:"description,omitempty"`
EmailDomain string `json:"emailDomain,omitempty"`
Name string `json:"name,omitempty"`
PreviewDeploymentSuffix string `json:"previewDeploymentSuffix,omitempty"`
Saml *UpdateSamlConfig `json:"saml,omitempty"`
Slug string `json:"slug,omitempty"`
EnablePreviewFeedback string `json:"enablePreviewFeedback,omitempty"`
EnableProductionFeedback string `json:"enableProductionFeedback,omitempty"`
SensitiveEnvironmentVariablePolicy string `json:"sensitiveEnvironmentVariablePolicy,omitempty"`
RemoteCaching *RemoteCaching `json:"remoteCaching,omitempty"`
HideIPAddresses *bool `json:"hideIpAddresses,omitempty"`
HideIPAddressesInLogDrains *bool `json:"hideIpAddressesInLogDrains,omitempty"`
}

func (c *Client) UpdateTeam(ctx context.Context, request UpdateTeamRequest) (t Team, err error) {
url := fmt.Sprintf("%s/v2/teams/%s", c.baseURL, request.TeamID)
payload := string(mustMarshal(request))
tflog.Info(ctx, "updating team", map[string]interface{}{
"url": url,
"payload": payload,
})
err = c.doRequest(clientRequest{
ctx: ctx,
method: "PATCH",
url: url,
body: payload,
}, &t)
return t, err
}
68 changes: 68 additions & 0 deletions docs/resources/team_config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "vercel_team_config Resource - terraform-provider-vercel"
subcategory: ""
description: |-
Manages the configuration of an existing Vercel Team.
---

# vercel_team_config (Resource)

Manages the configuration of an existing Vercel Team.

## Example Usage

```terraform
data "vercel_file" "example" {
path = "example/avatar.png"
}

resource "vercel_team_config" "example" {
id = "team_xxxxxxxxxxxxxxxxxxxxxxxx"
avatar = data.vercel_file.example.file
name = "Vercel terraform example"
slug = "vercel-terraform-example"
description = "Vercel Terraform Example"
sensitive_environment_variable_policy = "off"
remote_caching = {
enabled = true
}
enable_preview_feedback = "off"
enable_production_feedback = "off"
hide_ip_addresses = true
hide_ip_addresses_in_log_drains = true
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `id` (String) The ID of the existing Vercel Team.

### Optional

- `avatar` (Map of String) The `avatar` should be a the 'file' attribute from a vercel_file data source.
- `description` (String) A description of the team.
- `email_domain` (String) Hostname that'll be matched with emails on sign-up to automatically join the Team.
- `enable_preview_feedback` (String)
- `enable_production_feedback` (String)
- `hide_ip_addresses` (Boolean) Indicates if ip addresses should be accessible in o11y tooling.
- `hide_ip_addresses_in_log_drains` (Boolean) Indicates if ip addresses should be accessible in log drains.
- `name` (String) The name of the team.
- `preview_deployment_suffix` (String) The hostname that is used as the preview deployment suffix.
- `remote_caching` (Attributes) Configuration for Remote Caching. (see [below for nested schema](#nestedatt--remote_caching))
- `sensitive_environment_variable_policy` (String)
- `slug` (String) The slug of the team. Will be used in the URL of the team's dashboard.

### Read-Only

- `invite_code` (String) A code that can be used to join this team. Only visible to Team owners.

<a id="nestedatt--remote_caching"></a>
### Nested Schema for `remote_caching`

Optional:

- `enabled` (Boolean) Indicates if Remote Caching is enabled.
19 changes: 19 additions & 0 deletions examples/resources/vercel_team_config/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
data "vercel_file" "example" {
path = "example/avatar.png"
}

resource "vercel_team_config" "example" {
id = "team_xxxxxxxxxxxxxxxxxxxxxxxx"
avatar = data.vercel_file.example.file
name = "Vercel terraform example"
slug = "vercel-terraform-example"
description = "Vercel Terraform Example"
sensitive_environment_variable_policy = "off"
remote_caching = {
enabled = true
}
enable_preview_feedback = "off"
enable_production_feedback = "off"
hide_ip_addresses = true
hide_ip_addresses_in_log_drains = true
}
Binary file added vercel/examples/avatar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions vercel/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func (p *vercelProvider) Resources(_ context.Context) []func() resource.Resource
newProjectEnvironmentVariableResource,
newProjectResource,
newSharedEnvironmentVariableResource,
newTeamConfigResource,
newWebhookResource,
}
}
Expand Down
Loading