From b6dc26dc05a7a32d77c0fc129f7bc5172f10989d Mon Sep 17 00:00:00 2001 From: Matthew Binshtok Date: Wed, 19 Feb 2025 23:13:41 -0500 Subject: [PATCH 01/13] add field to structs --- client/project.go | 31 +++++++++++++++++-------------- vercel/data_source_project.go | 2 ++ vercel/resource_project.go | 30 +++++++++++++++++------------- 3 files changed, 36 insertions(+), 27 deletions(-) diff --git a/client/project.go b/client/project.go index f16d0cf2..86aff4ac 100644 --- a/client/project.go +++ b/client/project.go @@ -44,20 +44,21 @@ type DeploymentExpiration struct { // CreateProjectRequest defines the information necessary to create a project. type CreateProjectRequest struct { - BuildCommand *string `json:"buildCommand"` - CommandForIgnoringBuildStep *string `json:"commandForIgnoringBuildStep,omitempty"` - DevCommand *string `json:"devCommand"` - EnvironmentVariables []EnvironmentVariable `json:"environmentVariables,omitempty"` - Framework *string `json:"framework"` - GitRepository *GitRepository `json:"gitRepository,omitempty"` - InstallCommand *string `json:"installCommand"` - Name string `json:"name"` - OIDCTokenConfig *OIDCTokenConfig `json:"oidcTokenConfig,omitempty"` - OutputDirectory *string `json:"outputDirectory"` - PublicSource *bool `json:"publicSource"` - RootDirectory *string `json:"rootDirectory"` - ServerlessFunctionRegion string `json:"serverlessFunctionRegion,omitempty"` - ResourceConfig *ResourceConfig `json:"resourceConfig,omitempty"` + BuildCommand *string `json:"buildCommand"` + CommandForIgnoringBuildStep *string `json:"commandForIgnoringBuildStep,omitempty"` + DevCommand *string `json:"devCommand"` + EnableAffectedProjectsDeployments bool `json:"enableAffectedProjectsDeployments"` + EnvironmentVariables []EnvironmentVariable `json:"environmentVariables,omitempty"` + Framework *string `json:"framework"` + GitRepository *GitRepository `json:"gitRepository,omitempty"` + InstallCommand *string `json:"installCommand"` + Name string `json:"name"` + OIDCTokenConfig *OIDCTokenConfig `json:"oidcTokenConfig,omitempty"` + OutputDirectory *string `json:"outputDirectory"` + 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. @@ -191,6 +192,7 @@ type ProjectResponse struct { ProtectionBypass map[string]ProtectionBypass `json:"protectionBypass"` AutoExposeSystemEnvVars *bool `json:"autoExposeSystemEnvs"` EnablePreviewFeedback *bool `json:"enablePreviewFeedback"` + EnableAffectedProjectsDeployments bool `json:"enableAffectedProjectsDeployments"` AutoAssignCustomDomains bool `json:"autoAssignCustomDomains"` GitLFS bool `json:"gitLFS"` ServerlessFunctionZeroConfigFailover bool `json:"serverlessFunctionZeroConfigFailover"` @@ -291,6 +293,7 @@ type UpdateProjectRequest struct { OptionsAllowlist *OptionsAllowlist `json:"optionsAllowlist"` AutoExposeSystemEnvVars bool `json:"autoExposeSystemEnvs"` EnablePreviewFeedback *bool `json:"enablePreviewFeedback"` + EnableAffectedProjectsDeployments bool `json:"enableAffectedProjectsDeployments"` AutoAssignCustomDomains bool `json:"autoAssignCustomDomains"` GitLFS bool `json:"gitLFS"` ServerlessFunctionZeroConfigFailover bool `json:"serverlessFunctionZeroConfigFailover"` diff --git a/vercel/data_source_project.go b/vercel/data_source_project.go index 3be3b0cf..b08a6a08 100644 --- a/vercel/data_source_project.go +++ b/vercel/data_source_project.go @@ -404,6 +404,7 @@ type ProjectDataSource struct { GitForkProtection types.Bool `tfsdk:"git_fork_protection"` PrioritiseProductionBuilds types.Bool `tfsdk:"prioritise_production_builds"` DirectoryListing types.Bool `tfsdk:"directory_listing"` + EnableAffectedProjectsDeployments types.Bool `tfsdk:"enable_affected_projects_deployments"` SkewProtection types.String `tfsdk:"skew_protection"` ResourceConfig *ResourceConfig `tfsdk:"resource_config"` } @@ -472,6 +473,7 @@ func convertResponseToProjectDataSource(ctx context.Context, response client.Pro GitForkProtection: project.GitForkProtection, PrioritiseProductionBuilds: project.PrioritiseProductionBuilds, DirectoryListing: project.DirectoryListing, + EnableAffectedProjectsDeployments: project.EnableAffectedProjectsDeployments, SkewProtection: project.SkewProtection, ResourceConfig: project.ResourceConfig, }, nil diff --git a/vercel/resource_project.go b/vercel/resource_project.go index 944ae3c4..2db5ff1c 100644 --- a/vercel/resource_project.go +++ b/vercel/resource_project.go @@ -604,6 +604,7 @@ type Project struct { GitForkProtection types.Bool `tfsdk:"git_fork_protection"` PrioritiseProductionBuilds types.Bool `tfsdk:"prioritise_production_builds"` DirectoryListing types.Bool `tfsdk:"directory_listing"` + EnableAffectedProjectsDeployments types.Bool `tfsdk:"enable_affected_projects_deployments"` SkewProtection types.String `tfsdk:"skew_protection"` ResourceConfig *ResourceConfig `tfsdk:"resource_config"` } @@ -703,19 +704,20 @@ func parseEnvironment(ctx context.Context, vars []EnvironmentItem) (out []client func (p *Project) toCreateProjectRequest(ctx context.Context, envs []EnvironmentItem) (req client.CreateProjectRequest, diags diag.Diagnostics) { clientEnvs, diags := parseEnvironment(ctx, envs) return client.CreateProjectRequest{ - BuildCommand: p.BuildCommand.ValueStringPointer(), - CommandForIgnoringBuildStep: p.IgnoreCommand.ValueStringPointer(), - DevCommand: p.DevCommand.ValueStringPointer(), - EnvironmentVariables: clientEnvs, - Framework: p.Framework.ValueStringPointer(), - GitRepository: p.GitRepository.toCreateProjectRequest(), - InstallCommand: p.InstallCommand.ValueStringPointer(), - Name: p.Name.ValueString(), - OIDCTokenConfig: p.OIDCTokenConfig.toCreateProjectRequest(), - OutputDirectory: p.OutputDirectory.ValueStringPointer(), - PublicSource: p.PublicSource.ValueBoolPointer(), - RootDirectory: p.RootDirectory.ValueStringPointer(), - ServerlessFunctionRegion: p.ServerlessFunctionRegion.ValueString(), + BuildCommand: p.BuildCommand.ValueStringPointer(), + CommandForIgnoringBuildStep: p.IgnoreCommand.ValueStringPointer(), + DevCommand: p.DevCommand.ValueStringPointer(), + EnableAffectedProjectsDeployments: p.EnableAffectedProjectsDeployments.ValueBool(), + EnvironmentVariables: clientEnvs, + Framework: p.Framework.ValueStringPointer(), + GitRepository: p.GitRepository.toCreateProjectRequest(), + InstallCommand: p.InstallCommand.ValueStringPointer(), + Name: p.Name.ValueString(), + OIDCTokenConfig: p.OIDCTokenConfig.toCreateProjectRequest(), + OutputDirectory: p.OutputDirectory.ValueStringPointer(), + PublicSource: p.PublicSource.ValueBoolPointer(), + RootDirectory: p.RootDirectory.ValueStringPointer(), + ServerlessFunctionRegion: p.ServerlessFunctionRegion.ValueString(), }, diags } @@ -764,6 +766,7 @@ func (p *Project) toUpdateProjectRequest(ctx context.Context, oldName string) (r OptionsAllowlist: p.OptionsAllowlist.toUpdateProjectRequest(), AutoExposeSystemEnvVars: p.AutoExposeSystemEnvVars.ValueBool(), EnablePreviewFeedback: p.PreviewComments.ValueBoolPointer(), + EnableAffectedProjectsDeployments: p.EnableAffectedProjectsDeployments.ValueBool(), AutoAssignCustomDomains: p.AutoAssignCustomDomains.ValueBool(), GitLFS: p.GitLFS.ValueBool(), ServerlessFunctionZeroConfigFailover: p.FunctionFailover.ValueBool(), @@ -1368,6 +1371,7 @@ func convertResponseToProject(ctx context.Context, response client.ProjectRespon GitForkProtection: types.BoolValue(response.GitForkProtection), PrioritiseProductionBuilds: types.BoolValue(response.ProductionDeploymentsFastLane), DirectoryListing: types.BoolValue(response.DirectoryListing), + EnableAffectedProjectsDeployments: types.BoolValue(response.EnableAffectedProjectsDeployments), SkewProtection: fromSkewProtectionMaxAge(response.SkewProtectionMaxAge), GitComments: gitComments, ResourceConfig: resourceConfig, From 9bb577f029a4dfcb7222f6ac23b8d2978711fb41 Mon Sep 17 00:00:00 2001 From: Matthew Binshtok Date: Thu, 20 Feb 2025 00:19:28 -0500 Subject: [PATCH 02/13] change to optional --- client/project.go | 6 +++--- vercel/data_source_project.go | 4 ++++ vercel/data_source_project_test.go | 1 + vercel/resource_project.go | 6 +++--- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/client/project.go b/client/project.go index 86aff4ac..61ab17dd 100644 --- a/client/project.go +++ b/client/project.go @@ -47,7 +47,7 @@ type CreateProjectRequest struct { BuildCommand *string `json:"buildCommand"` CommandForIgnoringBuildStep *string `json:"commandForIgnoringBuildStep,omitempty"` DevCommand *string `json:"devCommand"` - EnableAffectedProjectsDeployments bool `json:"enableAffectedProjectsDeployments"` + EnableAffectedProjectsDeployments *bool `json:"enableAffectedProjectsDeployments"` EnvironmentVariables []EnvironmentVariable `json:"environmentVariables,omitempty"` Framework *string `json:"framework"` GitRepository *GitRepository `json:"gitRepository,omitempty"` @@ -192,7 +192,7 @@ type ProjectResponse struct { ProtectionBypass map[string]ProtectionBypass `json:"protectionBypass"` AutoExposeSystemEnvVars *bool `json:"autoExposeSystemEnvs"` EnablePreviewFeedback *bool `json:"enablePreviewFeedback"` - EnableAffectedProjectsDeployments bool `json:"enableAffectedProjectsDeployments"` + EnableAffectedProjectsDeployments *bool `json:"enableAffectedProjectsDeployments"` AutoAssignCustomDomains bool `json:"autoAssignCustomDomains"` GitLFS bool `json:"gitLFS"` ServerlessFunctionZeroConfigFailover bool `json:"serverlessFunctionZeroConfigFailover"` @@ -293,7 +293,7 @@ type UpdateProjectRequest struct { OptionsAllowlist *OptionsAllowlist `json:"optionsAllowlist"` AutoExposeSystemEnvVars bool `json:"autoExposeSystemEnvs"` EnablePreviewFeedback *bool `json:"enablePreviewFeedback"` - EnableAffectedProjectsDeployments bool `json:"enableAffectedProjectsDeployments"` + EnableAffectedProjectsDeployments *bool `json:"enableAffectedProjectsDeployments"` AutoAssignCustomDomains bool `json:"autoAssignCustomDomains"` GitLFS bool `json:"gitLFS"` ServerlessFunctionZeroConfigFailover bool `json:"serverlessFunctionZeroConfigFailover"` diff --git a/vercel/data_source_project.go b/vercel/data_source_project.go index b08a6a08..2f5ebda9 100644 --- a/vercel/data_source_project.go +++ b/vercel/data_source_project.go @@ -278,6 +278,10 @@ For more detailed information, please see the [Vercel documentation](https://ver Computed: true, Description: "Specifies whether the source code and logs of the deployments for this project should be public or not.", }, + "enable_affected_projects_deployments": schema.BoolAttribute{ + Computed: true, + Description: "When enabled, Vercel will automatically deploy all projects that are affected by a change to this project.", + }, "root_directory": schema.StringAttribute{ Computed: true, Description: "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.", diff --git a/vercel/data_source_project_test.go b/vercel/data_source_project_test.go index b18474bd..87f920f9 100644 --- a/vercel/data_source_project_test.go +++ b/vercel/data_source_project_test.go @@ -24,6 +24,7 @@ func TestAcc_ProjectDataSource(t *testing.T) { resource.TestCheckResourceAttr("data.vercel_project.test", "install_command", "npm install"), resource.TestCheckResourceAttr("data.vercel_project.test", "output_directory", ".output"), resource.TestCheckResourceAttr("data.vercel_project.test", "public_source", "true"), + resource.TestCheckResourceAttr("data.vercel_project.test", "enable_affected_projects_deployments", "false"), resource.TestCheckResourceAttr("data.vercel_project.test", "root_directory", "ui/src"), resource.TestCheckResourceAttr("data.vercel_project.test", "vercel_authentication.deployment_type", "standard_protection"), resource.TestCheckResourceAttr("data.vercel_project.test", "password_protection.deployment_type", "standard_protection"), diff --git a/vercel/resource_project.go b/vercel/resource_project.go index 2db5ff1c..6f956162 100644 --- a/vercel/resource_project.go +++ b/vercel/resource_project.go @@ -707,7 +707,7 @@ func (p *Project) toCreateProjectRequest(ctx context.Context, envs []Environment BuildCommand: p.BuildCommand.ValueStringPointer(), CommandForIgnoringBuildStep: p.IgnoreCommand.ValueStringPointer(), DevCommand: p.DevCommand.ValueStringPointer(), - EnableAffectedProjectsDeployments: p.EnableAffectedProjectsDeployments.ValueBool(), + EnableAffectedProjectsDeployments: p.EnableAffectedProjectsDeployments.ValueBoolPointer(), EnvironmentVariables: clientEnvs, Framework: p.Framework.ValueStringPointer(), GitRepository: p.GitRepository.toCreateProjectRequest(), @@ -766,7 +766,7 @@ func (p *Project) toUpdateProjectRequest(ctx context.Context, oldName string) (r OptionsAllowlist: p.OptionsAllowlist.toUpdateProjectRequest(), AutoExposeSystemEnvVars: p.AutoExposeSystemEnvVars.ValueBool(), EnablePreviewFeedback: p.PreviewComments.ValueBoolPointer(), - EnableAffectedProjectsDeployments: p.EnableAffectedProjectsDeployments.ValueBool(), + EnableAffectedProjectsDeployments: p.EnableAffectedProjectsDeployments.ValueBoolPointer(), AutoAssignCustomDomains: p.AutoAssignCustomDomains.ValueBool(), GitLFS: p.GitLFS.ValueBool(), ServerlessFunctionZeroConfigFailover: p.FunctionFailover.ValueBool(), @@ -1364,6 +1364,7 @@ func convertResponseToProject(ctx context.Context, response client.ProjectRespon ProtectionBypassForAutomationSecret: protectionBypassSecret, AutoExposeSystemEnvVars: types.BoolPointerValue(response.AutoExposeSystemEnvVars), PreviewComments: types.BoolPointerValue(response.EnablePreviewFeedback), + EnableAffectedProjectsDeployments: types.BoolPointerValue(response.EnableAffectedProjectsDeployments), AutoAssignCustomDomains: types.BoolValue(response.AutoAssignCustomDomains), GitLFS: types.BoolValue(response.GitLFS), FunctionFailover: types.BoolValue(response.ServerlessFunctionZeroConfigFailover), @@ -1371,7 +1372,6 @@ func convertResponseToProject(ctx context.Context, response client.ProjectRespon GitForkProtection: types.BoolValue(response.GitForkProtection), PrioritiseProductionBuilds: types.BoolValue(response.ProductionDeploymentsFastLane), DirectoryListing: types.BoolValue(response.DirectoryListing), - EnableAffectedProjectsDeployments: types.BoolValue(response.EnableAffectedProjectsDeployments), SkewProtection: fromSkewProtectionMaxAge(response.SkewProtectionMaxAge), GitComments: gitComments, ResourceConfig: resourceConfig, From 03300f046061857f9fbc05f8ed7c5471ff2d6558 Mon Sep 17 00:00:00 2001 From: Matthew Binshtok Date: Thu, 20 Feb 2025 00:33:45 -0500 Subject: [PATCH 03/13] remove from data source test --- vercel/data_source_project_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/vercel/data_source_project_test.go b/vercel/data_source_project_test.go index 87f920f9..b18474bd 100644 --- a/vercel/data_source_project_test.go +++ b/vercel/data_source_project_test.go @@ -24,7 +24,6 @@ func TestAcc_ProjectDataSource(t *testing.T) { resource.TestCheckResourceAttr("data.vercel_project.test", "install_command", "npm install"), resource.TestCheckResourceAttr("data.vercel_project.test", "output_directory", ".output"), resource.TestCheckResourceAttr("data.vercel_project.test", "public_source", "true"), - resource.TestCheckResourceAttr("data.vercel_project.test", "enable_affected_projects_deployments", "false"), resource.TestCheckResourceAttr("data.vercel_project.test", "root_directory", "ui/src"), resource.TestCheckResourceAttr("data.vercel_project.test", "vercel_authentication.deployment_type", "standard_protection"), resource.TestCheckResourceAttr("data.vercel_project.test", "password_protection.deployment_type", "standard_protection"), From c2a2ea6ca63ab93ad2aee76fa55f858360b91ba5 Mon Sep 17 00:00:00 2001 From: Matthew Binshtok Date: Thu, 20 Feb 2025 00:42:13 -0500 Subject: [PATCH 04/13] add to schema --- vercel/resource_project.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/vercel/resource_project.go b/vercel/resource_project.go index 6f956162..4088f3e3 100644 --- a/vercel/resource_project.go +++ b/vercel/resource_project.go @@ -432,6 +432,12 @@ At this time you cannot use a Vercel Project resource with in-line ` + "`environ PlanModifiers: []planmodifier.Bool{boolplanmodifier.UseStateForUnknown()}, Description: "Vercel provides a set of Environment Variables that are automatically populated by the System, such as the URL of the Deployment or the name of the Git branch deployed. To expose them to your Deployments, enable this field", }, + "enable_affected_projects_deployments": schema.BoolAttribute{ + Optional: true, + Computed: true, + PlanModifiers: []planmodifier.Bool{boolplanmodifier.UseStateForUnknown()}, + Description: "When enabled, Vercel will automatically deploy all projects that are affected by a change to this project.", + }, "git_comments": schema.SingleNestedAttribute{ Description: "Configuration for Git Comments.", Optional: true, From 02be1dc153d461ad4c502487d35ebd9a7c4b52f2 Mon Sep 17 00:00:00 2001 From: Matthew Binshtok Date: Thu, 20 Feb 2025 00:42:36 -0500 Subject: [PATCH 05/13] task docs --- docs/data-sources/project.md | 1 + docs/resources/project.md | 1 + 2 files changed, 2 insertions(+) diff --git a/docs/data-sources/project.md b/docs/data-sources/project.md index cc53fed9..38dc3a21 100644 --- a/docs/data-sources/project.md +++ b/docs/data-sources/project.md @@ -43,6 +43,7 @@ data "vercel_project" "example" { - `customer_success_code_visibility` (Boolean) Allows Vercel Customer Support to inspect all Deployments' source code in this project to assist with debugging. - `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. - `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. diff --git a/docs/resources/project.md b/docs/resources/project.md index e5c678bc..d443bdd6 100644 --- a/docs/resources/project.md +++ b/docs/resources/project.md @@ -61,6 +61,7 @@ resource "vercel_project" "example" { - `customer_success_code_visibility` (Boolean) Allows Vercel Customer Support to inspect all Deployments' source code in this project to assist with debugging. - `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. - `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. From 37dbf1c1d64b9611e7d8ce4847d7f9cf21c12351 Mon Sep 17 00:00:00 2001 From: Matthew Binshtok Date: Thu, 20 Feb 2025 15:35:50 -0500 Subject: [PATCH 06/13] add tests --- vercel/resource_project_test.go | 127 ++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) diff --git a/vercel/resource_project_test.go b/vercel/resource_project_test.go index b135bd3a..775e2266 100644 --- a/vercel/resource_project_test.go +++ b/vercel/resource_project_test.go @@ -411,6 +411,35 @@ func TestAcc_ProjectImport(t *testing.T) { }) } +func TestAcc_ProjectEnablingAffectedProjectDeployments(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: testAccProjectConfigWithoutEnableAffectedSet(projectSuffix, teamIDConfig()), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckNoResourceAttr("vercel_project.enable_affected_projects_deployments", "enable_affected_projects_deployments"), + ), + }, + { + Config: testAccProjectConfigWithEnableAffectedTrue(projectSuffix, teamIDConfig()), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("vercel_project.enable_affected_projects_deployments", "enable_affected_projects_deployments", "true"), + ), + }, + { + Config: testAccProjectConfigWithEnableAffectedFalse(projectSuffix, teamIDConfig()), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("vercel_project.enable_affected_projects_deployments", "enable_affected_projects_deployments", "false"), + ), + }, + }, + }) +} + func testAccProjectExists(n, teamID string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] @@ -833,6 +862,104 @@ resource "vercel_project" "test" { `, projectSuffix, teamID) } +func testAccProjectConfigWithoutEnableAffectedSet(projectSuffix, teamID string) string { + return fmt.Sprintf(` +resource "vercel_project" "test" { + name = "test-acc-project-%s" + %s + build_command = "npm run build" + dev_command = "npm run serve" + ignore_command = "echo 'wat'" + serverless_function_region = "syd1" + framework = "nextjs" + install_command = "npm install" + output_directory = ".output" + public_source = true + root_directory = "ui/src" + automatically_expose_system_environment_variables = true + git_comments = { + on_pull_request = true, + on_commit = true + } + preview_comments = true + auto_assign_custom_domains = true + git_lfs = true + function_failover = true + customer_success_code_visibility = true + git_fork_protection = true + prioritise_production_builds = true + directory_listing = true + skew_protection = "7 days" +} +`, projectSuffix, teamID) +} + +func testAccProjectConfigWithEnableAffectedFalse(projectSuffix, teamID string) string { + return fmt.Sprintf(` +resource "vercel_project" "test" { + name = "test-acc-project-%s" + %s + build_command = "npm run build" + dev_command = "npm run serve" + ignore_command = "echo 'wat'" + serverless_function_region = "syd1" + framework = "nextjs" + install_command = "npm install" + output_directory = ".output" + public_source = true + root_directory = "ui/src" + automatically_expose_system_environment_variables = true + git_comments = { + on_pull_request = true, + on_commit = true + } + preview_comments = true + auto_assign_custom_domains = true + git_lfs = true + function_failover = true + customer_success_code_visibility = true + git_fork_protection = true + prioritise_production_builds = true + directory_listing = true + skew_protection = "7 days" + enable_affected_projects_deployments = false +} +`, projectSuffix, teamID) +} + +func testAccProjectConfigWithEnableAffectedTrue(projectSuffix, teamID string) string { + return fmt.Sprintf(` +resource "vercel_project" "test" { + name = "test-acc-project-%s" + %s + build_command = "npm run build" + dev_command = "npm run serve" + ignore_command = "echo 'wat'" + serverless_function_region = "syd1" + framework = "nextjs" + install_command = "npm install" + output_directory = ".output" + public_source = true + root_directory = "ui/src" + automatically_expose_system_environment_variables = true + git_comments = { + on_pull_request = true, + on_commit = true + } + preview_comments = true + auto_assign_custom_domains = true + git_lfs = true + function_failover = true + customer_success_code_visibility = true + git_fork_protection = true + prioritise_production_builds = true + directory_listing = true + skew_protection = "7 days" + enable_affected_projects_deployments = true +} +`, projectSuffix, teamID) +} + func testAccProjectConfig(projectSuffix, teamID string) string { return fmt.Sprintf(` resource "vercel_project" "test" { From 769280d5472e4e893e3ddfaa9282ed1b6e0c5eed Mon Sep 17 00:00:00 2001 From: Matthew Binshtok Date: Thu, 20 Feb 2025 18:12:25 -0500 Subject: [PATCH 07/13] fix project name --- vercel/resource_project_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/vercel/resource_project_test.go b/vercel/resource_project_test.go index 775e2266..3b4dee02 100644 --- a/vercel/resource_project_test.go +++ b/vercel/resource_project_test.go @@ -421,19 +421,19 @@ func TestAcc_ProjectEnablingAffectedProjectDeployments(t *testing.T) { { Config: testAccProjectConfigWithoutEnableAffectedSet(projectSuffix, teamIDConfig()), Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckNoResourceAttr("vercel_project.enable_affected_projects_deployments", "enable_affected_projects_deployments"), + resource.TestCheckNoResourceAttr("vercel_project.test", "enable_affected_projects_deployments"), ), }, { Config: testAccProjectConfigWithEnableAffectedTrue(projectSuffix, teamIDConfig()), Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("vercel_project.enable_affected_projects_deployments", "enable_affected_projects_deployments", "true"), + resource.TestCheckResourceAttr("vercel_project.test", "enable_affected_projects_deployments", "true"), ), }, { Config: testAccProjectConfigWithEnableAffectedFalse(projectSuffix, teamIDConfig()), Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("vercel_project.enable_affected_projects_deployments", "enable_affected_projects_deployments", "false"), + resource.TestCheckResourceAttr("vercel_project.test", "enable_affected_projects_deployments", "false"), ), }, }, From d76181ae238a920a20321ad0148760abc574e2b5 Mon Sep 17 00:00:00 2001 From: Matthew Binshtok Date: Thu, 20 Feb 2025 22:54:39 -0500 Subject: [PATCH 08/13] computed -> optional --- vercel/resource_project.go | 1 - 1 file changed, 1 deletion(-) diff --git a/vercel/resource_project.go b/vercel/resource_project.go index 4088f3e3..efd2bebf 100644 --- a/vercel/resource_project.go +++ b/vercel/resource_project.go @@ -434,7 +434,6 @@ At this time you cannot use a Vercel Project resource with in-line ` + "`environ }, "enable_affected_projects_deployments": schema.BoolAttribute{ Optional: true, - Computed: true, PlanModifiers: []planmodifier.Bool{boolplanmodifier.UseStateForUnknown()}, Description: "When enabled, Vercel will automatically deploy all projects that are affected by a change to this project.", }, From d29fb244b8f71990be85ac5971f618be6f4febe4 Mon Sep 17 00:00:00 2001 From: Matthew Binshtok Date: Thu, 20 Feb 2025 23:08:13 -0500 Subject: [PATCH 09/13] remove use state modifier --- vercel/resource_project.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/vercel/resource_project.go b/vercel/resource_project.go index efd2bebf..53f26e32 100644 --- a/vercel/resource_project.go +++ b/vercel/resource_project.go @@ -433,9 +433,8 @@ At this time you cannot use a Vercel Project resource with in-line ` + "`environ Description: "Vercel provides a set of Environment Variables that are automatically populated by the System, such as the URL of the Deployment or the name of the Git branch deployed. To expose them to your Deployments, enable this field", }, "enable_affected_projects_deployments": schema.BoolAttribute{ - Optional: true, - PlanModifiers: []planmodifier.Bool{boolplanmodifier.UseStateForUnknown()}, - Description: "When enabled, Vercel will automatically deploy all projects that are affected by a change to this project.", + Optional: true, + Description: "When enabled, Vercel will automatically deploy all projects that are affected by a change to this project.", }, "git_comments": schema.SingleNestedAttribute{ Description: "Configuration for Git Comments.", From 8ef076b64dbf32e3097cc6ddebc1409adc960d20 Mon Sep 17 00:00:00 2001 From: Matthew Binshtok Date: Fri, 21 Feb 2025 00:05:58 -0500 Subject: [PATCH 10/13] null handling --- vercel/resource_project.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/vercel/resource_project.go b/vercel/resource_project.go index 53f26e32..0e525f7e 100644 --- a/vercel/resource_project.go +++ b/vercel/resource_project.go @@ -1327,6 +1327,11 @@ func convertResponseToProject(ctx context.Context, response client.ProjectRespon protectionBypassSecret = types.StringValue(plan.ProtectionBypassForAutomationSecret.ValueString()) } + enableAffectedProjectsDeployments := types.BoolNull() + if !plan.EnableAffectedProjectsDeployments.IsNull() { + enableAffectedProjectsDeployments = types.BoolValue(plan.EnableAffectedProjectsDeployments.ValueBool()) + } + environmentEntry := types.SetValueMust(envVariableElemType, env) if plan.Environment.IsNull() { environmentEntry = types.SetNull(envVariableElemType) @@ -1368,7 +1373,7 @@ func convertResponseToProject(ctx context.Context, response client.ProjectRespon ProtectionBypassForAutomationSecret: protectionBypassSecret, AutoExposeSystemEnvVars: types.BoolPointerValue(response.AutoExposeSystemEnvVars), PreviewComments: types.BoolPointerValue(response.EnablePreviewFeedback), - EnableAffectedProjectsDeployments: types.BoolPointerValue(response.EnableAffectedProjectsDeployments), + EnableAffectedProjectsDeployments: enableAffectedProjectsDeployments, AutoAssignCustomDomains: types.BoolValue(response.AutoAssignCustomDomains), GitLFS: types.BoolValue(response.GitLFS), FunctionFailover: types.BoolValue(response.ServerlessFunctionZeroConfigFailover), From ec05175d58bf689208cb360da2ee9a757eeca43e Mon Sep 17 00:00:00 2001 From: Matthew Binshtok Date: Fri, 21 Feb 2025 00:30:42 -0500 Subject: [PATCH 11/13] uncoerce? --- vercel/resource_project.go | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/vercel/resource_project.go b/vercel/resource_project.go index 0e525f7e..ba107348 100644 --- a/vercel/resource_project.go +++ b/vercel/resource_project.go @@ -1049,20 +1049,22 @@ func (t *OptionsAllowlist) toUpdateProjectRequest() *client.OptionsAllowlist { * This is implemented in the below uncoerceString and uncoerceBool functions. */ type projectCoercedFields struct { - BuildCommand types.String - DevCommand types.String - InstallCommand types.String - OutputDirectory types.String - PublicSource types.Bool + BuildCommand types.String + DevCommand types.String + InstallCommand types.String + OutputDirectory types.String + PublicSource types.Bool + EnableAffectedProjectsDeployments types.Bool } func (p *Project) coercedFields() projectCoercedFields { return projectCoercedFields{ - BuildCommand: p.BuildCommand, - DevCommand: p.DevCommand, - InstallCommand: p.InstallCommand, - OutputDirectory: p.OutputDirectory, - PublicSource: p.PublicSource, + BuildCommand: p.BuildCommand, + DevCommand: p.DevCommand, + InstallCommand: p.InstallCommand, + OutputDirectory: p.OutputDirectory, + PublicSource: p.PublicSource, + EnableAffectedProjectsDeployments: p.EnableAffectedProjectsDeployments, } } @@ -1327,11 +1329,6 @@ func convertResponseToProject(ctx context.Context, response client.ProjectRespon protectionBypassSecret = types.StringValue(plan.ProtectionBypassForAutomationSecret.ValueString()) } - enableAffectedProjectsDeployments := types.BoolNull() - if !plan.EnableAffectedProjectsDeployments.IsNull() { - enableAffectedProjectsDeployments = types.BoolValue(plan.EnableAffectedProjectsDeployments.ValueBool()) - } - environmentEntry := types.SetValueMust(envVariableElemType, env) if plan.Environment.IsNull() { environmentEntry = types.SetNull(envVariableElemType) @@ -1373,7 +1370,7 @@ func convertResponseToProject(ctx context.Context, response client.ProjectRespon ProtectionBypassForAutomationSecret: protectionBypassSecret, AutoExposeSystemEnvVars: types.BoolPointerValue(response.AutoExposeSystemEnvVars), PreviewComments: types.BoolPointerValue(response.EnablePreviewFeedback), - EnableAffectedProjectsDeployments: enableAffectedProjectsDeployments, + EnableAffectedProjectsDeployments: uncoerceBool(fields.EnableAffectedProjectsDeployments, types.BoolPointerValue(response.EnableAffectedProjectsDeployments)), AutoAssignCustomDomains: types.BoolValue(response.AutoAssignCustomDomains), GitLFS: types.BoolValue(response.GitLFS), FunctionFailover: types.BoolValue(response.ServerlessFunctionZeroConfigFailover), From 746d361ac424e8cbdad9a570d55d9e864b01ca39 Mon Sep 17 00:00:00 2001 From: Matthew Binshtok Date: Fri, 21 Feb 2025 00:47:50 -0500 Subject: [PATCH 12/13] omitEmpty? --- client/project.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/project.go b/client/project.go index 61ab17dd..3b897410 100644 --- a/client/project.go +++ b/client/project.go @@ -47,7 +47,7 @@ type CreateProjectRequest struct { BuildCommand *string `json:"buildCommand"` CommandForIgnoringBuildStep *string `json:"commandForIgnoringBuildStep,omitempty"` DevCommand *string `json:"devCommand"` - EnableAffectedProjectsDeployments *bool `json:"enableAffectedProjectsDeployments"` + EnableAffectedProjectsDeployments *bool `json:"enableAffectedProjectsDeployments,omitempty"` EnvironmentVariables []EnvironmentVariable `json:"environmentVariables,omitempty"` Framework *string `json:"framework"` GitRepository *GitRepository `json:"gitRepository,omitempty"` @@ -293,7 +293,7 @@ type UpdateProjectRequest struct { OptionsAllowlist *OptionsAllowlist `json:"optionsAllowlist"` AutoExposeSystemEnvVars bool `json:"autoExposeSystemEnvs"` EnablePreviewFeedback *bool `json:"enablePreviewFeedback"` - EnableAffectedProjectsDeployments *bool `json:"enableAffectedProjectsDeployments"` + EnableAffectedProjectsDeployments *bool `json:"enableAffectedProjectsDeployments,omitempty"` AutoAssignCustomDomains bool `json:"autoAssignCustomDomains"` GitLFS bool `json:"gitLFS"` ServerlessFunctionZeroConfigFailover bool `json:"serverlessFunctionZeroConfigFailover"` From d7c0239b4a56d639008427a675b892406112ae8f Mon Sep 17 00:00:00 2001 From: Matthew Binshtok Date: Fri, 21 Feb 2025 10:22:45 -0500 Subject: [PATCH 13/13] remove unnecessary fields --- vercel/resource_project_test.go | 69 --------------------------------- 1 file changed, 69 deletions(-) diff --git a/vercel/resource_project_test.go b/vercel/resource_project_test.go index 3b4dee02..0523a29d 100644 --- a/vercel/resource_project_test.go +++ b/vercel/resource_project_test.go @@ -867,29 +867,6 @@ func testAccProjectConfigWithoutEnableAffectedSet(projectSuffix, teamID string) resource "vercel_project" "test" { name = "test-acc-project-%s" %s - build_command = "npm run build" - dev_command = "npm run serve" - ignore_command = "echo 'wat'" - serverless_function_region = "syd1" - framework = "nextjs" - install_command = "npm install" - output_directory = ".output" - public_source = true - root_directory = "ui/src" - automatically_expose_system_environment_variables = true - git_comments = { - on_pull_request = true, - on_commit = true - } - preview_comments = true - auto_assign_custom_domains = true - git_lfs = true - function_failover = true - customer_success_code_visibility = true - git_fork_protection = true - prioritise_production_builds = true - directory_listing = true - skew_protection = "7 days" } `, projectSuffix, teamID) } @@ -899,29 +876,6 @@ func testAccProjectConfigWithEnableAffectedFalse(projectSuffix, teamID string) s resource "vercel_project" "test" { name = "test-acc-project-%s" %s - build_command = "npm run build" - dev_command = "npm run serve" - ignore_command = "echo 'wat'" - serverless_function_region = "syd1" - framework = "nextjs" - install_command = "npm install" - output_directory = ".output" - public_source = true - root_directory = "ui/src" - automatically_expose_system_environment_variables = true - git_comments = { - on_pull_request = true, - on_commit = true - } - preview_comments = true - auto_assign_custom_domains = true - git_lfs = true - function_failover = true - customer_success_code_visibility = true - git_fork_protection = true - prioritise_production_builds = true - directory_listing = true - skew_protection = "7 days" enable_affected_projects_deployments = false } `, projectSuffix, teamID) @@ -932,29 +886,6 @@ func testAccProjectConfigWithEnableAffectedTrue(projectSuffix, teamID string) st resource "vercel_project" "test" { name = "test-acc-project-%s" %s - build_command = "npm run build" - dev_command = "npm run serve" - ignore_command = "echo 'wat'" - serverless_function_region = "syd1" - framework = "nextjs" - install_command = "npm install" - output_directory = ".output" - public_source = true - root_directory = "ui/src" - automatically_expose_system_environment_variables = true - git_comments = { - on_pull_request = true, - on_commit = true - } - preview_comments = true - auto_assign_custom_domains = true - git_lfs = true - function_failover = true - customer_success_code_visibility = true - git_fork_protection = true - prioritise_production_builds = true - directory_listing = true - skew_protection = "7 days" enable_affected_projects_deployments = true } `, projectSuffix, teamID)