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

[enhanced builds] add build_machine_type option to project creation #319

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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 @@ -225,13 +225,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"`
Copy link
Collaborator

Choose a reason for hiding this comment

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

omitempty here means we'll never actually send null to the API. Probably want to remove that.

}

// GetProject retrieves information about an existing project from Vercel.
Expand Down
10 changes: 10 additions & 0 deletions vercel/data_source_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,14 @@ For more detailed information, please see the [Vercel documentation](https://ver
Optional: true,
Computed: true,
},
"build_machine_type": schema.StringAttribute{
Description: "When `on_demand_concurrent_builds` is enabled, choose the build machine: `standard` (4 vCPU, 8 GB) or `enhanced` (8 vCPU, 16GB)",
Optional: true,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't be optional on the data source. Only computed. (it's a read-only property here).

Computed: true,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we can add UseStateForUnknown, as this setting will never change based on the other settings changing, right?
Or does disabling on_demand_concurrent_builds affect this?

Copy link
Collaborator

Choose a reason for hiding this comment

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

edit: i'm a fool, this is the data source.

Validators: []validator.String{
Copy link
Collaborator

Choose a reason for hiding this comment

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

No need for validators on the data source.

stringvalidator.OneOf("standard", "enhanced"),
},
},
},
}
}
Expand Down Expand Up @@ -437,6 +445,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 @@ -503,6 +512,7 @@ func convertResponseToProjectDataSource(ctx context.Context, response client.Pro
ResourceConfig: project.ResourceConfig,
NodeVersion: project.NodeVersion,
OnDemandConcurrentBuilds: project.OnDemandConcurrentBuilds,
BuildMachineType: project.BuildMachineType,
}, nil
}

Expand Down
22 changes: 19 additions & 3 deletions vercel/resource_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,15 @@ 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: "When `on_demand_concurrent_builds` is enabled, choose the build machine: `standard` (4 vCPU, 8 GB) or `enhanced` (8 vCPU, 16GB)",
Optional: true,
Computed: true,
Validators: []validator.String{
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's figure out how to add a validator to make sure on_demand_concurrent_builds is enabled.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We have ModifyPlan on this resource - we can do it there.

stringvalidator.OneOf("standard", "enhanced"),
},
PlanModifiers: []planmodifier.String{stringplanmodifier.UseStateForUnknown()},
Copy link
Collaborator

Choose a reason for hiding this comment

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

What happens if on_demand_concurrent_builds is disabled?

},
},
}
}
Expand Down Expand Up @@ -631,6 +640,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 @@ -750,7 +760,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 @@ -831,7 +841,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 @@ -1083,7 +1093,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 @@ -1101,6 +1111,11 @@ func (r *ResourceConfig) toClientResourceConfig(onDemandConcurrentBuilds types.B
if !onDemandConcurrentBuilds.IsUnknown() {
resourceConfig.ElasticConcurrencyEnabled = onDemandConcurrentBuilds.ValueBoolPointer()
}
if !buildMachineType.IsUnknown() && *resourceConfig.ElasticConcurrencyEnabled {
Copy link
Collaborator

Choose a reason for hiding this comment

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

What if resourceConfig.ElasticConcurrencyEnabled is null?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think we need this logic here, we can just use a validator, and set buildMachineType without worrying about its relationship to elastic-concurrency.

// `build_machine_type` can only be set when `on_demand_concurrent_builds`
// is enabled.
resourceConfig.BuildMachineType = buildMachineType.ValueStringPointer()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't forget to convert standard to a null pointer?

}
return resourceConfig
}

Expand Down Expand Up @@ -1472,6 +1487,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),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't forget to convert null to standard? Also, dereferencing the pointer he could panic.

}, nil
}

Expand Down
Loading