-
Notifications
You must be signed in to change notification settings - Fork 63
Throw error when Tuple contains mixed Types #233
Conversation
In Terraform's type system, lists and maps must have consistent element types. However, the Kubernetes API spec defines certain fields as type IntOrString, which can lead to using more than one type in a list. Since Terraform has no equivalent type to translate this to, the solution is make each element of the List or Map the same type. Validation will fail if more than one type is used. Fixes hashicorp#231
a701fc4
to
fe2d2fa
Compare
This still panics when it hits a list that contains multiple types. However, it does not panic when the list is all one type. So it's a step closer to working...
There might be a better way to do this, since the SDK includes lists of the Types inside of both Tuples and Objects. https://pkg.go.dev/github.com/hashicorp/[email protected]/tftypes#Object https://pkg.go.dev/github.com/hashicorp/[email protected]/tftypes#Tuple But I couldn't find a way to access those, so I converted the Values into Go values instead. |
This is working for the first 3 conditions I tested for: Tuple containing Objects of type String and Number. This fails validation, as it should:
It passes validation when these are all Strings, as it should:
And it fails validation, as it should, for multiple types within a Tuple (without Objects):
But this is one case where it should not fail validation. It's a valid use case for a Tuple containing an Object of multiple Types:
|
I was originally trying to implement this as requested by @alexsomesan. He walked me through what the implementation would be like:
But after exploring this path, I found that sometimes a Tuple should have different types, so I wasn't able to implement this in the validation function as requested. Instead, I'm now validating that each call to tftypes.NewValue() will not cause a panic. There's a built-in function for validation prior to using NewValue, ValidateValue, which can tell us if the value is compatible with the Type that we're converting it to. I'm opening a new PR for this. |
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 issues. |
In Terraform's type system, Lists and Maps must have consistent element types. However, the Kubernetes API spec defines certain fields as type IntOrString, which can lead to using more than one type in a list. Since Terraform has no equivalent type to translate this to, the solution is make each element of the List or Map the same type. Validation will fail if more than one type is used.
Fixes #231
Description
Release Note
Release note for CHANGELOG:
References
Community Note