Skip to content
Merged
Show file tree
Hide file tree
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
Prev Previous commit
Next Next commit
add provisioenr version check too
  • Loading branch information
Emyrk committed May 20, 2025
commit 93b09744163865093ddf9fbd5e874410ba6f8de0
11 changes: 4 additions & 7 deletions coderd/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import (
"golang.org/x/sync/errgroup"
"golang.org/x/xerrors"

"github.com/coder/coder/v2/apiversion"
"github.com/coder/coder/v2/coderd/database"
"github.com/coder/coder/v2/coderd/database/dbauthz"
"github.com/coder/coder/v2/coderd/files"
"github.com/coder/coder/v2/coderd/httpapi"
"github.com/coder/coder/v2/coderd/httpmw"
"github.com/coder/coder/v2/coderd/util/ptr"
"github.com/coder/coder/v2/coderd/wsbuilder"
"github.com/coder/coder/v2/codersdk"
"github.com/coder/coder/v2/codersdk/wsjson"
sdkproto "github.com/coder/coder/v2/provisionersdk/proto"
Expand Down Expand Up @@ -69,13 +69,10 @@ func (api *API) templateVersionDynamicParameters(rw http.ResponseWriter, r *http
return
}

major, minor, err := apiversion.Parse(tf.ProvisionerdVersion)
// If the api version is not valid or less than 1.5, we need to use the static parameters
useStaticParams := err != nil || major < 1 || (major == 1 && minor < 6)
if useStaticParams {
api.handleStaticParameters(rw, r, templateVersion.ID)
} else {
if wsbuilder.ProvisionerVersionSupportsDynamicParameters(tf.ProvisionerdVersion) {
api.handleDynamicParameters(rw, r, tf, templateVersion)
} else {
api.handleStaticParameters(rw, r, templateVersion.ID)
}
}

Expand Down
34 changes: 34 additions & 0 deletions coderd/wsbuilder/wsbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/hashicorp/hcl/v2"
"github.com/hashicorp/hcl/v2/hclsyntax"

"github.com/coder/coder/v2/apiversion"
"github.com/coder/coder/v2/coderd/rbac/policy"
"github.com/coder/coder/v2/coderd/util/ptr"
"github.com/coder/coder/v2/provisioner/terraform/tfparse"
Expand Down Expand Up @@ -69,6 +70,7 @@ type Builder struct {
template *database.Template
templateVersion *database.TemplateVersion
templateVersionJob *database.ProvisionerJob
terraformValues *database.TemplateVersionTerraformValue
templateVersionParameters *[]database.TemplateVersionParameter
templateVersionVariables *[]database.TemplateVersionVariable
templateVersionWorkspaceTags *[]database.TemplateVersionWorkspaceTag
Expand Down Expand Up @@ -526,6 +528,22 @@ func (b *Builder) getTemplateVersionID() (uuid.UUID, error) {
return bld.TemplateVersionID, nil
}

func (b *Builder) getTemplateTerraformValues() (*database.TemplateVersionTerraformValue, error) {
if b.terraformValues != nil {
return b.terraformValues, nil
}
v, err := b.getTemplateVersion()
if err != nil {
return nil, xerrors.Errorf("get template version so we can get terraform values: %w", err)
}
vals, err := b.store.GetTemplateVersionTerraformValues(b.ctx, v.ID)
if err != nil {
return nil, xerrors.Errorf("get template version terraform values %s: %w", v.JobID, err)
}
b.terraformValues = &vals
return b.terraformValues, err
}

func (b *Builder) getLastBuild() (*database.WorkspaceBuild, error) {
if b.lastBuild != nil {
return b.lastBuild, nil
Expand Down Expand Up @@ -1007,6 +1025,15 @@ func (b *Builder) usingDynamicParameters() bool {
return false
}

vals, err := b.getTemplateTerraformValues()
if err != nil {
return false
}

if !ProvisionerVersionSupportsDynamicParameters(vals.ProvisionerdVersion) {
return false
}

if b.dynamicParametersEnabled != nil {
return *b.dynamicParametersEnabled
}
Expand All @@ -1017,3 +1044,10 @@ func (b *Builder) usingDynamicParameters() bool {
}
return !tpl.UseClassicParameterFlow
}

func ProvisionerVersionSupportsDynamicParameters(version string) bool {
major, minor, err := apiversion.Parse(version)
// If the api version is not valid or less than 1.6, we need to use the static parameters
useStaticParams := err != nil || major < 1 || (major == 1 && minor < 6)
return !useStaticParams
}
Comment on lines +1050 to +1055
Copy link
Member

Choose a reason for hiding this comment

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

nit: this feels like something that might want to be in provisionersdk

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm. Really tough to know where to place it. I'm going to keep it with wsbuilder right now, since it only affects workspace builds.

I think I'll create a new package for dynamic params more generally as more code is added to support the feature, and I can move it there.

24 changes: 24 additions & 0 deletions coderd/wsbuilder/wsbuilder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,30 @@ func TestWorkspaceBuildWithPreset(t *testing.T) {
req.NoError(err)
}

func TestProvisionerVersionSupportsDynamicParameters(t *testing.T) {
t.Parallel()

for v, dyn := range map[string]bool{
"": false,
"na": false,
"0.0": false,
"0.10": false,
"1.4": false,
"1.5": false,
"1.6": true,
"1.7": true,
"1.8": true,
"2.0": true,
"2.17": true,
"4.0": true,
} {
t.Run(v, func(t *testing.T) {
does := wsbuilder.ProvisionerVersionSupportsDynamicParameters(v)
require.Equal(t, dyn, does)
})
}
}

type txExpect func(mTx *dbmock.MockStore)

func expectDB(t *testing.T, opts ...txExpect) *dbmock.MockStore {
Expand Down
Loading