From 9400f12c981ce50f19fee1e42fdc74e384ac10d6 Mon Sep 17 00:00:00 2001 From: Florentin Eckl Date: Mon, 16 Sep 2024 17:35:12 +0200 Subject: [PATCH 1/5] add support for default project max duration --- client/project_function_max_duration.go | 82 ++++++ .../import.sh | 4 + .../resource.tf | 8 + ...ta_source_project_function_max_duration.go | 118 ++++++++ ...urce_project_function_max_duration_test.go | 45 ++++ .../resource_project_function_max_duration.go | 253 ++++++++++++++++++ ...urce_project_function_max_duration_test.go | 73 +++++ 7 files changed, 583 insertions(+) create mode 100644 client/project_function_max_duration.go create mode 100644 examples/resources/vercel_project_function_max_duration/import.sh create mode 100644 examples/resources/vercel_project_function_max_duration/resource.tf create mode 100644 vercel/data_source_project_function_max_duration.go create mode 100644 vercel/data_source_project_function_max_duration_test.go create mode 100644 vercel/resource_project_function_max_duration.go create mode 100644 vercel/resource_project_function_max_duration_test.go diff --git a/client/project_function_max_duration.go b/client/project_function_max_duration.go new file mode 100644 index 00000000..117d4a0b --- /dev/null +++ b/client/project_function_max_duration.go @@ -0,0 +1,82 @@ +package client + +import ( + "context" + "fmt" + + "github.com/hashicorp/terraform-plugin-log/tflog" +) + +type ProjectFunctionMaxDurationRequest struct { + ProjectID string + TeamID string + MaxDuration int64 +} + +type functionMaxDuration struct { + DefaultFunctionTimeout *int64 `json:"defaultFunctionTimeout"` +} + +type ProjectFunctionMaxDuration struct { + ProjectID string + TeamID string + MaxDuration *int64 +} + +func (c *Client) GetProjectFunctionMaxDuration(ctx context.Context, projectID, teamID string) (p ProjectFunctionMaxDuration, err error) { + url := fmt.Sprintf("%s/v1/projects/%s/resource-config", c.baseURL, projectID) + if c.teamID(teamID) != "" { + url = fmt.Sprintf("%s?teamId=%s", url, c.teamID(teamID)) + } + tflog.Info(ctx, "get project function max duration", map[string]interface{}{ + "url": url, + }) + var f functionMaxDuration + err = c.doRequest(clientRequest{ + ctx: ctx, + method: "GET", + url: url, + }, &f) + if err != nil { + return p, err + } + var maxDuration *int64 + if f.DefaultFunctionTimeout != nil { + maxDuration = f.DefaultFunctionTimeout + } + return ProjectFunctionMaxDuration{ + ProjectID: projectID, + TeamID: teamID, + MaxDuration: maxDuration, + }, err +} + +func (c *Client) UpdateProjectFunctionMaxDuration(ctx context.Context, request ProjectFunctionMaxDurationRequest) (p ProjectFunctionMaxDuration, err error) { + url := fmt.Sprintf("%s/v1/projects/%s/resource-config", c.baseURL, request.ProjectID) + if c.teamID(request.TeamID) != "" { + url = fmt.Sprintf("%s?teamId=%s", url, c.teamID(request.TeamID)) + } + + payload := string(mustMarshal(functionMaxDuration{ + DefaultFunctionTimeout: &request.MaxDuration, + })) + var f functionMaxDuration + err = c.doRequest(clientRequest{ + ctx: ctx, + method: "PATCH", + url: url, + body: payload, + }, &f) + if err != nil { + return p, err + } + var maxDuration *int64 + if f.DefaultFunctionTimeout != nil { + maxDuration = f.DefaultFunctionTimeout + } + return ProjectFunctionMaxDuration{ + ProjectID: request.ProjectID, + TeamID: request.TeamID, + MaxDuration: maxDuration, + }, err +} diff --git a/examples/resources/vercel_project_function_max_duration/import.sh b/examples/resources/vercel_project_function_max_duration/import.sh new file mode 100644 index 00000000..bcc4c6f8 --- /dev/null +++ b/examples/resources/vercel_project_function_max_duration/import.sh @@ -0,0 +1,4 @@ +# 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_max_duration.example team_xxxxxxxxxxxxxxxxxxxxxxxx/prj_xxxxxxxxxxxxxxxxxxxxxxxxxxxx diff --git a/examples/resources/vercel_project_function_max_duration/resource.tf b/examples/resources/vercel_project_function_max_duration/resource.tf new file mode 100644 index 00000000..65dbc5f7 --- /dev/null +++ b/examples/resources/vercel_project_function_max_duration/resource.tf @@ -0,0 +1,8 @@ +resource "vercel_project" "example" { + name = "example" +} + +resource "vercel_project_function_max_duration" "example" { + project_id = vercel_project.example.id + max_duration = 100 +} diff --git a/vercel/data_source_project_function_max_duration.go b/vercel/data_source_project_function_max_duration.go new file mode 100644 index 00000000..af6b4688 --- /dev/null +++ b/vercel/data_source_project_function_max_duration.go @@ -0,0 +1,118 @@ +package vercel + +import ( + "context" + "fmt" + + "github.com/hashicorp/terraform-plugin-framework/datasource" + "github.com/hashicorp/terraform-plugin-framework/datasource/schema" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" + "github.com/hashicorp/terraform-plugin-log/tflog" + "github.com/vercel/terraform-provider-vercel/client" +) + +// Ensure the implementation satisfies the expected interfaces. +var ( + _ datasource.DataSource = &projectFunctionMaxDurationDataSource{} + _ datasource.DataSourceWithConfigure = &projectFunctionMaxDurationDataSource{} +) + +func newProjectFunctionMaxDurationDataSource() datasource.DataSource { + return &projectFunctionMaxDurationDataSource{} +} + +type projectFunctionMaxDurationDataSource struct { + client *client.Client +} + +func (d *projectFunctionMaxDurationDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_project_function_max_duration" +} + +func (d *projectFunctionMaxDurationDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { + // Prevent panic if the provider has not been configured. + if req.ProviderData == nil { + return + } + + client, ok := req.ProviderData.(*client.Client) + if !ok { + resp.Diagnostics.AddError( + "Unexpected Data Source Configure Type", + fmt.Sprintf("Expected *client.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData), + ) + return + } + + d.client = client +} + +func (r *projectFunctionMaxDurationDataSource) Schema(_ context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { + resp.Schema = schema.Schema{ + Description: `Provides information about a Project's Function max duration setting. + +This controls the default maximum duration of your Serverless Functions can use while executing. 10s is recommended for most workloads. Can be configured from 1 to 900 seconds (plan limits apply). You can override this per function using the vercel.json file. +`, + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + Description: "The ID of the resource.", + Computed: true, + }, + "project_id": schema.StringAttribute{ + Description: "The ID of the Project to read the Function max duration setting for.", + Required: true, + }, + "team_id": schema.StringAttribute{ + Optional: true, + Computed: true, + Description: "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.", + }, + "max_duration": schema.Int64Attribute{ + Description: "The default max duration for your Serverless Functions. Must be between 1 and 900 (plan limits apply)", + Computed: true, + Validators: []validator.Int64{ + int64GreaterThan(0), + int64LessThan(900), + }, + }, + }, + } +} + +func (d *projectFunctionMaxDurationDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + var config ProjectFunctionMaxDuration + diags := req.Config.Get(ctx, &config) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + out, err := d.client.GetProjectFunctionMaxDuration(ctx, config.ProjectID.ValueString(), config.TeamID.ValueString()) + if client.NotFound(err) { + resp.State.RemoveResource(ctx) + return + } + if err != nil { + resp.Diagnostics.AddError( + "Error reading project Function max duration", + fmt.Sprintf("Could not get Project Function max duration %s %s, unexpected error: %s", + config.TeamID.ValueString(), + config.ProjectID.ValueString(), + err, + ), + ) + return + } + + result := convertResponseToProjectFunctionMaxDuration(out) + tflog.Info(ctx, "read project function max duration", map[string]interface{}{ + "team_id": result.TeamID.ValueString(), + "project_id": result.ProjectID.ValueString(), + }) + + diags = resp.State.Set(ctx, result) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } +} diff --git a/vercel/data_source_project_function_max_duration_test.go b/vercel/data_source_project_function_max_duration_test.go new file mode 100644 index 00000000..0f7d1921 --- /dev/null +++ b/vercel/data_source_project_function_max_duration_test.go @@ -0,0 +1,45 @@ +package vercel_test + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/acctest" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" +) + +func TestAcc_ProjectFunctionMaxDurationDataSource(t *testing.T) { + name := acctest.RandString(16) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccProjectFunctionMaxDurationDataSourceConfig(name, teamIDConfig()), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("data.vercel_project_function_max_duration.elevated", "max_duration", "100"), + ), + }, + }, + }) +} + +func testAccProjectFunctionMaxDurationDataSourceConfig(name, teamID string) string { + return fmt.Sprintf(` +resource "vercel_project" "elevated" { + name = "test-acc-%[1]s" + %[2]s +} + +resource "vercel_project_function_cpu" "elevated" { + project_id = vercel_project.elevated.id + max_duration = "100" + %[2]s +} + +data "vercel_project_function_cpu" "elevated" { + project_id = vercel_project_function_cpu.elevated.project_id + %[2]s +} +`, name, teamID) +} diff --git a/vercel/resource_project_function_max_duration.go b/vercel/resource_project_function_max_duration.go new file mode 100644 index 00000000..04f2d27f --- /dev/null +++ b/vercel/resource_project_function_max_duration.go @@ -0,0 +1,253 @@ +package vercel + +import ( + "context" + "fmt" + + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" + "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/hashicorp/terraform-plugin-log/tflog" + "github.com/vercel/terraform-provider-vercel/client" +) + +// Ensure the implementation satisfies the expected interfaces. +var ( + _ resource.Resource = &projectFunctionMaxDurationResource{} + _ resource.ResourceWithConfigure = &projectFunctionMaxDurationResource{} + _ resource.ResourceWithImportState = &projectFunctionMaxDurationResource{} +) + +func newProjectFunctionMaxDurationResource() resource.Resource { + return &projectFunctionMaxDurationResource{} +} + +type projectFunctionMaxDurationResource struct { + client *client.Client +} + +func (r *projectFunctionMaxDurationResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_project_function_max_duration" +} + +func (r *projectFunctionMaxDurationResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { + // Prevent panic if the provider has not been configured. + if req.ProviderData == nil { + return + } + + client, ok := req.ProviderData.(*client.Client) + if !ok { + resp.Diagnostics.AddError( + "Unexpected Resource Configure Type", + fmt.Sprintf("Expected *client.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData), + ) + return + } + + r.client = client +} + +// Schema returns the schema information for an alias resource. +func (r *projectFunctionMaxDurationResource) Schema(_ context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { + resp.Schema = schema.Schema{ + Description: `Provides a Function Max Duration resource for a Project. + +This controls the default maximum duration of your Serverless Functions can use while executing. 10s is recommended for most workloads. Can be configured from 1 to 900 seconds (plan limits apply). You can override this per function using the vercel.json file. + +A new Deployment is required for your changes to take effect. +`, + Attributes: map[string]schema.Attribute{ + "id": schema.StringAttribute{ + Description: "The ID of the resource.", + Computed: true, + PlanModifiers: []planmodifier.String{stringplanmodifier.UseStateForUnknown()}, + }, + "project_id": schema.StringAttribute{ + Description: "The ID of the Project to adjust the max duration for.", + Required: true, + PlanModifiers: []planmodifier.String{stringplanmodifier.RequiresReplace()}, + }, + "team_id": schema.StringAttribute{ + Optional: true, + Computed: true, + Description: "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.", + PlanModifiers: []planmodifier.String{stringplanmodifier.RequiresReplaceIfConfigured(), stringplanmodifier.UseStateForUnknown()}, + }, + "max_duration": schema.Int64Attribute{ + Description: "The default max duration for your Serverless Functions. Must be between 1 and 900 (plan limits apply)", + Required: true, + Validators: []validator.Int64{ + int64GreaterThan(1), + int64LessThan(900), + }, + }, + }, + } +} + +type ProjectFunctionMaxDuration struct { + ID types.String `tfsdk:"id"` + ProjectID types.String `tfsdk:"project_id"` + TeamID types.String `tfsdk:"team_id"` + MaxDuration types.Int64 `tfsdk:"max_duration"` +} + +func convertResponseToProjectFunctionMaxDuration(response client.ProjectFunctionMaxDuration) ProjectFunctionMaxDuration { + return ProjectFunctionMaxDuration{ + ID: types.StringValue(response.ProjectID), + TeamID: toTeamID(response.TeamID), + ProjectID: types.StringValue(response.ProjectID), + MaxDuration: types.Int64PointerValue(response.MaxDuration), + } +} + +func (r *projectFunctionMaxDurationResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + var plan ProjectFunctionMaxDuration + diags := req.Plan.Get(ctx, &plan) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + out, err := r.client.UpdateProjectFunctionMaxDuration(ctx, client.ProjectFunctionMaxDurationRequest{ + ProjectID: plan.ProjectID.ValueString(), + TeamID: plan.TeamID.ValueString(), + MaxDuration: plan.MaxDuration.ValueInt64(), + }) + if err != nil { + resp.Diagnostics.AddError( + "Error updating project Function max duration", + "Could not update function max duration, unexpected error: "+err.Error(), + ) + return + } + + result := convertResponseToProjectFunctionMaxDuration(out) + tflog.Info(ctx, "created project function max duration", map[string]interface{}{ + "team_id": plan.TeamID.ValueString(), + "project_id": plan.ProjectID.ValueString(), + "max_duration": result.MaxDuration.ValueInt64(), + }) + + diags = resp.State.Set(ctx, result) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } +} + +func (r *projectFunctionMaxDurationResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + var state ProjectFunctionMaxDuration + diags := req.State.Get(ctx, &state) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + out, err := r.client.GetProjectFunctionMaxDuration(ctx, state.ProjectID.ValueString(), state.TeamID.ValueString()) + if client.NotFound(err) { + resp.State.RemoveResource(ctx) + return + } + if err != nil { + resp.Diagnostics.AddError( + "Error reading project Function max duration", + fmt.Sprintf("Could not get Project Function max duration %s %s, unexpected error: %s", + state.TeamID.ValueString(), + state.ProjectID.ValueString(), + err, + ), + ) + return + } + + result := convertResponseToProjectFunctionMaxDuration(out) + tflog.Info(ctx, "read project function max duration", map[string]interface{}{ + "team_id": result.TeamID.ValueString(), + "project_id": result.ProjectID.ValueString(), + }) + + diags = resp.State.Set(ctx, result) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } +} + +func (r *projectFunctionMaxDurationResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + var plan ProjectFunctionMaxDuration + diags := req.Plan.Get(ctx, &plan) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + out, err := r.client.UpdateProjectFunctionMaxDuration(ctx, client.ProjectFunctionMaxDurationRequest{ + ProjectID: plan.ProjectID.ValueString(), + TeamID: plan.TeamID.ValueString(), + MaxDuration: plan.MaxDuration.ValueInt64(), + }) + if err != nil { + resp.Diagnostics.AddError( + "Error updating project Function max duration", + "Could not update function max duration, unexpected error: "+err.Error(), + ) + return + } + + result := convertResponseToProjectFunctionMaxDuration(out) + tflog.Info(ctx, "created project function max duration", map[string]interface{}{ + "team_id": plan.TeamID.ValueString(), + "project_id": plan.ProjectID.ValueString(), + "max_duration": result.MaxDuration.ValueInt64(), + }) + + diags = resp.State.Set(ctx, result) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } +} + +func (r *projectFunctionMaxDurationResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { + tflog.Info(ctx, "deleted project function max duration", map[string]interface{}{}) +} + +func (r *projectFunctionMaxDurationResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { + teamID, projectID, ok := splitInto1Or2(req.ID) + if !ok { + resp.Diagnostics.AddError( + "Error importing Project Function Max Duration", + fmt.Sprintf("Invalid id '%s' specified. should be in format \"team_id/project_id\" or \"project_id\"", req.ID), + ) + } + + out, err := r.client.GetProjectFunctionMaxDuration(ctx, projectID, teamID) + if err != nil { + resp.Diagnostics.AddError( + "Error reading Project Function max duration", + fmt.Sprintf("Could not get Project Function Max Duration %s %s, unexpected error: %s", + teamID, + projectID, + err, + ), + ) + return + } + + result := convertResponseToProjectFunctionMaxDuration(out) + tflog.Info(ctx, "import project function max duration", map[string]interface{}{ + "team_id": result.TeamID.ValueString(), + "project_id": result.ProjectID.ValueString(), + }) + + diags := resp.State.Set(ctx, result) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } +} diff --git a/vercel/resource_project_function_max_duration_test.go b/vercel/resource_project_function_max_duration_test.go new file mode 100644 index 00000000..99adc593 --- /dev/null +++ b/vercel/resource_project_function_max_duration_test.go @@ -0,0 +1,73 @@ +package vercel_test + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/acctest" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" +) + +func TestAcc_ProjectFunctionMaxDurationResource(t *testing.T) { + name := acctest.RandString(16) + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccProjectFunctionMaxDurationResourceConfig(name, teamIDConfig()), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("vercel_project_function_max_duration.elevated", "max_duration", "elevated"), + ), + }, + { + ImportState: true, + ResourceName: "vercel_project_function_max_duration.elevated", + ImportStateIdFunc: func(s *terraform.State) (string, error) { + rs, ok := s.RootModule().Resources["vercel_project_function_max_duration.elevated"] + if !ok { + return "", fmt.Errorf("resource not found") + } + return fmt.Sprintf("%s/%s", rs.Primary.Attributes["team_id"], rs.Primary.ID), nil + }, + }, + { + Config: testAccProjectFunctionMaxDurationResourceConfigUpdated(name, teamIDConfig()), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("vercel_project_function_max_duration.elevated", "max_duration", "performance"), + ), + }, + }, + }) +} + +func testAccProjectFunctionMaxDurationResourceConfig(name, teamID string) string { + return fmt.Sprintf(` +resource "vercel_project" "elevated" { + name = "test-acc-%[1]s" + %[2]s +} + +resource "vercel_project_function_max_duration" "elevated" { + project_id = vercel_project.elevated.id + max_duration = "100" + %[2]s +} +`, name, teamID) +} + +func testAccProjectFunctionMaxDurationResourceConfigUpdated(name, teamID string) string { + return fmt.Sprintf(` +resource "vercel_project" "elevated" { + name = "test-acc-%[1]s" + %[2]s +} + +resource "vercel_project_function_max_duration" "elevated" { + project_id = vercel_project.elevated.id + max_duration = 100 + %[2]s +} +`, name, teamID) +} From 3d6a5bab672a6454649066366a6d650d6071f986 Mon Sep 17 00:00:00 2001 From: Florentin Eckl Date: Mon, 16 Sep 2024 17:41:31 +0200 Subject: [PATCH 2/5] mv str to int --- vercel/data_source_project_function_max_duration_test.go | 2 +- vercel/resource_project_function_max_duration_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/vercel/data_source_project_function_max_duration_test.go b/vercel/data_source_project_function_max_duration_test.go index 0f7d1921..b4aad976 100644 --- a/vercel/data_source_project_function_max_duration_test.go +++ b/vercel/data_source_project_function_max_duration_test.go @@ -33,7 +33,7 @@ resource "vercel_project" "elevated" { resource "vercel_project_function_cpu" "elevated" { project_id = vercel_project.elevated.id - max_duration = "100" + max_duration = 100 %[2]s } diff --git a/vercel/resource_project_function_max_duration_test.go b/vercel/resource_project_function_max_duration_test.go index 99adc593..6d60ef1c 100644 --- a/vercel/resource_project_function_max_duration_test.go +++ b/vercel/resource_project_function_max_duration_test.go @@ -51,7 +51,7 @@ resource "vercel_project" "elevated" { resource "vercel_project_function_max_duration" "elevated" { project_id = vercel_project.elevated.id - max_duration = "100" + max_duration = 100 %[2]s } `, name, teamID) From 2e0911cdd0368590dc254d75348379800926c2b6 Mon Sep 17 00:00:00 2001 From: Florentin Eckl Date: Mon, 16 Sep 2024 17:42:57 +0200 Subject: [PATCH 3/5] add resource and data source to provider --- vercel/provider.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/vercel/provider.go b/vercel/provider.go index bbcb7695..fbb5875d 100644 --- a/vercel/provider.go +++ b/vercel/provider.go @@ -62,6 +62,7 @@ func (p *vercelProvider) Resources(_ context.Context) []func() resource.Resource newProjectDomainResource, newProjectEnvironmentVariableResource, newProjectFunctionCPUResource, + newProjectFunctionMaxDurationResource, newProjectResource, newSharedEnvironmentVariableResource, newWebhookResource, @@ -84,6 +85,7 @@ func (p *vercelProvider) DataSources(_ context.Context) []func() datasource.Data newProjectDeploymentRetentionDataSource, newProjectDirectoryDataSource, newProjectFunctionCPUDataSource, + newProjectFunctionMaxDurationDataSource, newSharedEnvironmentVariableDataSource, } } From 4462956487bdebb3c2dc8d92aff45f2ef2fd1f4f Mon Sep 17 00:00:00 2001 From: Florentin Eckl Date: Mon, 16 Sep 2024 17:57:51 +0200 Subject: [PATCH 4/5] add docs --- .../project_function_max_duration.md | 32 +++++++++++ .../project_function_max_duration.md | 57 +++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 docs/data-sources/project_function_max_duration.md create mode 100644 docs/resources/project_function_max_duration.md diff --git a/docs/data-sources/project_function_max_duration.md b/docs/data-sources/project_function_max_duration.md new file mode 100644 index 00000000..cf763dd8 --- /dev/null +++ b/docs/data-sources/project_function_max_duration.md @@ -0,0 +1,32 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "vercel_project_function_max_duration Data Source - terraform-provider-vercel" +subcategory: "" +description: |- + Provides information about a Project's Function max duration setting. + This controls the default maximum duration of your Serverless Functions can use while executing. 10s is recommended for most workloads. Can be configured from 1 to 900 seconds (plan limits apply). You can override this per function using the vercel.json file. +--- + +# vercel_project_function_max_duration (Data Source) + +Provides information about a Project's Function max duration setting. + +This controls the default maximum duration of your Serverless Functions can use while executing. 10s is recommended for most workloads. Can be configured from 1 to 900 seconds (plan limits apply). You can override this per function using the vercel.json file. + + + + +## Schema + +### Required + +- `project_id` (String) The ID of the Project to read the Function max duration 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 + +- `id` (String) The ID of the resource. +- `max_duration` (Number) The default max duration for your Serverless Functions. Must be between 1 and 900 (plan limits apply) diff --git a/docs/resources/project_function_max_duration.md b/docs/resources/project_function_max_duration.md new file mode 100644 index 00000000..04fb101c --- /dev/null +++ b/docs/resources/project_function_max_duration.md @@ -0,0 +1,57 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "vercel_project_function_max_duration Resource - terraform-provider-vercel" +subcategory: "" +description: |- + Provides a Function Max Duration resource for a Project. + This controls the default maximum duration of your Serverless Functions can use while executing. 10s is recommended for most workloads. Can be configured from 1 to 900 seconds (plan limits apply). 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_max_duration (Resource) + +Provides a Function Max Duration resource for a Project. + +This controls the default maximum duration of your Serverless Functions can use while executing. 10s is recommended for most workloads. Can be configured from 1 to 900 seconds (plan limits apply). 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_max_duration" "example" { + project_id = vercel_project.example.id + max_duration = 100 +} +``` + + +## Schema + +### Required + +- `max_duration` (Number) The default max duration for your Serverless Functions. Must be between 1 and 900 (plan limits apply) +- `project_id` (String) The ID of the Project to adjust the max duration 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_max_duration.example team_xxxxxxxxxxxxxxxxxxxxxxxx/prj_xxxxxxxxxxxxxxxxxxxxxxxxxxxx +``` From a4422fa6f8180d3a089e7121d8c6b9fec45ed34b Mon Sep 17 00:00:00 2001 From: Florentin Eckl Date: Tue, 17 Sep 2024 10:31:04 +0200 Subject: [PATCH 5/5] fix --- vercel/data_source_project_function_max_duration_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/vercel/data_source_project_function_max_duration_test.go b/vercel/data_source_project_function_max_duration_test.go index b4aad976..e5d54f2e 100644 --- a/vercel/data_source_project_function_max_duration_test.go +++ b/vercel/data_source_project_function_max_duration_test.go @@ -31,14 +31,14 @@ resource "vercel_project" "elevated" { %[2]s } -resource "vercel_project_function_cpu" "elevated" { +resource "vercel_project_function_max_duration" "elevated" { project_id = vercel_project.elevated.id max_duration = 100 %[2]s } -data "vercel_project_function_cpu" "elevated" { - project_id = vercel_project_function_cpu.elevated.project_id +data "vercel_project_function_max_duration" "elevated" { + project_id = vercel_project_function_max_duration.elevated.project_id %[2]s } `, name, teamID)