- Notifications
You must be signed in to change notification settings - Fork928
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ALTER TABLE parameter_schemas DROP COLUMN index; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
-- temporarily create index column as nullable | ||
ALTER TABLE parameter_schemas ADD COLUMN index integer; | ||
-- initialize ordering for existing parameters | ||
WITH tmp AS ( | ||
SELECT id, row_number() OVER (PARTITION BY job_id ORDER BY name) AS index | ||
FROM parameter_schemas | ||
) | ||
UPDATE parameter_schemas | ||
SET index = tmp.index | ||
FROM tmp | ||
WHERE parameter_schemas.id = tmp.id; | ||
-- all rows should now be initialized | ||
ALTER TABLE parameter_schemas ALTER COLUMN index SET NOT NULL; |
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -5,6 +5,7 @@ import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"sort" | ||
"strings" | ||
"github.com/hashicorp/terraform-config-inspect/tfconfig" | ||
@@ -22,8 +23,17 @@ func (*server) Parse(request *proto.Parse_Request, stream proto.DRPCProvisioner_ | ||
return xerrors.Errorf("load module: %s", formatDiagnostics(request.Directory, diags)) | ||
} | ||
// 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) | ||
}) | ||
Comment on lines +26 to +33 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 👀 | ||
parameters := make([]*proto.ParameterSchema, 0, len(variables)) | ||
for _, v := range variables { | ||
schema, err := convertVariableToParameter(v) | ||
if err != nil { | ||
return xerrors.Errorf("convert variable %q: %w", v.Name, err) | ||
@@ -129,3 +139,10 @@ func formatDiagnostics(baseDir string, diags tfconfig.Diagnostics) string { | ||
return spacer + strings.TrimSpace(msgs.String()) | ||
} | ||
func compareSourcePos(x, y tfconfig.SourcePos) bool { | ||
if x.Filename != y.Filename { | ||
return x.Filename < y.Filename | ||
} | ||
return x.Line < y.Line | ||
} |