-
Notifications
You must be signed in to change notification settings - Fork 3
feat: ValidatePrebuilds to validate presets for prebuild use #194
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
base: main
Are you sure you want to change the base?
Conversation
cstyan
left a comment
There was a problem hiding this 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() { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
| 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), | ||
| }, | ||
| }, | ||
| } | ||
| } | ||
| }() |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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.
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.