From f3d2de4e083fd0ba11cf7e4fe8788862138ebd85 Mon Sep 17 00:00:00 2001
From: Shohei Maeda <11495867+smaeda-ks@users.noreply.github.com>
Date: Thu, 19 Sep 2024 22:07:39 +0900
Subject: [PATCH 01/10] Migrate `vercel_project_function_cpu` into
`vercel_project`
---
client/project.go | 8 +++
vercel/resource_project.go | 108 +++++++++++++++++++++++++++++++-
vercel/resource_project_test.go | 95 ++++++++++++++++++++++++++++
3 files changed, 210 insertions(+), 1 deletion(-)
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/vercel/resource_project.go b/vercel/resource_project.go
index 609cab4a..a584565e 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"
@@ -368,6 +369,11 @@ At this time you cannot use a Vercel Project resource with in-line ` + "`environ
"protection_bypass_for_automation_secret": schema.StringAttribute{
Computed: true,
Description: "If `protection_bypass_for_automation` is enabled, use this value in the `x-vercel-protection-bypass` header to bypass Vercel Authentication and Password Protection for both Preview and Production Deployments.",
+ // This is a read-only attribute. Avoid empty plans.
+ PlanModifiers: []planmodifier.String{
+ SuppressDiffIfNotConfigured(),
+ stringplanmodifier.UseStateForUnknown(),
+ },
},
"automatically_expose_system_environment_variables": schema.BoolAttribute{
Optional: true,
@@ -443,10 +449,76 @@ 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),
+ },
+ 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 +553,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 +587,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 +714,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 +907,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 +1134,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 +1264,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_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" {
From 0ba34f110570d455a303949542174cf76b805ff4 Mon Sep 17 00:00:00 2001
From: Shohei Maeda <11495867+smaeda-ks@users.noreply.github.com>
Date: Thu, 19 Sep 2024 22:22:56 +0900
Subject: [PATCH 02/10] deprecate resource
---
docs/resources/project_function_cpu.md | 46 +------------------------
vercel/resource_project_function_cpu.go | 15 ++++++++
2 files changed, 16 insertions(+), 45 deletions(-)
diff --git a/docs/resources/project_function_cpu.md b/docs/resources/project_function_cpu.md
index 92ef60af..e2124d28 100644
--- a/docs/resources/project_function_cpu.md
+++ b/docs/resources/project_function_cpu.md
@@ -10,48 +10,4 @@ description: |-
# vercel_project_function_cpu (Resource)
-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.
-
-## Example Usage
-
-```terraform
-resource "vercel_project" "example" {
- name = "example"
-}
-
-resource "vercel_project_function_cpu" "example" {
- project_id = vercel_project.example.id
- cpu = "performance"
-}
-```
-
-
-## Schema
-
-### Required
-
-- `cpu` (String) The amount of CPU available to your Serverless Functions. Should be one of 'basic' (0.6vCPU), 'standard' (1vCPU) or 'performance' (1.7vCPUs).
-- `project_id` (String) The ID of the Project to adjust the CPU 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.
-
-### Read-Only
-
-- `id` (String) The ID of the resource.
-
-## Import
-
-Import is supported using the following syntax:
-
-```shell
-# 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_function_cpu.example team_xxxxxxxxxxxxxxxxxxxxxxxx/prj_xxxxxxxxxxxxxxxxxxxxxxxxxxxx
-```
+~> This resource has been deprecated and no longer works. Please use the `vercel_project` resource and its `resource_config` attribute instead.
diff --git a/vercel/resource_project_function_cpu.go b/vercel/resource_project_function_cpu.go
index 6b871498..d6f039fb 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,6 +54,7 @@ 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{
+ DeprecationMessage: "This resource is deprecated and no longer works. Please use the `vercel_project` resource and its `resource_config` attribute instead.",
Description: `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 +103,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 +142,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 +183,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 +221,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{}{})
}
From 681e9064675ddfff8d2da6aabe4ab9d8844cd2c4 Mon Sep 17 00:00:00 2001
From: Shohei Maeda <11495867+smaeda-ks@users.noreply.github.com>
Date: Thu, 19 Sep 2024 22:25:24 +0900
Subject: [PATCH 03/10] deprecate data source
---
docs/data-sources/project_function_cpu.md | 32 +---------------------
vercel/data_source_project_function_cpu.go | 5 ++++
2 files changed, 6 insertions(+), 31 deletions(-)
diff --git a/docs/data-sources/project_function_cpu.md b/docs/data-sources/project_function_cpu.md
index 0e47dc70..a211e04f 100644
--- a/docs/data-sources/project_function_cpu.md
+++ b/docs/data-sources/project_function_cpu.md
@@ -9,34 +9,4 @@ description: |-
# vercel_project_function_cpu (Data Source)
-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.
-
-## Example Usage
-
-```terraform
-data "vercel_project" "example" {
- name = "example"
-}
-
-data "vercel_project_function_cpu" "example" {
- project_id = data.vercel_project.example.id
-}
-```
-
-
-## Schema
-
-### Required
-
-- `project_id` (String) The ID of the Project to read the Function CPU setting 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.
-
-### Read-Only
-
-- `cpu` (String) The amount of CPU available to your Serverless Functions. Should be one of 'basic' (0.6vCPU), 'standard' (1vCPU) or 'performance' (1.7vCPUs).
-- `id` (String) The ID of the resource.
+~> This data source has been deprecated and no longer works. Please use the `vercel_project` data source and its `resource_config` attribute instead.
diff --git a/vercel/data_source_project_function_cpu.go b/vercel/data_source_project_function_cpu.go
index 8b4a77a3..94e6ef60 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,6 +49,7 @@ 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{
+ DeprecationMessage: "This data source is deprecated and no longer works. Please use the `vercel_project` data source and its `resource_config` attribute instead.",
Description: `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 +77,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...)
From 7978e896ef85db8dfb9c8ea2c037709b1cf51b61 Mon Sep 17 00:00:00 2001
From: Shohei Maeda <11495867+smaeda-ks@users.noreply.github.com>
Date: Thu, 19 Sep 2024 22:47:06 +0900
Subject: [PATCH 04/10] update data source
---
vercel/data_source_project.go | 25 +++++++++++++++++++++++++
vercel/data_source_project_test.go | 6 ++++++
2 files changed, 31 insertions(+)
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_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" {
From ad207ce0f23d5034e08f8bd8f9ce1b813fb86e15 Mon Sep 17 00:00:00 2001
From: Shohei Maeda <11495867+smaeda-ks@users.noreply.github.com>
Date: Thu, 19 Sep 2024 22:59:10 +0900
Subject: [PATCH 05/10] docs
---
docs/data-sources/project.md | 10 +++++
docs/data-sources/project_function_cpu.md | 32 +++++++++++++++
docs/resources/project.md | 10 +++++
docs/resources/project_function_cpu.md | 48 ++++++++++++++++++++++-
4 files changed, 99 insertions(+), 1 deletion(-)
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 a211e04f..5e4a45b7 100644
--- a/docs/data-sources/project_function_cpu.md
+++ b/docs/data-sources/project_function_cpu.md
@@ -10,3 +10,35 @@ description: |-
# 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.
+
+## Example Usage
+
+```terraform
+data "vercel_project" "example" {
+ name = "example"
+}
+
+data "vercel_project_function_cpu" "example" {
+ project_id = data.vercel_project.example.id
+}
+```
+
+
+## Schema
+
+### Required
+
+- `project_id` (String) The ID of the Project to read the Function CPU setting 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.
+
+### Read-Only
+
+- `cpu` (String) The amount of CPU available to your Serverless Functions. Should be one of 'basic' (0.6vCPU), 'standard' (1vCPU) or 'performance' (1.7vCPUs).
+- `id` (String) The ID of the resource.
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 e2124d28..2deb3516 100644
--- a/docs/resources/project_function_cpu.md
+++ b/docs/resources/project_function_cpu.md
@@ -10,4 +10,50 @@ 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.
+~> This data source has been deprecated and no longer works. Please use the `vercel_project` data source 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.
+
+## Example Usage
+
+```terraform
+resource "vercel_project" "example" {
+ name = "example"
+}
+
+resource "vercel_project_function_cpu" "example" {
+ project_id = vercel_project.example.id
+ cpu = "performance"
+}
+```
+
+
+## Schema
+
+### Required
+
+- `cpu` (String) The amount of CPU available to your Serverless Functions. Should be one of 'basic' (0.6vCPU), 'standard' (1vCPU) or 'performance' (1.7vCPUs).
+- `project_id` (String) The ID of the Project to adjust the CPU 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.
+
+### Read-Only
+
+- `id` (String) The ID of the resource.
+
+## Import
+
+Import is supported using the following syntax:
+
+```shell
+# 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_function_cpu.example team_xxxxxxxxxxxxxxxxxxxxxxxx/prj_xxxxxxxxxxxxxxxxxxxxxxxxxxxx
+```
From 84259e5727e951902a3026ae8a88dd8a12faae5f Mon Sep 17 00:00:00 2001
From: Shohei Maeda <11495867+smaeda-ks@users.noreply.github.com>
Date: Thu, 19 Sep 2024 22:59:20 +0900
Subject: [PATCH 06/10] skip deprecated tests
---
vercel/data_source_project_function_cpu_test.go | 1 +
vercel/resource_project_function_cpu_test.go | 1 +
2 files changed, 2 insertions(+)
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/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) },
From da2a16b75b16bb9c632a4027fb83fc0c2d36c8b9 Mon Sep 17 00:00:00 2001
From: Shohei Maeda <11495867+smaeda-ks@users.noreply.github.com>
Date: Thu, 19 Sep 2024 23:11:56 +0900
Subject: [PATCH 07/10] docs
---
docs/resources/project_function_cpu.md | 2 +-
vercel/data_source_project_function_cpu.go | 5 ++++-
vercel/resource_project_function_cpu.go | 5 ++++-
3 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/docs/resources/project_function_cpu.md b/docs/resources/project_function_cpu.md
index 2deb3516..d827bf52 100644
--- a/docs/resources/project_function_cpu.md
+++ b/docs/resources/project_function_cpu.md
@@ -10,7 +10,7 @@ description: |-
# vercel_project_function_cpu (Resource)
-~> This data source has been deprecated and no longer works. Please use the `vercel_project` data source and its `resource_config` attribute instead.
+~> 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.
diff --git a/vercel/data_source_project_function_cpu.go b/vercel/data_source_project_function_cpu.go
index 94e6ef60..701fe2e1 100644
--- a/vercel/data_source_project_function_cpu.go
+++ b/vercel/data_source_project_function_cpu.go
@@ -50,7 +50,10 @@ 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{
DeprecationMessage: "This data source is deprecated and no longer works. Please use the `vercel_project` data source and its `resource_config` attribute instead.",
- Description: `Provides information about a Project's Function CPU setting.
+ 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.
`,
diff --git a/vercel/resource_project_function_cpu.go b/vercel/resource_project_function_cpu.go
index d6f039fb..31732b25 100644
--- a/vercel/resource_project_function_cpu.go
+++ b/vercel/resource_project_function_cpu.go
@@ -55,7 +55,10 @@ func (r *projectFunctionCPUResource) Configure(ctx context.Context, req resource
func (r *projectFunctionCPUResource) Schema(_ context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
resp.Schema = schema.Schema{
DeprecationMessage: "This resource is deprecated and no longer works. Please use the `vercel_project` resource and its `resource_config` attribute instead.",
- Description: `Provides a Function CPU resource for a Project.
+ 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.
From 433b9d47df64c0ca4a921f294fabbea9a23faaf1 Mon Sep 17 00:00:00 2001
From: Shohei Maeda <11495867+smaeda-ks@users.noreply.github.com>
Date: Thu, 19 Sep 2024 23:14:13 +0900
Subject: [PATCH 08/10] remove change
---
vercel/resource_project.go | 5 -----
1 file changed, 5 deletions(-)
diff --git a/vercel/resource_project.go b/vercel/resource_project.go
index a584565e..bebdd680 100644
--- a/vercel/resource_project.go
+++ b/vercel/resource_project.go
@@ -369,11 +369,6 @@ At this time you cannot use a Vercel Project resource with in-line ` + "`environ
"protection_bypass_for_automation_secret": schema.StringAttribute{
Computed: true,
Description: "If `protection_bypass_for_automation` is enabled, use this value in the `x-vercel-protection-bypass` header to bypass Vercel Authentication and Password Protection for both Preview and Production Deployments.",
- // This is a read-only attribute. Avoid empty plans.
- PlanModifiers: []planmodifier.String{
- SuppressDiffIfNotConfigured(),
- stringplanmodifier.UseStateForUnknown(),
- },
},
"automatically_expose_system_environment_variables": schema.BoolAttribute{
Optional: true,
From a9d82fc197a29ff572b73725d35267ea821171c6 Mon Sep 17 00:00:00 2001
From: Shohei Maeda <11495867+smaeda-ks@users.noreply.github.com>
Date: Thu, 19 Sep 2024 23:40:07 +0900
Subject: [PATCH 09/10] docs
---
docs/data-sources/project_function_cpu.md | 1 +
docs/resources/project_function_cpu.md | 1 +
2 files changed, 2 insertions(+)
diff --git a/docs/data-sources/project_function_cpu.md b/docs/data-sources/project_function_cpu.md
index 5e4a45b7..0f948eb3 100644
--- a/docs/data-sources/project_function_cpu.md
+++ b/docs/data-sources/project_function_cpu.md
@@ -3,6 +3,7 @@
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.
---
diff --git a/docs/resources/project_function_cpu.md b/docs/resources/project_function_cpu.md
index d827bf52..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.
From 7cae2d49649722262b8897acc17de5ee2f0bce7b Mon Sep 17 00:00:00 2001
From: Shohei Maeda <11495867+smaeda-ks@users.noreply.github.com>
Date: Fri, 20 Sep 2024 17:52:09 +0900
Subject: [PATCH 10/10] feedback
---
vercel/resource_project.go | 1 +
1 file changed, 1 insertion(+)
diff --git a/vercel/resource_project.go b/vercel/resource_project.go
index bebdd680..7573deac 100644
--- a/vercel/resource_project.go
+++ b/vercel/resource_project.go
@@ -465,6 +465,7 @@ At this time you cannot use a Vercel Project resource with in-line ` + "`environ
Computed: true,
Validators: []validator.Int64{
int64GreaterThan(0),
+ int64LessThan(901),
},
PlanModifiers: []planmodifier.Int64{SuppressDiffIfNotConfigured(), int64planmodifier.UseStateForUnknown()},
},