diff --git a/client/project.go b/client/project.go
index 14779bd5..cf40dde0 100644
--- a/client/project.go
+++ b/client/project.go
@@ -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.
@@ -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 {
@@ -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)
@@ -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.
diff --git a/docs/data-sources/project.md b/docs/data-sources/project.md
index 95dd2063..33e61425 100644
--- a/docs/data-sources/project.md
+++ b/docs/data-sources/project.md
@@ -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.
@@ -148,6 +149,15 @@ Read-Only:
- `deployment_type` (String) The deployment environment that will be protected.
+
+### 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.
+
+
### Nested Schema for `trusted_ips`
diff --git a/docs/data-sources/project_function_cpu.md b/docs/data-sources/project_function_cpu.md
index 0e47dc70..0f948eb3 100644
--- a/docs/data-sources/project_function_cpu.md
+++ b/docs/data-sources/project_function_cpu.md
@@ -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.
diff --git a/docs/resources/project.md b/docs/resources/project.md
index 983d2b8e..b7943bcd 100644
--- a/docs/resources/project.md
+++ b/docs/resources/project.md
@@ -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.
@@ -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.
+
+### 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.
+
+
### Nested Schema for `trusted_ips`
diff --git a/docs/resources/project_function_cpu.md b/docs/resources/project_function_cpu.md
index 92ef60af..d1b59242 100644
--- a/docs/resources/project_function_cpu.md
+++ b/docs/resources/project_function_cpu.md
@@ -3,6 +3,7 @@
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.
@@ -10,6 +11,8 @@ description: |-
# 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.
diff --git a/vercel/data_source_project.go b/vercel/data_source_project.go
index 8019bd94..b76fdf68 100644
--- a/vercel/data_source_project.go
+++ b/vercel/data_source_project.go
@@ -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,
+ },
+ },
+ },
},
}
}
@@ -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) {
@@ -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
@@ -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
}
diff --git a/vercel/data_source_project_function_cpu.go b/vercel/data_source_project_function_cpu.go
index 8b4a77a3..701fe2e1 100644
--- a/vercel/data_source_project_function_cpu.go
+++ b/vercel/data_source_project_function_cpu.go
@@ -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"
)
@@ -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.
`,
@@ -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...)
diff --git a/vercel/data_source_project_function_cpu_test.go b/vercel/data_source_project_function_cpu_test.go
index f7627f63..cc6f62b8 100644
--- a/vercel/data_source_project_function_cpu_test.go
+++ b/vercel/data_source_project_function_cpu_test.go
@@ -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) },
diff --git a/vercel/data_source_project_test.go b/vercel/data_source_project_test.go
index 93b040f7..2deccaeb 100644
--- a/vercel/data_source_project_test.go
+++ b/vercel/data_source_project_test.go
@@ -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"),
),
},
},
@@ -125,6 +127,10 @@ resource "vercel_project" "test" {
}
]
}
+ resource_config = {
+ function_default_cpu_type = "standard_legacy"
+ function_default_timeout = 30
+ }
}
data "vercel_project" "test" {
diff --git a/vercel/resource_project.go b/vercel/resource_project.go
index 609cab4a..7573deac 100644
--- a/vercel/resource_project.go
+++ b/vercel/resource_project.go
@@ -12,6 +12,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/boolplanmodifier"
+ "github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/objectdefault"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/objectplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
@@ -443,10 +444,77 @@ At this time you cannot use a Vercel Project resource with in-line ` + "`environ
stringOneOf("30 minutes", "12 hours", "1 day", "7 days"),
},
},
+ "resource_config": schema.SingleNestedAttribute{
+ Description: "Resource Configuration for the project.",
+ Optional: true,
+ 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).",
+ Optional: true,
+ Computed: true,
+ Validators: []validator.String{
+ stringOneOf("standard_legacy", "standard", "performance"),
+ },
+ PlanModifiers: []planmodifier.String{SuppressDiffIfNotConfigured(), stringplanmodifier.UseStateForUnknown()},
+ },
+ "function_default_timeout": schema.Int64Attribute{
+ Description: "The default timeout for Serverless Functions.",
+ Optional: true,
+ Computed: true,
+ Validators: []validator.Int64{
+ int64GreaterThan(0),
+ int64LessThan(901),
+ },
+ PlanModifiers: []planmodifier.Int64{SuppressDiffIfNotConfigured(), int64planmodifier.UseStateForUnknown()},
+ },
+ },
+ Default: objectdefault.StaticValue(types.ObjectValueMust(
+ map[string]attr.Type{
+ "function_default_cpu_type": types.StringType,
+ "function_default_timeout": types.Int64Type,
+ },
+ map[string]attr.Value{
+ "function_default_cpu_type": types.StringNull(),
+ "function_default_timeout": types.Int64Null(),
+ },
+ )),
+ },
},
}
}
+type suppressDiffIfNotConfigured struct{}
+
+func SuppressDiffIfNotConfigured() *suppressDiffIfNotConfigured {
+ return &suppressDiffIfNotConfigured{}
+}
+
+func (m *suppressDiffIfNotConfigured) Description(ctx context.Context) string {
+ return "Ensures that the diff is suppressed if the attribute is not explicitly configured by users."
+}
+
+func (m *suppressDiffIfNotConfigured) MarkdownDescription(ctx context.Context) string {
+ return m.Description(ctx)
+}
+
+func (m *suppressDiffIfNotConfigured) PlanModifyString(ctx context.Context, req planmodifier.StringRequest, resp *planmodifier.StringResponse) {
+ if req.ConfigValue.IsNull() {
+ resp.PlanValue = req.StateValue
+ resp.RequiresReplace = false
+ return
+ }
+}
+
+func (m *suppressDiffIfNotConfigured) PlanModifyInt64(ctx context.Context, req planmodifier.Int64Request, resp *planmodifier.Int64Response) {
+ if req.ConfigValue.IsNull() {
+ resp.PlanValue = req.StateValue
+ resp.RequiresReplace = false
+ return
+ }
+}
+
// Project reflects the state terraform stores internally for a project.
type Project struct {
BuildCommand types.String `tfsdk:"build_command"`
@@ -481,6 +549,7 @@ type Project 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"`
}
type GitComments struct {
@@ -514,7 +583,8 @@ func (p Project) RequiresUpdateAfterCreation() bool {
(!p.GitForkProtection.IsNull() && !p.GitForkProtection.ValueBool()) ||
!p.PrioritiseProductionBuilds.IsNull() ||
!p.DirectoryListing.IsNull() ||
- !p.SkewProtection.IsNull()
+ !p.SkewProtection.IsNull() ||
+ p.ResourceConfig != nil
}
var nullProject = Project{
@@ -640,6 +710,7 @@ func (p *Project) toUpdateProjectRequest(ctx context.Context, oldName string) (r
DirectoryListing: p.DirectoryListing.ValueBool(),
SkewProtectionMaxAge: toSkewProtectionAge(p.SkewProtection),
GitComments: gc.toUpdateProjectRequest(),
+ ResourceConfig: p.ResourceConfig.toUpdateProjectRequest(),
}, nil
}
@@ -832,6 +903,26 @@ func (o *OIDCTokenConfig) toUpdateProjectRequest() *client.OIDCTokenConfig {
}
}
+type ResourceConfig struct {
+ FunctionDefaultMemoryType types.String `tfsdk:"function_default_cpu_type"`
+ FunctionDefaultTimeout types.Int64 `tfsdk:"function_default_timeout"`
+}
+
+func (r *ResourceConfig) toUpdateProjectRequest() *client.ResourceConfig {
+ resourceConfig := &client.ResourceConfig{}
+ if r == nil {
+ return resourceConfig
+ }
+
+ if !r.FunctionDefaultMemoryType.IsNull() {
+ resourceConfig.FunctionDefaultMemoryType = r.FunctionDefaultMemoryType.ValueString()
+ }
+ if !r.FunctionDefaultTimeout.IsNull() {
+ resourceConfig.FunctionDefaultTimeout = r.FunctionDefaultTimeout.ValueInt64()
+ }
+ return resourceConfig
+}
+
func (t *OptionsAllowlist) toUpdateProjectRequest() *client.OptionsAllowlist {
if t == nil {
return nil
@@ -1039,6 +1130,16 @@ func convertResponseToProject(ctx context.Context, response client.ProjectRespon
oidcTokenConfig.Enabled = types.BoolValue(response.OIDCTokenConfig.Enabled)
}
+ resourceConfig := &ResourceConfig{}
+ if response.ResourceConfig != nil && plan.ResourceConfig != nil {
+ if !plan.ResourceConfig.FunctionDefaultMemoryType.IsNull() {
+ resourceConfig.FunctionDefaultMemoryType = types.StringValue(response.ResourceConfig.FunctionDefaultMemoryType)
+ }
+ if !plan.ResourceConfig.FunctionDefaultTimeout.IsNull() {
+ resourceConfig.FunctionDefaultTimeout = types.Int64Value(response.ResourceConfig.FunctionDefaultTimeout)
+ }
+ }
+
var oal *OptionsAllowlist
if response.OptionsAllowlist != nil {
var paths []OptionsAllowlistPath
@@ -1159,6 +1260,7 @@ func convertResponseToProject(ctx context.Context, response client.ProjectRespon
DirectoryListing: types.BoolValue(response.DirectoryListing),
SkewProtection: fromSkewProtectionMaxAge(response.SkewProtectionMaxAge),
GitComments: gitComments,
+ ResourceConfig: resourceConfig,
}, nil
}
diff --git a/vercel/resource_project_function_cpu.go b/vercel/resource_project_function_cpu.go
index 6b871498..31732b25 100644
--- a/vercel/resource_project_function_cpu.go
+++ b/vercel/resource_project_function_cpu.go
@@ -4,6 +4,7 @@ import (
"context"
"fmt"
+ "github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
@@ -53,7 +54,11 @@ func (r *projectFunctionCPUResource) Configure(ctx context.Context, req resource
// Schema returns the schema information for an alias resource.
func (r *projectFunctionCPUResource) Schema(_ context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
resp.Schema = schema.Schema{
- Description: `Provides a Function CPU resource for a Project.
+ DeprecationMessage: "This resource is deprecated and no longer works. Please use the `vercel_project` resource and its `resource_config` attribute instead.",
+ 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.
@@ -101,6 +106,10 @@ func convertResponseToProjectFunctionCPU(response client.ProjectFunctionCPU) Pro
}
func (r *projectFunctionCPUResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
+ resp.Diagnostics.Append(
+ diag.NewErrorDiagnostic("`vercel_project_function_cpu` resource deprecated", "use `vercel_project` resource and its `resource_config` attribute instead"),
+ )
+
var plan ProjectFunctionCPU
diags := req.Plan.Get(ctx, &plan)
resp.Diagnostics.Append(diags...)
@@ -136,6 +145,9 @@ func (r *projectFunctionCPUResource) Create(ctx context.Context, req resource.Cr
}
func (r *projectFunctionCPUResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
+ resp.Diagnostics.Append(
+ diag.NewErrorDiagnostic("`vercel_project_function_cpu` resource deprecated", "use `vercel_project` resource and its `resource_config` attribute instead"),
+ )
var state ProjectFunctionCPU
diags := req.State.Get(ctx, &state)
resp.Diagnostics.Append(diags...)
@@ -174,6 +186,9 @@ func (r *projectFunctionCPUResource) Read(ctx context.Context, req resource.Read
}
func (r *projectFunctionCPUResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
+ resp.Diagnostics.Append(
+ diag.NewErrorDiagnostic("`vercel_project_function_cpu` resource deprecated", "use `vercel_project` resource and its `resource_config` attribute instead"),
+ )
var plan ProjectFunctionCPU
diags := req.Plan.Get(ctx, &plan)
resp.Diagnostics.Append(diags...)
@@ -209,6 +224,9 @@ func (r *projectFunctionCPUResource) Update(ctx context.Context, req resource.Up
}
func (r *projectFunctionCPUResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
+ resp.Diagnostics.Append(
+ diag.NewErrorDiagnostic("`vercel_project_function_cpu` resource deprecated", "use `vercel_project` resource and its `resource_config` attribute instead"),
+ )
tflog.Info(ctx, "deleted project function cpu", map[string]interface{}{})
}
diff --git a/vercel/resource_project_function_cpu_test.go b/vercel/resource_project_function_cpu_test.go
index c34c0c1b..7713754e 100644
--- a/vercel/resource_project_function_cpu_test.go
+++ b/vercel/resource_project_function_cpu_test.go
@@ -10,6 +10,7 @@ import (
)
func TestAcc_ProjectFunctionCPUResource(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) },
diff --git a/vercel/resource_project_test.go b/vercel/resource_project_test.go
index e6bbf99c..1d1efcf3 100644
--- a/vercel/resource_project_test.go
+++ b/vercel/resource_project_test.go
@@ -8,7 +8,11 @@ import (
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
+ "github.com/hashicorp/terraform-plugin-testing/knownvalue"
+ "github.com/hashicorp/terraform-plugin-testing/plancheck"
+ "github.com/hashicorp/terraform-plugin-testing/statecheck"
"github.com/hashicorp/terraform-plugin-testing/terraform"
+ "github.com/hashicorp/terraform-plugin-testing/tfjsonpath"
"github.com/vercel/terraform-provider-vercel/client"
)
@@ -119,6 +123,75 @@ func TestAcc_ProjectAddingEnvAfterInitialCreation(t *testing.T) {
})
}
+func TestAcc_ProjectUpdateResourceConfig(t *testing.T) {
+ projectSuffix := acctest.RandString(16)
+ resource.Test(t, resource.TestCase{
+ PreCheck: func() { testAccPreCheck(t) },
+ ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
+ CheckDestroy: testAccProjectDestroy("vercel_project.test", testTeam()),
+ Steps: []resource.TestStep{
+ {
+ Config: testAccProjectConfigBase(projectSuffix, teamIDConfig()),
+ Check: resource.ComposeAggregateTestCheckFunc(
+ testAccProjectExists("vercel_project.test", testTeam()),
+ ),
+ ConfigStateChecks: []statecheck.StateCheck{
+ statecheck.ExpectKnownValue(
+ "vercel_project.test",
+ tfjsonpath.New("resource_config").AtMapKey("function_default_cpu_type"),
+ knownvalue.Null(),
+ ),
+ statecheck.ExpectKnownValue(
+ "vercel_project.test",
+ tfjsonpath.New("resource_config").AtMapKey("function_default_timeout"),
+ knownvalue.Null(),
+ ),
+ },
+ },
+ {
+ Config: testAccProjectConfigBase(projectSuffix, teamIDConfig()),
+ Check: resource.ComposeAggregateTestCheckFunc(
+ testAccProjectExists("vercel_project.test", testTeam()),
+ ),
+ ConfigPlanChecks: resource.ConfigPlanChecks{
+ PreApply: []plancheck.PlanCheck{
+ plancheck.ExpectEmptyPlan(),
+ },
+ },
+ },
+ {
+ Config: testAccProjectConfigWithResourceConfig(projectSuffix, teamIDConfig()),
+ Check: resource.ComposeAggregateTestCheckFunc(
+ testAccProjectExists("vercel_project.test", testTeam()),
+ ),
+ ConfigStateChecks: []statecheck.StateCheck{
+ statecheck.ExpectKnownValue(
+ "vercel_project.test",
+ tfjsonpath.New("resource_config").AtMapKey("function_default_cpu_type"),
+ knownvalue.StringExact("standard_legacy"),
+ ),
+ statecheck.ExpectKnownValue(
+ "vercel_project.test",
+ tfjsonpath.New("resource_config").AtMapKey("function_default_timeout"),
+ knownvalue.Int64Exact(30),
+ ),
+ },
+ },
+ {
+ Config: testAccProjectConfigWithResourceConfig(projectSuffix, teamIDConfig()),
+ Check: resource.ComposeAggregateTestCheckFunc(
+ testAccProjectExists("vercel_project.test", testTeam()),
+ ),
+ ConfigPlanChecks: resource.ConfigPlanChecks{
+ PreApply: []plancheck.PlanCheck{
+ plancheck.ExpectEmptyPlan(),
+ },
+ },
+ },
+ },
+ })
+}
+
func TestAcc_ProjectWithGitRepository(t *testing.T) {
projectSuffix := acctest.RandString(16)
resource.Test(t, resource.TestCase{
@@ -332,6 +405,28 @@ func testAccProjectDestroy(n, teamID string) resource.TestCheckFunc {
}
}
+func testAccProjectConfigBase(projectSuffix, teamID string) string {
+ return fmt.Sprintf(`
+resource "vercel_project" "test" {
+ name = "test-acc-two-%s"
+ %s
+}
+`, projectSuffix, teamID)
+}
+
+func testAccProjectConfigWithResourceConfig(projectSuffix, teamID string) string {
+ return fmt.Sprintf(`
+resource "vercel_project" "test" {
+ name = "test-acc-two-%s"
+ resource_config = {
+ function_default_cpu_type = "standard_legacy"
+ function_default_timeout = 30
+ }
+ %s
+}
+`, projectSuffix, teamID)
+}
+
func testAccProjectConfigWithoutEnv(projectSuffix, teamID string) string {
return fmt.Sprintf(`
resource "vercel_project" "test" {