Skip to content

Conversation

@Emyrk
Copy link
Member

@Emyrk Emyrk commented Dec 11, 2025

Presets were being created with prebuild counts, even if the preset was unable to be used for a prebuild. This creates a function that can validate prebuilds.

Related: coder/coder#21237

Goal is to prevent creating templates with prebuilds that will just spam failures.

@Emyrk Emyrk changed the title feat: ValidatePresets to validate presets for prebuild use feat: ValidatePrebuilds to validate presets for prebuild use Dec 11, 2025
@Emyrk Emyrk requested a review from SasSwart December 11, 2025 22:53
@Emyrk Emyrk requested a review from cstyan December 11, 2025 22:53
Copy link

@cstyan cstyan left a comment

Choose a reason for hiding this comment

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

approving to unblock, just had some minor comments/questions


func PresetFromBlock(block *terraform.Block) types.Preset {
func PresetFromBlock(block *terraform.Block) (tfPreset types.Preset) {
defer func() {
Copy link

Choose a reason for hiding this comment

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

did you run into a case where this can panic?

Copy link
Member Author

Choose a reason for hiding this comment

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

I wish I had receipts. I did not find a location where presets panic'd, but we've hit panics in the past when converting cty -> normal types.

Since the preset code is not tested that much, I just feel more comfortable with this safeguard in place. A panic never raises well, and we hit it a few times in the early days of parameters.

This is just being defensive.

Comment on lines +13 to +30
defer func() {
// Extra safety mechanism to ensure that if a panic occurs, we do not break
// everything else.
if r := recover(); r != nil {
tfPreset = types.Preset{
PresetData: types.PresetData{
Name: block.Label(),
},
Diagnostics: types.Diagnostics{
{
Severity: hcl.DiagError,
Summary: "Panic occurred in extracting preset. This should not happen, please report this to Coder.",
Detail: fmt.Sprintf("panic in preset extract: %+v", r),
},
},
}
}
}()
Copy link
Member Author

Choose a reason for hiding this comment

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

This is just a safety for when we use cty. It helps prevent production breaks from 1 unexpected template value.


func PresetFromBlock(block *terraform.Block) types.Preset {
func PresetFromBlock(block *terraform.Block) (tfPreset types.Preset) {
defer func() {
Copy link
Member Author

Choose a reason for hiding this comment

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

I wish I had receipts. I did not find a location where presets panic'd, but we've hit panics in the past when converting cty -> normal types.

Since the preset code is not tested that much, I just feel more comfortable with this safeguard in place. A panic never raises well, and we hit it a few times in the early days of parameters.

This is just being defensive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants