Skip to content

chore: use static params when dynamic param metadata is missing #17836

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
merged 25 commits into from
May 16, 2025
Merged
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
Working prototype
  • Loading branch information
Emyrk committed May 14, 2025
commit d9c5ce58df84196cd0e18c2beb88b8d05bdf6b4e
10 changes: 8 additions & 2 deletions coderd/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
sdkproto "github.com/coder/coder/v2/provisionersdk/proto"
"github.com/coder/preview"
previewtypes "github.com/coder/preview/types"
"github.com/coder/terraform-provider-coder/v2/provider"
"github.com/coder/websocket"
)

Expand Down Expand Up @@ -194,7 +195,7 @@
// Having the Terraform plan available for the evaluation engine is helpful
// for populating values from data blocks, but isn't strictly required. If
// we don't have a cached plan available, we just use an empty one instead.
plan := json.RawMessage("{}")

Check failure on line 198 in coderd/parameters.go

View workflow job for this annotation

GitHub Actions / lint

ineffectual assignment to plan (ineffassign)
plan = tf.CachedPlan

if tf.CachedModuleFiles.Valid {
Expand Down Expand Up @@ -226,7 +227,7 @@
Owner: owner,
}

return func(ctx context.Context, values map[string]string) (*preview.Output, hcl.Diagnostics) {

Check failure on line 230 in coderd/parameters.go

View workflow job for this annotation

GitHub Actions / lint

unused-parameter: parameter 'values' seems to be unused, consider removing or renaming it as _ (revive)
return preview.Preview(ctx, input, templateFS)
}, closeFiles, true
}
Expand All @@ -250,8 +251,8 @@
Mutable: it.Mutable,
DefaultValue: previewtypes.StringLiteral(it.DefaultValue),
Icon: it.Icon,
Options: nil,
Validations: nil,
Options: make([]*previewtypes.ParameterOption, 0),
Validations: make([]*previewtypes.ParameterValidation, 0),
Required: it.Required,
Order: int64(it.DisplayOrder),
Ephemeral: it.Ephemeral,
Expand Down Expand Up @@ -303,18 +304,23 @@
})
}

// Take the form type from the ValidateFormType function. This is a bit
// unfortunate we have to do this, but it will return the default form_type
// for a given set of conditions.
_, param.FormType, _ = provider.ValidateFormType(provider.OptionType(param.Type), len(param.Options), param.FormType)

param.Diagnostics = previewtypes.Diagnostics(param.Valid(param.Value))
params = append(params, param)
}

return func(ctx context.Context, values map[string]string) (*preview.Output, hcl.Diagnostics) {

Check failure on line 316 in coderd/parameters.go

View workflow job for this annotation

GitHub Actions / lint

unused-parameter: parameter 'ctx' seems to be unused, consider removing or renaming it as _ (revive)
for i := range params {
param := &params[i]
paramValue, ok := values[param.Name]
if ok {
param.Value = previewtypes.StringLiteral(paramValue)
} else {
paramValue = param.DefaultValue.AsString()

Check failure on line 323 in coderd/parameters.go

View workflow job for this annotation

GitHub Actions / lint

ineffectual assignment to paramValue (ineffassign)
}
param.Diagnostics = previewtypes.Diagnostics(param.Valid(param.Value))
}
Expand Down
Loading