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

[project] Support build_machine_type in project declarations #345

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
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 @@ -231,13 +231,15 @@ type ResourceConfigResponse struct {
FunctionDefaultTimeout *int64 `json:"functionDefaultTimeout"`
Fluid bool `json:"fluid"`
ElasticConcurrencyEnabled bool `json:"elasticConcurrencyEnabled"`
BuildMachineType string `json:"buildMachineType"`
}

type ResourceConfig struct {
FunctionDefaultMemoryType *string `json:"functionDefaultMemoryType,omitempty"`
FunctionDefaultTimeout *int64 `json:"functionDefaultTimeout,omitempty"`
Fluid *bool `json:"fluid,omitempty"`
ElasticConcurrencyEnabled *bool `json:"elasticConcurrencyEnabled,omitempty"`
BuildMachineType *string `json:"buildMachineType,omitempty"`
}

// GetProject retrieves information about an existing project from 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 @@ -33,6 +33,7 @@ data "vercel_project" "example" {

### Optional

- `build_machine_type` (String) The build machine type to use for this project.
- `on_demand_concurrent_builds` (Boolean) Instantly scale build capacity to skip the queue, even if all build slots are in use. You can also choose a larger build machine; charges apply per minute if it exceeds your team's default.
- `team_id` (String) The team ID the project exists beneath. Required when configuring a team resource if a default team has not been set in the provider.

Expand Down
1 change: 1 addition & 0 deletions docs/resources/project.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ resource "vercel_project" "example" {
- `auto_assign_custom_domains` (Boolean) Automatically assign custom production domains after each Production deployment via merge to the production branch or Vercel CLI deploy with --prod. Defaults to `true`
- `automatically_expose_system_environment_variables` (Boolean) 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
- `build_command` (String) The build command for this project. If omitted, this value will be automatically detected.
- `build_machine_type` (String) The build machine type to use for this project. Must be one of "enhanced".
- `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.
Expand Down
7 changes: 7 additions & 0 deletions vercel/data_source_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,11 @@ For more detailed information, please see the [Vercel documentation](https://ver
Optional: true,
Computed: true,
},
"build_machine_type": schema.StringAttribute{
Description: "The build machine type to use for this project.",
Optional: true,
Computed: true,
},
},
}
}
Expand Down Expand Up @@ -438,6 +443,7 @@ type ProjectDataSource struct {
ResourceConfig types.Object `tfsdk:"resource_config"`
NodeVersion types.String `tfsdk:"node_version"`
OnDemandConcurrentBuilds types.Bool `tfsdk:"on_demand_concurrent_builds"`
BuildMachineTYpe types.String `tfsdk:"build_machine_type"`
}

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

Expand Down
2 changes: 2 additions & 0 deletions vercel/data_source_project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func TestAcc_ProjectDataSource(t *testing.T) {
resource.TestCheckResourceAttr("data.vercel_project.test", "oidc_token_config.enabled", "true"),
resource.TestCheckResourceAttr("data.vercel_project.test", "oidc_token_config.issuer_mode", "team"),
resource.TestCheckResourceAttr("data.vercel_project.test", "on_demand_concurrent_builds", "true"),
resource.TestCheckResourceAttr("data.vercel_project.test", "build_machine_type", "enhanced"),
),
},
},
Expand Down Expand Up @@ -141,6 +142,7 @@ resource "vercel_project" "test" {
issuer_mode = "team"
}
on_demand_concurrent_builds = true
build_machine_type = "enhanced"
}

data "vercel_project" "test" {
Expand Down
19 changes: 16 additions & 3 deletions vercel/resource_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,14 @@ At this time you cannot use a Vercel Project resource with in-line ` + "`environ
Computed: true,
PlanModifiers: []planmodifier.Bool{boolplanmodifier.UseStateForUnknown()},
},
"build_machine_type": schema.StringAttribute{
Description: "The build machine type to use for this project. Must be one of \"enhanced\".",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔜

Optional: true,
Computed: true,
Validators: []validator.String{
stringvalidator.OneOf("enhanced"),
},
},
},
}
}
Expand Down Expand Up @@ -635,6 +643,7 @@ type Project struct {
SkewProtection types.String `tfsdk:"skew_protection"`
ResourceConfig types.Object `tfsdk:"resource_config"`
OnDemandConcurrentBuilds types.Bool `tfsdk:"on_demand_concurrent_builds"`
BuildMachineType types.String `tfsdk:"build_machine_type"`
}

