Skip to content

Commit bf5a322

Browse files
[projects] Support setting enableAffectedProjectsDeployments (#272)
* add field to structs * change to optional * remove from data source test * add to schema * task docs * add tests * fix project name * computed -> optional * remove use state modifier * null handling * uncoerce? * omitEmpty? * remove unnecessary fields
1 parent f1323e8 commit bf5a322

File tree

6 files changed

+116
-37
lines changed

6 files changed

+116
-37
lines changed

client/project.go

+17-14
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,21 @@ type DeploymentExpiration struct {
4444

4545
// CreateProjectRequest defines the information necessary to create a project.
4646
type CreateProjectRequest struct {
47-
BuildCommand *string `json:"buildCommand"`
48-
CommandForIgnoringBuildStep *string `json:"commandForIgnoringBuildStep,omitempty"`
49-
DevCommand *string `json:"devCommand"`
50-
EnvironmentVariables []EnvironmentVariable `json:"environmentVariables,omitempty"`
51-
Framework *string `json:"framework"`
52-
GitRepository *GitRepository `json:"gitRepository,omitempty"`
53-
InstallCommand *string `json:"installCommand"`
54-
Name string `json:"name"`
55-
OIDCTokenConfig *OIDCTokenConfig `json:"oidcTokenConfig,omitempty"`
56-
OutputDirectory *string `json:"outputDirectory"`
57-
PublicSource *bool `json:"publicSource"`
58-
RootDirectory *string `json:"rootDirectory"`
59-
ServerlessFunctionRegion string `json:"serverlessFunctionRegion,omitempty"`
60-
ResourceConfig *ResourceConfig `json:"resourceConfig,omitempty"`
47+
BuildCommand *string `json:"buildCommand"`
48+
CommandForIgnoringBuildStep *string `json:"commandForIgnoringBuildStep,omitempty"`
49+
DevCommand *string `json:"devCommand"`
50+
EnableAffectedProjectsDeployments *bool `json:"enableAffectedProjectsDeployments,omitempty"`
51+
EnvironmentVariables []EnvironmentVariable `json:"environmentVariables,omitempty"`
52+
Framework *string `json:"framework"`
53+
GitRepository *GitRepository `json:"gitRepository,omitempty"`
54+
InstallCommand *string `json:"installCommand"`
55+
Name string `json:"name"`
56+
OIDCTokenConfig *OIDCTokenConfig `json:"oidcTokenConfig,omitempty"`
57+
OutputDirectory *string `json:"outputDirectory"`
58+
PublicSource *bool `json:"publicSource"`
59+
RootDirectory *string `json:"rootDirectory"`
60+
ServerlessFunctionRegion string `json:"serverlessFunctionRegion,omitempty"`
61+
ResourceConfig *ResourceConfig `json:"resourceConfig,omitempty"`
6162
}
6263

6364
// CreateProject will create a project within Vercel.
@@ -191,6 +192,7 @@ type ProjectResponse struct {
191192
ProtectionBypass map[string]ProtectionBypass `json:"protectionBypass"`
192193
AutoExposeSystemEnvVars *bool `json:"autoExposeSystemEnvs"`
193194
EnablePreviewFeedback *bool `json:"enablePreviewFeedback"`
195+
EnableAffectedProjectsDeployments *bool `json:"enableAffectedProjectsDeployments"`
194196
AutoAssignCustomDomains bool `json:"autoAssignCustomDomains"`
195197
GitLFS bool `json:"gitLFS"`
196198
ServerlessFunctionZeroConfigFailover bool `json:"serverlessFunctionZeroConfigFailover"`
@@ -291,6 +293,7 @@ type UpdateProjectRequest struct {
291293
OptionsAllowlist *OptionsAllowlist `json:"optionsAllowlist"`
292294
AutoExposeSystemEnvVars bool `json:"autoExposeSystemEnvs"`
293295
EnablePreviewFeedback *bool `json:"enablePreviewFeedback"`
296+
EnableAffectedProjectsDeployments *bool `json:"enableAffectedProjectsDeployments,omitempty"`
294297
AutoAssignCustomDomains bool `json:"autoAssignCustomDomains"`
295298
GitLFS bool `json:"gitLFS"`
296299
ServerlessFunctionZeroConfigFailover bool `json:"serverlessFunctionZeroConfigFailover"`

docs/data-sources/project.md

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ data "vercel_project" "example" {
4343
- `customer_success_code_visibility` (Boolean) Allows Vercel Customer Support to inspect all Deployments' source code in this project to assist with debugging.
4444
- `dev_command` (String) The dev command for this project. If omitted, this value will be automatically detected.
4545
- `directory_listing` (Boolean) If no index file is present within a directory, the directory contents will be displayed.
46+
- `enable_affected_projects_deployments` (Boolean) When enabled, Vercel will automatically deploy all projects that are affected by a change to this project.
4647
- `environment` (Attributes Set) A list of environment variables that should be configured for the project. (see [below for nested schema](#nestedatt--environment))
4748
- `framework` (String) The framework that is being used for this project. If omitted, no framework is selected.
4849
- `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.

docs/resources/project.md

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ resource "vercel_project" "example" {
6161
- `customer_success_code_visibility` (Boolean) Allows Vercel Customer Support to inspect all Deployments' source code in this project to assist with debugging.
6262
- `dev_command` (String) The dev command for this project. If omitted, this value will be automatically detected.
6363
- `directory_listing` (Boolean) If no index file is present within a directory, the directory contents will be displayed.
64+
- `enable_affected_projects_deployments` (Boolean) When enabled, Vercel will automatically deploy all projects that are affected by a change to this project.
6465
- `environment` (Attributes Set) A set of Environment Variables that should be configured for the project. (see [below for nested schema](#nestedatt--environment))
6566
- `framework` (String) The framework that is being used for this project. If omitted, no framework is selected.
6667
- `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.

vercel/data_source_project.go

+6
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,10 @@ For more detailed information, please see the [Vercel documentation](https://ver
278278
Computed: true,
279279
Description: "Specifies whether the source code and logs of the deployments for this project should be public or not.",
280280
},
281+
"enable_affected_projects_deployments": schema.BoolAttribute{
282+
Computed: true,
283+
Description: "When enabled, Vercel will automatically deploy all projects that are affected by a change to this project.",
284+
},
281285
"root_directory": schema.StringAttribute{
282286
Computed: true,
283287
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.",
@@ -404,6 +408,7 @@ type ProjectDataSource struct {
404408
GitForkProtection types.Bool `tfsdk:"git_fork_protection"`
405409
PrioritiseProductionBuilds types.Bool `tfsdk:"prioritise_production_builds"`
406410
DirectoryListing types.Bool `tfsdk:"directory_listing"`
411+
EnableAffectedProjectsDeployments types.Bool `tfsdk:"enable_affected_projects_deployments"`
407412
SkewProtection types.String `tfsdk:"skew_protection"`
408413
ResourceConfig *ResourceConfig `tfsdk:"resource_config"`
409414
}
@@ -472,6 +477,7 @@ func convertResponseToProjectDataSource(ctx context.Context, response client.Pro
472477
GitForkProtection: project.GitForkProtection,
473478
PrioritiseProductionBuilds: project.PrioritiseProductionBuilds,
474479
DirectoryListing: project.DirectoryListing,
480+
EnableAffectedProjectsDeployments: project.EnableAffectedProjectsDeployments,
475481
SkewProtection: project.SkewProtection,
476482
ResourceConfig: project.ResourceConfig,
477483
}, nil

vercel/resource_project.go

+33-23
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,10 @@ At this time you cannot use a Vercel Project resource with in-line ` + "`environ
432432
PlanModifiers: []planmodifier.Bool{boolplanmodifier.UseStateForUnknown()},
433433
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",
434434
},
435+
"enable_affected_projects_deployments": schema.BoolAttribute{
436+
Optional: true,
437+
Description: "When enabled, Vercel will automatically deploy all projects that are affected by a change to this project.",
438+
},
435439
"git_comments": schema.SingleNestedAttribute{
436440
Description: "Configuration for Git Comments.",
437441
Optional: true,
@@ -604,6 +608,7 @@ type Project struct {
604608
GitForkProtection types.Bool `tfsdk:"git_fork_protection"`
605609
PrioritiseProductionBuilds types.Bool `tfsdk:"prioritise_production_builds"`
606610
DirectoryListing types.Bool `tfsdk:"directory_listing"`
611+
EnableAffectedProjectsDeployments types.Bool `tfsdk:"enable_affected_projects_deployments"`
607612
SkewProtection types.String `tfsdk:"skew_protection"`
608613
ResourceConfig *ResourceConfig `tfsdk:"resource_config"`
609614
}
@@ -703,19 +708,20 @@ func parseEnvironment(ctx context.Context, vars []EnvironmentItem) (out []client
703708
func (p *Project) toCreateProjectRequest(ctx context.Context, envs []EnvironmentItem) (req client.CreateProjectRequest, diags diag.Diagnostics) {
704709
clientEnvs, diags := parseEnvironment(ctx, envs)
705710
return client.CreateProjectRequest{
706-
BuildCommand: p.BuildCommand.ValueStringPointer(),
707-
CommandForIgnoringBuildStep: p.IgnoreCommand.ValueStringPointer(),
708-
DevCommand: p.DevCommand.ValueStringPointer(),
709-
EnvironmentVariables: clientEnvs,
710-
Framework: p.Framework.ValueStringPointer(),
711-
GitRepository: p.GitRepository.toCreateProjectRequest(),
712-
InstallCommand: p.InstallCommand.ValueStringPointer(),
713-
Name: p.Name.ValueString(),
714-
OIDCTokenConfig: p.OIDCTokenConfig.toCreateProjectRequest(),
715-
OutputDirectory: p.OutputDirectory.ValueStringPointer(),
716-
PublicSource: p.PublicSource.ValueBoolPointer(),
717-
RootDirectory: p.RootDirectory.ValueStringPointer(),
718-
ServerlessFunctionRegion: p.ServerlessFunctionRegion.ValueString(),
711+
BuildCommand: p.BuildCommand.ValueStringPointer(),
712+
CommandForIgnoringBuildStep: p.IgnoreCommand.ValueStringPointer(),
713+
DevCommand: p.DevCommand.ValueStringPointer(),
714+
EnableAffectedProjectsDeployments: p.EnableAffectedProjectsDeployments.ValueBoolPointer(),
715+
EnvironmentVariables: clientEnvs,
716+
Framework: p.Framework.ValueStringPointer(),
717+
GitRepository: p.GitRepository.toCreateProjectRequest(),
718+
InstallCommand: p.InstallCommand.ValueStringPointer(),
719+
Name: p.Name.ValueString(),
720+
OIDCTokenConfig: p.OIDCTokenConfig.toCreateProjectRequest(),
721+
OutputDirectory: p.OutputDirectory.ValueStringPointer(),
722+
PublicSource: p.PublicSource.ValueBoolPointer(),
723+
RootDirectory: p.RootDirectory.ValueStringPointer(),
724+
ServerlessFunctionRegion: p.ServerlessFunctionRegion.ValueString(),
719725
}, diags
720726
}
721727

@@ -764,6 +770,7 @@ func (p *Project) toUpdateProjectRequest(ctx context.Context, oldName string) (r
764770
OptionsAllowlist: p.OptionsAllowlist.toUpdateProjectRequest(),
765771
AutoExposeSystemEnvVars: p.AutoExposeSystemEnvVars.ValueBool(),
766772
EnablePreviewFeedback: p.PreviewComments.ValueBoolPointer(),
773+
EnableAffectedProjectsDeployments: p.EnableAffectedProjectsDeployments.ValueBoolPointer(),
767774
AutoAssignCustomDomains: p.AutoAssignCustomDomains.ValueBool(),
768775
GitLFS: p.GitLFS.ValueBool(),
769776
ServerlessFunctionZeroConfigFailover: p.FunctionFailover.ValueBool(),
@@ -1042,20 +1049,22 @@ func (t *OptionsAllowlist) toUpdateProjectRequest() *client.OptionsAllowlist {
10421049
* This is implemented in the below uncoerceString and uncoerceBool functions.
10431050
*/
10441051
type projectCoercedFields struct {
1045-
BuildCommand types.String
1046-
DevCommand types.String
1047-
InstallCommand types.String
1048-
OutputDirectory types.String
1049-
PublicSource types.Bool
1052+
BuildCommand types.String
1053+
DevCommand types.String
1054+
InstallCommand types.String
1055+
OutputDirectory types.String
1056+
PublicSource types.Bool
1057+
EnableAffectedProjectsDeployments types.Bool
10501058
}
10511059

10521060
func (p *Project) coercedFields() projectCoercedFields {
10531061
return projectCoercedFields{
1054-
BuildCommand: p.BuildCommand,
1055-
DevCommand: p.DevCommand,
1056-
InstallCommand: p.InstallCommand,
1057-
OutputDirectory: p.OutputDirectory,
1058-
PublicSource: p.PublicSource,
1062+
BuildCommand: p.BuildCommand,
1063+
DevCommand: p.DevCommand,
1064+
InstallCommand: p.InstallCommand,
1065+
OutputDirectory: p.OutputDirectory,
1066+
PublicSource: p.PublicSource,
1067+
EnableAffectedProjectsDeployments: p.EnableAffectedProjectsDeployments,
10591068
}
10601069
}
10611070

@@ -1361,6 +1370,7 @@ func convertResponseToProject(ctx context.Context, response client.ProjectRespon
13611370
ProtectionBypassForAutomationSecret: protectionBypassSecret,
13621371
AutoExposeSystemEnvVars: types.BoolPointerValue(response.AutoExposeSystemEnvVars),
13631372
PreviewComments: types.BoolPointerValue(response.EnablePreviewFeedback),
1373+
EnableAffectedProjectsDeployments: uncoerceBool(fields.EnableAffectedProjectsDeployments, types.BoolPointerValue(response.EnableAffectedProjectsDeployments)),
13641374
AutoAssignCustomDomains: types.BoolValue(response.AutoAssignCustomDomains),
13651375
GitLFS: types.BoolValue(response.GitLFS),
13661376
FunctionFailover: types.BoolValue(response.ServerlessFunctionZeroConfigFailover),

vercel/resource_project_test.go

+58
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,35 @@ func TestAcc_ProjectImport(t *testing.T) {
411411
})
412412
}
413413

414+
func TestAcc_ProjectEnablingAffectedProjectDeployments(t *testing.T) {
415+
projectSuffix := acctest.RandString(16)
416+
resource.Test(t, resource.TestCase{
417+
PreCheck: func() { testAccPreCheck(t) },
418+
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
419+
CheckDestroy: testAccProjectDestroy("vercel_project.test", testTeam()),
420+
Steps: []resource.TestStep{
421+
{
422+
Config: testAccProjectConfigWithoutEnableAffectedSet(projectSuffix, teamIDConfig()),
423+
Check: resource.ComposeAggregateTestCheckFunc(
424+
resource.TestCheckNoResourceAttr("vercel_project.test", "enable_affected_projects_deployments"),
425+
),
426+
},
427+
{
428+
Config: testAccProjectConfigWithEnableAffectedTrue(projectSuffix, teamIDConfig()),
429+
Check: resource.ComposeAggregateTestCheckFunc(
430+
resource.TestCheckResourceAttr("vercel_project.test", "enable_affected_projects_deployments", "true"),
431+
),
432+
},
433+
{
434+
Config: testAccProjectConfigWithEnableAffectedFalse(projectSuffix, teamIDConfig()),
435+
Check: resource.ComposeAggregateTestCheckFunc(
436+
resource.TestCheckResourceAttr("vercel_project.test", "enable_affected_projects_deployments", "false"),
437+
),
438+
},
439+
},
440+
})
441+
}
442+
414443
func testAccProjectExists(n, teamID string) resource.TestCheckFunc {
415444
return func(s *terraform.State) error {
416445
rs, ok := s.RootModule().Resources[n]
@@ -833,6 +862,35 @@ resource "vercel_project" "test" {
833862
`, projectSuffix, teamID)
834863
}
835864

865+
func testAccProjectConfigWithoutEnableAffectedSet(projectSuffix, teamID string) string {
866+
return fmt.Sprintf(`
867+
resource "vercel_project" "test" {
868+
name = "test-acc-project-%s"
869+
%s
870+
}
871+
`, projectSuffix, teamID)
872+
}
873+
874+
func testAccProjectConfigWithEnableAffectedFalse(projectSuffix, teamID string) string {
875+
return fmt.Sprintf(`
876+
resource "vercel_project" "test" {
877+
name = "test-acc-project-%s"
878+
%s
879+
enable_affected_projects_deployments = false
880+
}
881+
`, projectSuffix, teamID)
882+
}
883+
884+
func testAccProjectConfigWithEnableAffectedTrue(projectSuffix, teamID string) string {
885+
return fmt.Sprintf(`
886+
resource "vercel_project" "test" {
887+
name = "test-acc-project-%s"
888+
%s
889+
enable_affected_projects_deployments = true
890+
}
891+
`, projectSuffix, teamID)
892+
}
893+
836894
func testAccProjectConfig(projectSuffix, teamID string) string {
837895
return fmt.Sprintf(`
838896
resource "vercel_project" "test" {

0 commit comments

Comments
 (0)