Skip to content

Return template parameters in consistent order #2975

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 3 commits into from
Jul 13, 2022

Conversation

dwahler
Copy link
Contributor

@dwahler dwahler commented Jul 13, 2022

This PR makes the order in which we display and prompt for template parameters deterministic and consistent. It involves two different functional changes:

  • The Terraform provisioner now sorts the returned list of ParameterSchema messages to match the order of their variable blocks in the template source (first lexicographically by filename, then by line number)
  • coderd persists the variable ordering using a new parameter_schemas.index database column, and sorts by that column when querying for parameters

For template versions that existed prior to this change, the database migration initializes the index column by putting the variable names for each version in lexicographic order, since we don't know the original source order.

Fixes #2471

@dwahler dwahler marked this pull request as ready for review July 13, 2022 19:28
@dwahler dwahler requested a review from a team July 13, 2022 19:29
Copy link
Member

@kylecarbs kylecarbs left a comment

Choose a reason for hiding this comment

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

Looks good to me. Fun change!

Comment on lines +26 to +33
// Sort variables by (filename, line) to make the ordering consistent
variables := make([]*tfconfig.Variable, 0, len(module.Variables))
for _, v := range module.Variables {
variables = append(variables, v)
}
sort.Slice(variables, func(i, j int) bool {
return compareSourcePos(variables[i].Pos, variables[j].Pos)
})
Copy link
Member

Choose a reason for hiding this comment

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

This is pretty cool. It's awesome that customers will be able to control the order that variables display in the UI 👀

@dwahler dwahler merged commit b5f5e90 into main Jul 13, 2022
@dwahler dwahler deleted the dwahler/2471-template-variable-order branch July 13, 2022 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prompt for workspace/template variables in a consistent order
2 participants