type GitComments struct {
Expand Down Expand Up @@ -754,7 +763,7 @@ func (p *Project) toCreateProjectRequest(ctx context.Context, envs []Environment
PublicSource: p.PublicSource.ValueBoolPointer(),
RootDirectory: p.RootDirectory.ValueStringPointer(),
ServerlessFunctionRegion: p.ServerlessFunctionRegion.ValueString(),
ResourceConfig: resourceConfig.toClientResourceConfig(p.OnDemandConcurrentBuilds),
ResourceConfig: resourceConfig.toClientResourceConfig(p.OnDemandConcurrentBuilds, p.BuildMachineType),
EnablePreviewFeedback: oneBoolPointer(p.EnablePreviewFeedback, p.PreviewComments),
EnableProductionFeedback: p.EnableProductionFeedback.ValueBoolPointer(),
}, diags
Expand Down Expand Up @@ -835,7 +844,7 @@ func (p *Project) toUpdateProjectRequest(ctx context.Context, oldName string) (r
DirectoryListing: p.DirectoryListing.ValueBool(),
SkewProtectionMaxAge: toSkewProtectionAge(p.SkewProtection),
GitComments: gc.toUpdateProjectRequest(),
ResourceConfig: resourceConfig.toClientResourceConfig(p.OnDemandConcurrentBuilds),
ResourceConfig: resourceConfig.toClientResourceConfig(p.OnDemandConcurrentBuilds, p.BuildMachineType),
NodeVersion: p.NodeVersion.ValueString(),
}, nil
}
Expand Down Expand Up @@ -1087,7 +1096,7 @@ func (p *Project) resourceConfig(ctx context.Context) (rc *ResourceConfig, diags
return rc, diags
}

func (r *ResourceConfig) toClientResourceConfig(onDemandConcurrentBuilds types.Bool) *client.ResourceConfig {
func (r *ResourceConfig) toClientResourceConfig(onDemandConcurrentBuilds types.Bool, buildMachineType types.String) *client.ResourceConfig {
if r == nil {
return nil
}
Expand All @@ -1105,6 +1114,9 @@ func (r *ResourceConfig) toClientResourceConfig(onDemandConcurrentBuilds types.B
if !onDemandConcurrentBuilds.IsUnknown() {
resourceConfig.ElasticConcurrencyEnabled = onDemandConcurrentBuilds.ValueBoolPointer()
}
if !buildMachineType.IsUnknown() {
resourceConfig.BuildMachineType = buildMachineType.ValueStringPointer()
}
return resourceConfig
}

Expand Down Expand Up @@ -1476,6 +1488,7 @@ func convertResponseToProject(ctx context.Context, response client.ProjectRespon
ResourceConfig: resourceConfig,
NodeVersion: types.StringValue(response.NodeVersion),
OnDemandConcurrentBuilds: types.BoolValue(response.ResourceConfig.ElasticConcurrencyEnabled),
BuildMachineType: types.StringValue(response.ResourceConfig.BuildMachineType),
}, nil
}

Expand Down
3 changes: 3 additions & 0 deletions vercel/resource_project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ func TestAcc_Project(t *testing.T) {
resource.TestCheckResourceAttr("vercel_project.test", "resource_config.function_default_cpu_type", "standard"),
resource.TestCheckResourceAttr("vercel_project.test", "resource_config.function_default_timeout", "60"),
resource.TestCheckResourceAttr("vercel_project.test", "on_demand_concurrent_builds", "true"),
resource.TestCheckResourceAttr("vercel_project.test", "build_machine_type", "enhanced"),
),
},
// Update testing
Expand All @@ -100,6 +101,7 @@ func TestAcc_Project(t *testing.T) {
resource.TestCheckResourceAttr("vercel_project.test", "enable_preview_feedback", "false"),
resource.TestCheckResourceAttr("vercel_project.test", "enable_production_feedback", "true"),
resource.TestCheckResourceAttr("vercel_project.test", "on_demand_concurrent_builds", "false"),
resource.TestCheckResourceAttr("vercel_project.test", "build_machine_type", ""),
),
},
// Test mutual exclusivity validation
Expand Down Expand Up @@ -1066,6 +1068,7 @@ resource "vercel_project" "test" {
}
]
on_demand_concurrent_builds = true
build_machine_type = "enhanced"
}
`, projectSuffix)
}