Thanks to visit codestin.com
Credit goes to github.com

Skip to content

chore: add dynamic parameter warning if missing metadata #17809

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 9 commits into from
May 14, 2025
Merged
Changes from 1 commit
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
Next Next commit
chore: previous template versions missing dynamic param metadata
  • Loading branch information
Emyrk committed May 13, 2025
commit 6f67a9aca51a69bbf1df770060f77c54a626eca2
15 changes: 13 additions & 2 deletions coderd/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"time"

"github.com/google/uuid"
"github.com/hashicorp/hcl/v2"
"golang.org/x/sync/errgroup"
"golang.org/x/xerrors"

Expand Down Expand Up @@ -79,11 +80,21 @@
}
defer api.FileCache.Release(fileID)

staticDiagnostics := hcl.Diagnostics{}

// 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("{}")
tf, err := api.Database.GetTemplateVersionTerraformValues(ctx, templateVersion.ID)
if xerrors.Is(err, sql.ErrNoRows) {
staticDiagnostics.Append(&hcl.Diagnostic{

Check failure on line 91 in coderd/parameters.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `staticDiagnostics.Append` is not checked (errcheck)
Severity: hcl.DiagWarning,
Summary: "This template version is missing required metadata to support dynamic parameters.",
Detail: "To restore full functionality, please re-import the terraform as a new template version.",
})
}

if err == nil {
plan = tf.CachedPlan

Expand Down Expand Up @@ -148,7 +159,7 @@
result, diagnostics := preview.Preview(ctx, input, templateFS)
response := codersdk.DynamicParametersResponse{
ID: -1,
Diagnostics: previewtypes.Diagnostics(diagnostics),
Diagnostics: previewtypes.Diagnostics(diagnostics.Extend(staticDiagnostics)),
}
if result != nil {
response.Parameters = result.Parameters
Expand Down Expand Up @@ -176,7 +187,7 @@
result, diagnostics := preview.Preview(ctx, input, templateFS)
response := codersdk.DynamicParametersResponse{
ID: update.ID,
Diagnostics: previewtypes.Diagnostics(diagnostics),
Diagnostics: previewtypes.Diagnostics(diagnostics.Extend(staticDiagnostics)),
}
if result != nil {
response.Parameters = result.Parameters
Expand Down
Loading