-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
Introduce metadata functions
command
#32487
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Partial review before we talk about this in a moment. I've commented on the TODOs inline.
As for serialization of can
, try
and type
, I imagine we'll want to end up with something like:
"can": {
"description": "...",
"return_type": "bool",
"parameters": [
{
"name": "expression",
"type": "dynamic"
}
]
},
"try": {
"description": "...",
"return_type": "dynamic",
"variadic_parameter": {
"name": "expressions",
"description": "...",
"type": "dynamic"
}
},
"type": {
"description": "...",
"return_type": "dynamic",
"parameters": [
{
"name": "value",
"type": "dynamic"
}
]
},
Also worth noting that the type
function is only available in terraform console
. I think this information is relevant for some consumers of terraform metadata functions
, including the LS. We may want to represent this information somehow. Noting this on the RFC as it is a design decision.
fmt.Printf("Failed to serialize function %q: %s\n", k, err) // TODO! handle error | ||
continue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should return nil, err
so the error can be correctly handled in command/metadata_functions.go
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, it may be better to collect up all the functions that have failed to marshal and have Marshal()
return them in one well-formatted error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This enables easier deserialisation of types when parsing the JSON.
175017d
to
a2b308c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it worth document the command along with the JSON format on a separate page, like we do it for terraform providers schema -json
here?
Co-authored-by: kmoe <[email protected]>
Reminder for the merging maintainer: if this is a user-visible change, please update the changelog on the appropriate release branch. |
* Add metadata functions command skeleton * Export functions as JSON via cli command * Add metadata command * Add tests to jsonfunction package * WIP: Add metadata functions test * Change return_type & type in JSON to json.RawMessage This enables easier deserialisation of types when parsing the JSON. * Skip is_nullable when false * Update cli docs with metadata command * Use tfdiags to report function marshal errors * Ignore map, list and type functions * Test Marshal function with diags * Test metadata functions command output * Simplify type marshaling by using cty.Type * Add static function signatures for can and try * Update internal/command/jsonfunction/function_test.go Co-authored-by: kmoe <[email protected]> --------- Co-authored-by: kmoe <[email protected]>
I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions. |
This PR builds upon the function descriptions added in #32453 and adds a new CLI command to export those as JSON. The new command enables machine-readable function signatures (more: TF-508: Machine-readable function signatures), which can be consumed by the language server and others (CDK, website docs, ...). The first consumer will be the Terraform language server, to provide function signature information inside the editor.
UX
Metadata command:
Metadata functions command (missing flag):
Metadata functions command (error example):
Metadata functions command (valid):
Full (formatted) output
Open Questions / TODOs
TestMetadataFunctions_output
testMarshall
?can
andtry
?Target Release
1.4.x
Draft CHANGELOG entry
NEW FEATURES
terraform metadata functions -json