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

Deprecate vercel_project_function_cpu and merge into vercel_project #206

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 10 commits into from
Sep 20, 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
8 changes: 8 additions & 0 deletions client/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type CreateProjectRequest struct {
PublicSource *bool `json:"publicSource"`
RootDirectory *string `json:"rootDirectory"`
ServerlessFunctionRegion string `json:"serverlessFunctionRegion,omitempty"`
ResourceConfig *ResourceConfig `json:"resourceConfig,omitempty"`
}

// CreateProject will create a project within Vercel.
Expand Down Expand Up @@ -197,6 +198,7 @@ type ProjectResponse struct {
GitComments *GitComments `json:"gitComments"`
Security *Security `json:"security"`
DeploymentExpiration *DeploymentExpiration `json:"deploymentExpiration"`
ResourceConfig *ResourceConfig `json:"resourceConfig"`
}

type GitComments struct {
Expand All @@ -208,6 +210,11 @@ type Security struct {
AttackModeEnabled bool `json:"attackModeEnabled"`
}

type ResourceConfig struct {
FunctionDefaultMemoryType string `json:"functionDefaultMemoryType,omitempty"`
FunctionDefaultTimeout int64 `json:"functionDefaultTimeout,omitempty"`
}

// GetProject retrieves information about an existing project from Vercel.
func (c *Client) GetProject(ctx context.Context, projectID, teamID string) (r ProjectResponse, err error) {
url := fmt.Sprintf("%s/v10/projects/%s", c.baseURL, projectID)
Expand Down Expand Up @@ -289,6 +296,7 @@ type UpdateProjectRequest struct {
DirectoryListing bool `json:"directoryListing"`
SkewProtectionMaxAge int `json:"skewProtectionMaxAge"`
GitComments *GitComments `json:"gitComments"`
ResourceConfig *ResourceConfig `json:"resourceConfig,omitempty"`
}

// UpdateProject updates an existing projects configuration within Vercel.
Expand Down
10 changes: 10 additions & 0 deletions docs/data-sources/project.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ output "project_id" {
- `prioritise_production_builds` (Boolean) If enabled, builds for the Production environment will be prioritized over Preview environments.
- `protection_bypass_for_automation` (Boolean) Allows automation services to bypass Vercel Authentication and Password Protection for both Preview and Production Deployments on this project when using an HTTP header named `x-vercel-protection-bypass`.
- `public_source` (Boolean) Specifies whether the source code and logs of the deployments for this project should be public or not.
- `resource_config` (Attributes) Resource Configuration for the project. (see [below for nested schema](#nestedatt--resource_config))
- `root_directory` (String) The name of a directory or relative path to the source code of your project. When null is used it will default to the project root.
- `serverless_function_region` (String) The region on Vercel's network to which your Serverless Functions are deployed. It should be close to any data source your Serverless Function might depend on. A new Deployment is required for your changes to take effect. Please see [Vercel's documentation](https://vercel.com/docs/concepts/edge-network/regions) for a full list of regions.
- `skew_protection` (String) Ensures that outdated clients always fetch the correct version for a given deployment. This value defines how long Vercel keeps Skew Protection active.
Expand Down Expand Up @@ -148,6 +149,15 @@ Read-Only:
- `deployment_type` (String) The deployment environment that will be protected.


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

Read-Only:

- `function_default_cpu_type` (String) The amount of CPU available to your Serverless Functions. Should be one of 'standard_legacy' (0.6vCPU), 'standard' (1vCPU) or 'performance' (1.7vCPUs).
- `function_default_timeout` (Number) The default timeout for Serverless Functions.


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

Expand Down
3 changes: 3 additions & 0 deletions docs/data-sources/project_function_cpu.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
page_title: "vercel_project_function_cpu Data Source - terraform-provider-vercel"
subcategory: ""
description: |-
~> This data source has been deprecated and no longer works. Please use the vercel_project data source and its resource_config attribute instead.
Provides information about a Project's Function CPU setting.
This controls the maximum amount of CPU utilization your Serverless Functions can use while executing. Standard is optimal for most frontend workloads. You can override this per function using the vercel.json file.
---

# vercel_project_function_cpu (Data Source)

~> This data source has been deprecated and no longer works. Please use the `vercel_project` data source and its `resource_config` attribute instead.

Provides information about a Project's Function CPU setting.

This controls the maximum amount of CPU utilization your Serverless Functions can use while executing. Standard is optimal for most frontend workloads. You can override this per function using the vercel.json file.
Expand Down
10 changes: 10 additions & 0 deletions docs/resources/project.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ resource "vercel_project" "example" {
- `prioritise_production_builds` (Boolean) If enabled, builds for the Production environment will be prioritized over Preview environments.
- `protection_bypass_for_automation` (Boolean) Allow automation services to bypass Vercel Authentication and Password Protection for both Preview and Production Deployments on this project when using an HTTP header named `x-vercel-protection-bypass` with a value of the `password_protection_for_automation_secret` field.
- `public_source` (Boolean) By default, visitors to the `/_logs` and `/_src` paths of your Production and Preview Deployments must log in with Vercel (requires being a member of your team) to see the Source, Logs and Deployment Status of your project. Setting `public_source` to `true` disables this behaviour, meaning the Source, Logs and Deployment Status can be publicly viewed.
- `resource_config` (Attributes) Resource Configuration for the project. (see [below for nested schema](#nestedatt--resource_config))
- `root_directory` (String) The name of a directory or relative path to the source code of your project. If omitted, it will default to the project root.
- `serverless_function_region` (String) The region on Vercel's network to which your Serverless Functions are deployed. It should be close to any data source your Serverless Function might depend on. A new Deployment is required for your changes to take effect. Please see [Vercel's documentation](https://vercel.com/docs/concepts/edge-network/regions) for a full list of regions.
- `skew_protection` (String) Ensures that outdated clients always fetch the correct version for a given deployment. This value defines how long Vercel keeps Skew Protection active.
Expand Down Expand Up @@ -179,6 +180,15 @@ Required:
- `password` (String, Sensitive) The password that visitors must enter to gain access to your Preview Deployments. Drift detection is not possible for this field.


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

Optional:

- `function_default_cpu_type` (String) The amount of CPU available to your Serverless Functions. Should be one of 'standard_legacy' (0.6vCPU), 'standard' (1vCPU) or 'performance' (1.7vCPUs).
- `function_default_timeout` (Number) The default timeout for Serverless Functions.


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

Expand Down
3 changes: 3 additions & 0 deletions docs/resources/project_function_cpu.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
page_title: "vercel_project_function_cpu Resource - terraform-provider-vercel"
subcategory: ""
description: |-
~> This resource has been deprecated and no longer works. Please use the vercel_project resource and its resource_config attribute instead.
Provides a Function CPU resource for a Project.
This controls the maximum amount of CPU utilization your Serverless Functions can use while executing. Standard is optimal for most frontend workloads. You can override this per function using the vercel.json file.
A new Deployment is required for your changes to take effect.
---

# vercel_project_function_cpu (Resource)

~> This resource has been deprecated and no longer works. Please use the `vercel_project` resource and its `resource_config` attribute instead.

Provides a Function CPU resource for a Project.

This controls the maximum amount of CPU utilization your Serverless Functions can use while executing. Standard is optimal for most frontend workloads. You can override this per function using the vercel.json file.
Expand Down
25 changes: 25 additions & 0 deletions vercel/data_source_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,21 @@ For more detailed information, please see the [Vercel documentation](https://ver
Computed: true,
Description: "Ensures that outdated clients always fetch the correct version for a given deployment. This value defines how long Vercel keeps Skew Protection active.",
},
"resource_config": schema.SingleNestedAttribute{
Description: "Resource Configuration for the project.",
Computed: true,
Attributes: map[string]schema.Attribute{
// This is actually "function_default_memory_type" in the API schema, but for better convention, we use "cpu" and do translation in the provider.
"function_default_cpu_type": schema.StringAttribute{
Description: "The amount of CPU available to your Serverless Functions. Should be one of 'standard_legacy' (0.6vCPU), 'standard' (1vCPU) or 'performance' (1.7vCPUs).",
Computed: true,
},
"function_default_timeout": schema.Int64Attribute{
Description: "The default timeout for Serverless Functions.",
Computed: true,
},
},
},
},
}
}
Expand Down Expand Up @@ -359,6 +374,7 @@ type ProjectDataSource struct {
PrioritiseProductionBuilds types.Bool `tfsdk:"prioritise_production_builds"`
DirectoryListing types.Bool `tfsdk:"directory_listing"`
SkewProtection types.String `tfsdk:"skew_protection"`
ResourceConfig *ResourceConfig `tfsdk:"resource_config"`
}

func convertResponseToProjectDataSource(ctx context.Context, response client.ProjectResponse, plan Project, environmentVariables []client.EnvironmentVariable) (ProjectDataSource, error) {
Expand All @@ -373,6 +389,14 @@ func convertResponseToProjectDataSource(ctx context.Context, response client.Pro
"on_commit": types.BoolValue(response.GitComments.OnCommit),
})
}

if response.ResourceConfig != nil {
plan.ResourceConfig = &ResourceConfig{
FunctionDefaultMemoryType: types.StringValue(response.ResourceConfig.FunctionDefaultMemoryType),
FunctionDefaultTimeout: types.Int64Value(response.ResourceConfig.FunctionDefaultTimeout),
}
}

project, err := convertResponseToProject(ctx, response, plan, environmentVariables)
if err != nil {
return ProjectDataSource{}, err
Expand Down Expand Up @@ -416,6 +440,7 @@ func convertResponseToProjectDataSource(ctx context.Context, response client.Pro
PrioritiseProductionBuilds: project.PrioritiseProductionBuilds,
DirectoryListing: project.DirectoryListing,
SkewProtection: project.SkewProtection,
ResourceConfig: project.ResourceConfig,
}, nil
}

Expand Down
10 changes: 9 additions & 1 deletion vercel/data_source_project_function_cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/vercel/terraform-provider-vercel/client"
)
Expand Down Expand Up @@ -48,7 +49,11 @@ func (d *projectFunctionCPUDataSource) Configure(ctx context.Context, req dataso

func (r *projectFunctionCPUDataSource) Schema(_ context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Description: `Provides information about a Project's Function CPU setting.
DeprecationMessage: "This data source is deprecated and no longer works. Please use the `vercel_project` data source and its `resource_config` attribute instead.",
Description: `
~> This data source has been deprecated and no longer works. Please use the ` + "`vercel_project`" + ` data source and its ` + "`resource_config`" + ` attribute instead.

Provides information about a Project's Function CPU setting.

This controls the maximum amount of CPU utilization your Serverless Functions can use while executing. Standard is optimal for most frontend workloads. You can override this per function using the vercel.json file.
`,
Expand All @@ -75,6 +80,9 @@ This controls the maximum amount of CPU utilization your Serverless Functions ca
}

func (d *projectFunctionCPUDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
resp.Diagnostics.Append(
diag.NewErrorDiagnostic("`vercel_project_function_cpu` data source deprecated", "use `vercel_project` data source and its `resource_config` attribute instead"),
)
var config ProjectFunctionCPU
diags := req.Config.Get(ctx, &config)
resp.Diagnostics.Append(diags...)
Expand Down
1 change: 1 addition & 0 deletions vercel/data_source_project_function_cpu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
)

func TestAcc_ProjectFunctionCPUDataSource(t *testing.T) {
t.Skip("the resource is deprecated and tests should be removed in the next release")
name := acctest.RandString(16)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand Down
6 changes: 6 additions & 0 deletions vercel/data_source_project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ func TestAcc_ProjectDataSource(t *testing.T) {
resource.TestCheckResourceAttr("data.vercel_project.test", "prioritise_production_builds", "true"),
resource.TestCheckResourceAttr("data.vercel_project.test", "directory_listing", "true"),
resource.TestCheckResourceAttr("data.vercel_project.test", "skew_protection", "7 days"),
resource.TestCheckResourceAttr("data.vercel_project.test", "resource_config.function_default_cpu_type", "standard_legacy"),
resource.TestCheckResourceAttr("data.vercel_project.test", "resource_config.function_default_timeout", "30"),
),
},
},
Expand Down Expand Up @@ -125,6 +127,10 @@ resource "vercel_project" "test" {
}
]
}
resource_config = {
function_default_cpu_type = "standard_legacy"
function_default_timeout = 30
}
}

data "vercel_project" "test" {
Expand Down
Loading
Loading