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

Add support for Vercel Toolbar settings at project level #308

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 1, 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
4 changes: 4 additions & 0 deletions client/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ type CreateProjectRequest struct {
RootDirectory *string `json:"rootDirectory"`
ServerlessFunctionRegion string `json:"serverlessFunctionRegion,omitempty"`
ResourceConfig *ResourceConfig `json:"resourceConfig,omitempty"`
EnablePreviewFeedback *bool `json:"enablePreviewFeedback,omitempty"`
EnableProductionFeedback *bool `json:"enableProductionFeedback,omitempty"`
}

// CreateProject will create a project within Vercel.
Expand Down Expand Up @@ -192,6 +194,7 @@ type ProjectResponse struct {
ProtectionBypass map[string]ProtectionBypass `json:"protectionBypass"`
AutoExposeSystemEnvVars *bool `json:"autoExposeSystemEnvs"`
EnablePreviewFeedback *bool `json:"enablePreviewFeedback"`
EnableProductionFeedback *bool `json:"enableProductionFeedback"`
EnableAffectedProjectsDeployments *bool `json:"enableAffectedProjectsDeployments"`
AutoAssignCustomDomains bool `json:"autoAssignCustomDomains"`
GitLFS bool `json:"gitLFS"`
Expand Down Expand Up @@ -301,6 +304,7 @@ type UpdateProjectRequest struct {
OptionsAllowlist *OptionsAllowlist `json:"optionsAllowlist"`
AutoExposeSystemEnvVars bool `json:"autoExposeSystemEnvs"`
EnablePreviewFeedback *bool `json:"enablePreviewFeedback"`
EnableProductionFeedback *bool `json:"enableProductionFeedback"`
EnableAffectedProjectsDeployments *bool `json:"enableAffectedProjectsDeployments,omitempty"`
AutoAssignCustomDomains bool `json:"autoAssignCustomDomains"`
GitLFS bool `json:"gitLFS"`
Expand Down
4 changes: 3 additions & 1 deletion docs/data-sources/project.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ data "vercel_project" "example" {
- `dev_command` (String) The dev command for this project. If omitted, this value will be automatically detected.
- `directory_listing` (Boolean) If no index file is present within a directory, the directory contents will be displayed.
- `enable_affected_projects_deployments` (Boolean) When enabled, Vercel will automatically deploy all projects that are affected by a change to this project.
- `enable_preview_feedback` (Boolean) Whether the Vercel Toolbar is enabled on your preview deployments. If unspecified, defaults to team setting.
- `enable_production_feedback` (Boolean) Whether the Vercel Toolbar is enabled on your production deployments. If unspecified, defaults to team setting.
- `environment` (Attributes Set) A list of environment variables that should be configured for the project. (see [below for nested schema](#nestedatt--environment))
- `framework` (String) The framework that is being used for this project. If omitted, no framework is selected.
- `function_failover` (Boolean) Automatically failover Serverless Functions to the nearest region. You can customize regions through vercel.json. A new Deployment is required for your changes to take effect.
Expand All @@ -59,7 +61,7 @@ data "vercel_project" "example" {
- `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.
- `password_protection` (Attributes) Ensures visitors of your Preview Deployments must enter a password in order to gain access. (see [below for nested schema](#nestedatt--password_protection))
- `preview_comments` (Boolean) Whether comments are enabled on your Preview Deployments.
- `preview_comments` (Boolean, Deprecated) Whether comments are enabled on your Preview Deployments.
- `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 Deployment Protection on this project when using an HTTP header named `x-vercel-protection-bypass` with the value from `protection_bypass_for_automation_secret`.
- `protection_bypass_for_automation_secret` (String, Sensitive) If `protection_bypass_for_automation` is enabled, optionally set this value to specify a 32 character secret, otherwise a secret will be generated.
Expand Down
4 changes: 3 additions & 1 deletion docs/resources/project.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ resource "vercel_project" "example" {
- `dev_command` (String) The dev command for this project. If omitted, this value will be automatically detected.
- `directory_listing` (Boolean) If no index file is present within a directory, the directory contents will be displayed.
- `enable_affected_projects_deployments` (Boolean) When enabled, Vercel will automatically deploy all projects that are affected by a change to this project.
- `enable_preview_feedback` (Boolean) Enables the Vercel Toolbar on your preview deployments.
- `enable_production_feedback` (Boolean) Enables the Vercel Toolbar on your production deployments: one of on, off or default.
- `environment` (Attributes Set) A set of Environment Variables that should be configured for the project. (see [below for nested schema](#nestedatt--environment))
- `framework` (String) The framework that is being used for this project. If omitted, no framework is selected.
- `function_failover` (Boolean) Automatically failover Serverless Functions to the nearest region. You can customize regions through vercel.json. A new Deployment is required for your changes to take effect.
Expand All @@ -76,7 +78,7 @@ resource "vercel_project" "example" {
- `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.
- `password_protection` (Attributes) Ensures visitors of your Preview Deployments must enter a password in order to gain access. (see [below for nested schema](#nestedatt--password_protection))
- `preview_comments` (Boolean) Whether to enable comments on your Preview Deployments. If omitted, comments are controlled at the team level (default behaviour).
- `preview_comments` (Boolean, Deprecated) Enables the Vercel Toolbar on your preview deployments.
- `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 Deployment Protection on this project when using an HTTP header named `x-vercel-protection-bypass` with a value of the `protection_bypass_for_automation_secret` field.
- `protection_bypass_for_automation_secret` (String, Sensitive) If `protection_bypass_for_automation` is enabled, optionally set this value to specify a 32 character secret, otherwise a secret will be generated.
Expand Down
15 changes: 14 additions & 1 deletion vercel/data_source_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,17 @@ For more detailed information, please see the [Vercel documentation](https://ver
},
},
"preview_comments": schema.BoolAttribute{
Computed: true,
DeprecationMessage: "Use `enable_preview_feedback` instead. This attribute will be removed in a future version.",
Description: "Whether comments are enabled on your Preview Deployments.",
},
"enable_preview_feedback": schema.BoolAttribute{
Computed: true,
Description: "Whether the Vercel Toolbar is enabled on your preview deployments. If unspecified, defaults to team setting.",
},
"enable_production_feedback": schema.BoolAttribute{
Computed: true,
Description: "Whether comments are enabled on your Preview Deployments.",
Description: "Whether the Vercel Toolbar is enabled on your production deployments. If unspecified, defaults to team setting.",
},
"auto_assign_custom_domains": schema.BoolAttribute{
Computed: true,
Expand Down Expand Up @@ -409,6 +418,8 @@ type ProjectDataSource struct {
AutoExposeSystemEnvVars types.Bool `tfsdk:"automatically_expose_system_environment_variables"`
GitComments types.Object `tfsdk:"git_comments"`
PreviewComments types.Bool `tfsdk:"preview_comments"`
EnablePreviewFeedback types.Bool `tfsdk:"enable_preview_feedback"`
EnableProductionFeedback types.Bool `tfsdk:"enable_production_feedback"`
AutoAssignCustomDomains types.Bool `tfsdk:"auto_assign_custom_domains"`
GitLFS types.Bool `tfsdk:"git_lfs"`
FunctionFailover types.Bool `tfsdk:"function_failover"`
Expand Down Expand Up @@ -472,6 +483,8 @@ func convertResponseToProjectDataSource(ctx context.Context, response client.Pro
ProtectionBypassForAutomationSecret: project.ProtectionBypassForAutomationSecret,
GitComments: project.GitComments,
PreviewComments: project.PreviewComments,
EnablePreviewFeedback: project.EnablePreviewFeedback,
EnableProductionFeedback: project.EnableProductionFeedback,
AutoAssignCustomDomains: project.AutoAssignCustomDomains,
GitLFS: project.GitLFS,
FunctionFailover: project.FunctionFailover,
Expand Down
5 changes: 4 additions & 1 deletion vercel/data_source_project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ func TestAcc_ProjectDataSource(t *testing.T) {
resource.TestCheckResourceAttr("data.vercel_project.test", "git_comments.on_pull_request", "true"),
resource.TestCheckResourceAttr("data.vercel_project.test", "git_comments.on_commit", "true"),
resource.TestCheckResourceAttr("data.vercel_project.test", "preview_comments", "true"),
resource.TestCheckResourceAttr("data.vercel_project.test", "enable_preview_feedback", "true"),
resource.TestCheckResourceAttr("data.vercel_project.test", "enable_production_feedback", "false"),
resource.TestCheckResourceAttr("data.vercel_project.test", "auto_assign_custom_domains", "true"),
resource.TestCheckResourceAttr("data.vercel_project.test", "git_lfs", "true"),
resource.TestCheckResourceAttr("data.vercel_project.test", "function_failover", "true"),
Expand Down Expand Up @@ -109,7 +111,8 @@ resource "vercel_project" "test" {
on_pull_request = true,
on_commit = true
}
preview_comments = true
enable_preview_feedback = true
enable_production_feedback = false
auto_assign_custom_domains = true
git_lfs = true
function_failover = true
Expand Down
50 changes: 46 additions & 4 deletions vercel/resource_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"regexp"

"github.com/hashicorp/terraform-plugin-framework-validators/boolvalidator"
"github.com/hashicorp/terraform-plugin-framework-validators/int64validator"
"github.com/hashicorp/terraform-plugin-framework-validators/setvalidator"
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
Expand Down Expand Up @@ -465,9 +466,29 @@ At this time you cannot use a Vercel Project resource with in-line ` + "`environ
},
},
"preview_comments": schema.BoolAttribute{
Description: "Enables the Vercel Toolbar on your preview deployments.",
DeprecationMessage: "Use `enable_preview_feedback` instead. This attribute will be removed in a future version.",
Optional: true,
Computed: true,
Validators: []validator.Bool{boolvalidator.ConflictsWith(
path.MatchRoot("preview_comments"),
path.MatchRoot("enable_preview_feedback"),
)},
},
"enable_preview_feedback": schema.BoolAttribute{
Description: "Enables the Vercel Toolbar on your preview deployments.",
Optional: true,
Computed: true,
Validators: []validator.Bool{boolvalidator.ConflictsWith(
path.MatchRoot("preview_comments"),
path.MatchRoot("enable_preview_feedback"),
)},
},
"enable_production_feedback": schema.BoolAttribute{
Description: "Enables the Vercel Toolbar on your production deployments: one of on, off or default.",
Optional: true,
Computed: true,
PlanModifiers: []planmodifier.Bool{boolplanmodifier.UseStateForUnknown()},
Description: "Whether to enable comments on your Preview Deployments. If omitted, comments are controlled at the team level (default behaviour).",
},
"auto_assign_custom_domains": schema.BoolAttribute{
Optional: true,
Expand Down Expand Up @@ -591,6 +612,8 @@ type Project struct {
AutoExposeSystemEnvVars types.Bool `tfsdk:"automatically_expose_system_environment_variables"`
GitComments types.Object `tfsdk:"git_comments"`
PreviewComments types.Bool `tfsdk:"preview_comments"`
EnablePreviewFeedback types.Bool `tfsdk:"enable_preview_feedback"`
EnableProductionFeedback types.Bool `tfsdk:"enable_production_feedback"`
AutoAssignCustomDomains types.Bool `tfsdk:"auto_assign_custom_domains"`
GitLFS types.Bool `tfsdk:"git_lfs"`
FunctionFailover types.Bool `tfsdk:"function_failover"`
Expand Down Expand Up @@ -626,7 +649,6 @@ func (p Project) RequiresUpdateAfterCreation() bool {
p.OptionsAllowlist != nil ||
!p.AutoExposeSystemEnvVars.IsNull() ||
p.GitComments.IsNull() ||
!p.PreviewComments.IsNull() ||
(!p.AutoAssignCustomDomains.IsNull() && !p.AutoAssignCustomDomains.ValueBool()) ||
!p.GitLFS.IsNull() ||
!p.FunctionFailover.IsNull() ||
Expand Down Expand Up @@ -722,6 +744,8 @@ func (p *Project) toCreateProjectRequest(ctx context.Context, envs []Environment
RootDirectory: p.RootDirectory.ValueStringPointer(),
ServerlessFunctionRegion: p.ServerlessFunctionRegion.ValueString(),
ResourceConfig: resourceConfig.toClientResourceConfig(),
EnablePreviewFeedback: oneBoolPointer(p.EnablePreviewFeedback, p.PreviewComments),
EnableProductionFeedback: p.EnableProductionFeedback.ValueBoolPointer(),
}, diags
}

Expand All @@ -735,7 +759,22 @@ func toSkewProtectionAge(sp types.String) int {
"1 day": 86400,
"7 days": 604800,
}
return ages[sp.ValueString()]
v, ok := ages[sp.ValueString()]
if !ok {
// Should not happen due to validation
return 0
}
return v
}

func oneBoolPointer(a, b types.Bool) *bool {
if !a.IsNull() && !a.IsUnknown() {
return a.ValueBoolPointer()
}
if !b.IsNull() && !b.IsUnknown() {
return b.ValueBoolPointer()
}
return nil
}

func (p *Project) toUpdateProjectRequest(ctx context.Context, oldName string) (req client.UpdateProjectRequest, diags diag.Diagnostics) {
Expand Down Expand Up @@ -773,7 +812,8 @@ func (p *Project) toUpdateProjectRequest(ctx context.Context, oldName string) (r
OIDCTokenConfig: p.OIDCTokenConfig.toUpdateProjectRequest(),
OptionsAllowlist: p.OptionsAllowlist.toUpdateProjectRequest(),
AutoExposeSystemEnvVars: p.AutoExposeSystemEnvVars.ValueBool(),
EnablePreviewFeedback: p.PreviewComments.ValueBoolPointer(),
EnablePreviewFeedback: oneBoolPointer(p.EnablePreviewFeedback, p.PreviewComments),
EnableProductionFeedback: p.EnableProductionFeedback.ValueBoolPointer(),
EnableAffectedProjectsDeployments: p.EnableAffectedProjectsDeployments.ValueBoolPointer(),
AutoAssignCustomDomains: p.AutoAssignCustomDomains.ValueBool(),
GitLFS: p.GitLFS.ValueBool(),
Expand Down Expand Up @@ -1407,6 +1447,8 @@ func convertResponseToProject(ctx context.Context, response client.ProjectRespon
ProtectionBypassForAutomationSecret: protectionBypassSecret,
AutoExposeSystemEnvVars: types.BoolPointerValue(response.AutoExposeSystemEnvVars),
PreviewComments: types.BoolPointerValue(response.EnablePreviewFeedback),
EnablePreviewFeedback: types.BoolPointerValue(response.EnablePreviewFeedback),
EnableProductionFeedback: types.BoolPointerValue(response.EnableProductionFeedback),
EnableAffectedProjectsDeployments: uncoerceBool(fields.EnableAffectedProjectsDeployments, types.BoolPointerValue(response.EnableAffectedProjectsDeployments)),
AutoAssignCustomDomains: types.BoolValue(response.AutoAssignCustomDomains),
GitLFS: types.BoolValue(response.GitLFS),
Expand Down
Loading