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

Create resource for vercel_project_crons #334

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
May 27, 2025
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
6 changes: 6 additions & 0 deletions client/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,12 @@ type ProjectResponse struct {
DeploymentExpiration *DeploymentExpiration `json:"deploymentExpiration"`
ResourceConfig *ResourceConfigResponse `json:"resourceConfig"`
NodeVersion string `json:"nodeVersion"`
Crons *ProjectCronsResponse `json:"crons"`
}

type ProjectCronsResponse struct {
DisabledAt *int `json:"disabledAt"`
EnabledAt int `json:"enabled"`
}

type GitComments struct {
Expand Down
51 changes: 51 additions & 0 deletions client/project_crons.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package client

import (
"context"
"fmt"

"github.com/hashicorp/terraform-plugin-log/tflog"
)

// ProjectCrons represents the crons settings for a Vercel project.
type ProjectCrons struct {
ProjectID string `json:"-"`
TeamID string `json:"-"`
Enabled bool `json:"enabled"`
}

// GetProjectCrons retrieves the current crons status for a project.
func (c *Client) GetProjectCrons(ctx context.Context, projectID, teamID string) (ProjectCrons, error) {
r, err := c.GetProject(ctx, projectID, teamID)

return ProjectCrons{
ProjectID: projectID,
TeamID: teamID,
Enabled: r.Crons == nil || r.Crons.DisabledAt == nil,
}, err
}

// UpdateProjectCrons toggles the crons feature for a project.
func (c *Client) UpdateProjectCrons(ctx context.Context, request ProjectCrons) (ProjectCrons, error) {
url := fmt.Sprintf("%s/v1/projects/%s/crons", c.baseURL, request.ProjectID)
if c.TeamID(request.TeamID) != "" {
url = fmt.Sprintf("%s?teamId=%s", url, c.TeamID(request.TeamID))
}
tflog.Info(ctx, "updating project crons", map[string]any{
"url": url,
"payload": request,
})
var r ProjectResponse
err := c.doRequest(clientRequest{
ctx: ctx,
method: "PATCH",
url: url,
body: string(mustMarshal(request)),
}, &r)

return ProjectCrons{
ProjectID: request.ProjectID,
TeamID: request.TeamID,
Enabled: r.Crons == nil || r.Crons.DisabledAt == nil,
}, err
}
60 changes: 60 additions & 0 deletions docs/resources/project_crons.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "vercel_project_crons Resource - terraform-provider-vercel"
subcategory: ""
description: |-
Provides a Project Crons resource.
The resource toggles whether crons are enabled for a Vercel project.
---

# vercel_project_crons (Resource)

Provides a Project Crons resource.

The resource toggles whether crons are enabled for a Vercel project.

## Example Usage

```terraform
resource "vercel_project" "example" {
name = "example-project"
framework = "nextjs"

git_repository = {
type = "github"
repo = "vercel/some-repo"
}
}

resource "vercel_project_crons" "example" {
project_id = vercel_project.example.id
enabled = true
}
```

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

### Required

- `enabled` (Boolean) Whether crons are enabled for the project.
- `project_id` (String) The ID of the Project to toggle crons for.

### Optional

- `team_id` (String) The ID of the team the Project exists under. Required when configuring a team resource if a default team has not been set in the provider.

## Import

Import is supported using the following syntax:

```shell
# If importing with a team configured on the provider, simply use the project ID.
# - project_id can be found in the project `settings` tab in the Vercel UI.
terraform import vercel_project_crons.example prj_xxxxxxxxxxxxxxxxxxxxxxxxxxxx

# Alternatively, you can import via the team_id and project_id.
# - team_id can be found in the team `settings` tab in the Vercel UI.
# - project_id can be found in the project `settings` tab in the Vercel UI.
terraform import vercel_project_crons.example team_xxxxxxxxxxxxxxxxxxxxxxxx/prj_xxxxxxxxxxxxxxxxxxxxxxxxxxxx
```
8 changes: 8 additions & 0 deletions examples/resources/vercel_project_crons/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# If importing with a team configured on the provider, simply use the project ID.
# - project_id can be found in the project `settings` tab in the Vercel UI.
terraform import vercel_project_crons.example prj_xxxxxxxxxxxxxxxxxxxxxxxxxxxx

# Alternatively, you can import via the team_id and project_id.
# - team_id can be found in the team `settings` tab in the Vercel UI.
# - project_id can be found in the project `settings` tab in the Vercel UI.
terraform import vercel_project_crons.example team_xxxxxxxxxxxxxxxxxxxxxxxx/prj_xxxxxxxxxxxxxxxxxxxxxxxxxxxx
14 changes: 14 additions & 0 deletions examples/resources/vercel_project_crons/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
resource "vercel_project" "example" {
name = "example-project"
framework = "nextjs"

git_repository = {
type = "github"
repo = "vercel/some-repo"
}
}

resource "vercel_project_crons" "example" {
project_id = vercel_project.example.id
enabled = true
}
1 change: 1 addition & 0 deletions vercel/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func (p *vercelProvider) Resources(_ context.Context) []func() resource.Resource
newMicrofrontendGroupMembershipResource,
newMicrofrontendGroupResource,
newProjectDeploymentRetentionResource,
newProjectCronsResource,
newProjectDomainResource,
newProjectEnvironmentVariableResource,
newProjectEnvironmentVariablesResource,
Expand Down
Loading