-
Notifications
You must be signed in to change notification settings - Fork 1
feat: Preview can now show presets and validate them #149
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
type Preset struct { | ||
PresetData | ||
// Diagnostics is used to store any errors that occur during parsing | ||
// of the parameter. |
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.
// of the parameter. | |
// of the preset. |
params := block.GetAttribute("parameters").AsMapValue() | ||
for presetParamName, presetParamValue := range params.Value() { | ||
p.Parameters[presetParamName] = presetParamValue | ||
} |
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 wonder what happens on unknown
or null
values 🤔
continue | ||
} | ||
templateParam := parameters[templateParamIndex] | ||
for _, diag := range templateParam.Valid(types.StringLiteral(paramValue)) { |
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.
Nice 👍
func presets(modules terraform.Modules, parameters []types.Parameter) ([]types.Preset, hcl.Diagnostics) { | ||
diags := make(hcl.Diagnostics, 0) | ||
presets := make([]types.Preset, 0) |
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.
the function name presets
is shadowed by the variable. Would be nice if they were different
@@ -208,3 +208,70 @@ func tfVarFiles(path string, dir fs.FS) ([]string, error) { | |||
} | |||
return files, nil | |||
} | |||
|
|||
func PreviewPresets(ctx context.Context, dir fs.FS) ([]types.Preset, hcl.Diagnostics) { |
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.
Ideally we'd just put this in Preview
. And if the diagnostics are scoped to Presets
, then we can essentially ignore preset diagnostics when they are not relevant.
But I do see it can throw top level diags.
So maybe there is a way we can filter diags by certain categories 🤔
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 had it in Preview
initially, but then I moved it out as my understanding of the codebase evolved. I think it has evolved further such that we can move it back into Preview
, yes.
This PR provides a mechanism to "lint" presets to ensure that they refer to parameters that actually exist and define values that are actually valid for those parameters.
Relates to: coder/coder#17333