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
lang/funcs: add (console-only) TypeFunction #28501
Conversation
The type() function, which is only available for terraform console, prints out the type of a given value. This is mainly intended for debugging - it's nice to be able to print out terraform's understanding of a complex variable. This introduces a new field for Scope: ConsoleMode. When ConsoleMode is true, any additional functions intended for use in the console (only) may be added.
Codecov Report
|
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 is great! Thanks for coming back to it.
I have a couple of minor suggestions inline about empty object/tuple cases, but otherwise ✅
lang/funcs/conversion.go
Outdated
case ty.IsObjectType(): | ||
atys := ty.AttributeTypes() | ||
if len(atys) == 0 { | ||
b.WriteString("object{}") |
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.
b.WriteString("object{}") | |
b.WriteString("object({})") |
Lines up with the configuration for an empty object type constructor:
variable "foo" {
type = object({})
}
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.
great catch, thank you, those are both much better. I made those changes and added more test cases to go with 'em.
lang/funcs/conversion.go
Outdated
case ty.IsTupleType(): | ||
etys := ty.TupleElementTypes() | ||
if len(etys) == 0 { | ||
b.WriteString("tuple") |
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.
b.WriteString("tuple") | |
b.WriteString("tuple([])") |
Same method as above, the type constructor syntax for this is:
variable "foo" {
type = tuple([])
}
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. |
The
type() function
, which is only available for terraform console,prints out a string representation of the type of a given value. This is mainly intended for
debugging - it's handy to be able to directly inspect terraform's understanding
of a complex variable.
This introduces a new field for
lang.Scope
:ConsoleMode
. WhenConsoleMode
is true, any additional functions intended for use in the console (only) may be added.(with bonus
go mody tidy
cleanup)