Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support node_version on vercel_project resource + data source #285

Merged
merged 1 commit into from
Mar 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions client/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ type ProjectResponse struct {
Security *Security `json:"security"`
DeploymentExpiration *DeploymentExpiration `json:"deploymentExpiration"`
ResourceConfig *ResourceConfig `json:"resourceConfig"`
NodeVersion string `json:"nodeVersion"`
}

type GitComments struct {
Expand Down Expand Up @@ -304,6 +305,7 @@ type UpdateProjectRequest struct {
SkewProtectionMaxAge int `json:"skewProtectionMaxAge"`
GitComments *GitComments `json:"gitComments"`
ResourceConfig *ResourceConfig `json:"resourceConfig,omitempty"`
NodeVersion string `json:"nodeVersion,omitempty"`
}

// UpdateProject updates an existing projects configuration within Vercel.
Expand Down
1 change: 1 addition & 0 deletions docs/data-sources/project.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ data "vercel_project" "example" {
- `id` (String) The ID of this resource.
- `ignore_command` (String) When a commit is pushed to the Git repository that is connected with your Project, its SHA will determine if a new Build has to be issued. If the SHA was deployed before, no new Build will be issued. You can customize this behavior with a command that exits with code 1 (new Build needed) or code 0.
- `install_command` (String) The install command for this project. If omitted, this value will be automatically detected.
- `node_version` (String) The version of Node.js that is used in the Build Step and for Serverless Functions.
- `oidc_token_config` (Attributes) Configuration for OpenID Connect (OIDC) tokens. (see [below for nested schema](#nestedatt--oidc_token_config))
- `options_allowlist` (Attributes) Disable Deployment Protection for CORS preflight `OPTIONS` requests for a list of paths. (see [below for nested schema](#nestedatt--options_allowlist))
- `output_directory` (String) The output directory of the project. When null is used this value will be automatically detected.
Expand Down
1 change: 1 addition & 0 deletions docs/resources/project.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ resource "vercel_project" "example" {
- `git_repository` (Attributes) The Git Repository that will be connected to the project. When this is defined, any pushes to the specified connected Git Repository will be automatically deployed. This requires the corresponding Vercel for [Github](https://vercel.com/docs/concepts/git/vercel-for-github), [Gitlab](https://vercel.com/docs/concepts/git/vercel-for-gitlab) or [Bitbucket](https://vercel.com/docs/concepts/git/vercel-for-bitbucket) plugins to be installed. (see [below for nested schema](#nestedatt--git_repository))
- `ignore_command` (String) When a commit is pushed to the Git repository that is connected with your Project, its SHA will determine if a new Build has to be issued. If the SHA was deployed before, no new Build will be issued. You can customize this behavior with a command that exits with code 1 (new Build needed) or code 0.
- `install_command` (String) The install command for this project. If omitted, this value will be automatically detected.
- `node_version` (String) The version of Node.js that is used in the Build Step and for Serverless Functions. A new Deployment is required for your changes to take effect.
- `oidc_token_config` (Attributes) Configuration for OpenID Connect (OIDC) tokens. (see [below for nested schema](#nestedatt--oidc_token_config))
- `options_allowlist` (Attributes) Disable Deployment Protection for CORS preflight `OPTIONS` requests for a list of paths. (see [below for nested schema](#nestedatt--options_allowlist))
- `output_directory` (String) The output directory of the project. If omitted, this value will be automatically detected.
Expand Down
6 changes: 6 additions & 0 deletions vercel/data_source_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ For more detailed information, please see the [Vercel documentation](https://ver
Computed: true,
Description: "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.",
},
"node_version": schema.StringAttribute{
Computed: true,
Description: "The version of Node.js that is used in the Build Step and for Serverless Functions.",
},
"environment": schema.SetNestedAttribute{
Description: "A list of environment variables that should be configured for the project.",
Computed: true,
Expand Down Expand Up @@ -411,6 +415,7 @@ type ProjectDataSource struct {
EnableAffectedProjectsDeployments types.Bool `tfsdk:"enable_affected_projects_deployments"`
SkewProtection types.String `tfsdk:"skew_protection"`
ResourceConfig *ResourceConfig `tfsdk:"resource_config"`
NodeVersion types.String `tfsdk:"node_version"`
}

func convertResponseToProjectDataSource(ctx context.Context, response client.ProjectResponse, plan Project, environmentVariables []client.EnvironmentVariable) (ProjectDataSource, error) {
Expand Down Expand Up @@ -480,6 +485,7 @@ func convertResponseToProjectDataSource(ctx context.Context, response client.Pro
EnableAffectedProjectsDeployments: project.EnableAffectedProjectsDeployments,
SkewProtection: project.SkewProtection,
ResourceConfig: project.ResourceConfig,
NodeVersion: project.NodeVersion,
}, nil
}

Expand Down
20 changes: 19 additions & 1 deletion vercel/resource_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,19 @@ At this time you cannot use a Vercel Project resource with in-line ` + "`environ
validateServerlessFunctionRegion(),
},
},
"node_version": schema.StringAttribute{
Optional: true,
Computed: true,
PlanModifiers: []planmodifier.String{stringplanmodifier.UseStateForUnknown()},
Validators: []validator.String{
stringvalidator.OneOf(
"18.x",
"20.x",
"22.x",
),
},
Description: "The version of Node.js that is used in the Build Step and for Serverless Functions. A new Deployment is required for your changes to take effect.",
},
"environment": schema.SetNestedAttribute{
Description: "A set of Environment Variables that should be configured for the project.",
Optional: true,
Expand Down Expand Up @@ -586,6 +599,7 @@ type Project struct {
IgnoreCommand types.String `tfsdk:"ignore_command"`
InstallCommand types.String `tfsdk:"install_command"`
Name types.String `tfsdk:"name"`
NodeVersion types.String `tfsdk:"node_version"`
OutputDirectory types.String `tfsdk:"output_directory"`
PublicSource types.Bool `tfsdk:"public_source"`
RootDirectory types.String `tfsdk:"root_directory"`
Expand Down Expand Up @@ -645,7 +659,9 @@ func (p Project) RequiresUpdateAfterCreation() bool {
!p.PrioritiseProductionBuilds.IsNull() ||
!p.DirectoryListing.IsNull() ||
!p.SkewProtection.IsNull() ||
p.ResourceConfig != nil
p.ResourceConfig != nil ||
!p.NodeVersion.IsNull()

}

var nullProject = Project{
Expand Down Expand Up @@ -781,6 +797,7 @@ func (p *Project) toUpdateProjectRequest(ctx context.Context, oldName string) (r
SkewProtectionMaxAge: toSkewProtectionAge(p.SkewProtection),
GitComments: gc.toUpdateProjectRequest(),
ResourceConfig: p.ResourceConfig.toUpdateProjectRequest(),
NodeVersion: p.NodeVersion.ValueString(),
}, nil
}

Expand Down Expand Up @@ -1394,6 +1411,7 @@ func convertResponseToProject(ctx context.Context, response client.ProjectRespon
SkewProtection: fromSkewProtectionMaxAge(response.SkewProtectionMaxAge),
GitComments: gitComments,
ResourceConfig: resourceConfig,
NodeVersion: types.StringValue(response.NodeVersion),
}, nil
}

Expand Down