terraform-plugin-framework
terraform-plugin-framework copied to clipboard
Add Int32 type
Module version
github.com/hashicorp/terraform-plugin-framework v1.3.2
Use-cases
Any time you want to use a default int in golang.
Attempted Solutions
Currently using the schema.Int64Attribute and related types. I have to do type conversions in various places.
Proposal
Add an Int type similar to Int64 which just returns a default golang int.
Hi @pgier 👋 Thank you for raising this.
One thing that has come up occasionally before is specifically supporting a 32-bit integer type, but this is the first direct request for a Go-specific int type. One of the challenges with the Go int type is that it is defined by the CPU architecture running the code (or lower, such as running a 32-bit binary on 64-bit CPU), so supported integers may be 64-bit or 32-bit depending on where the provider was running. This can ultimately leading to practitioner confusion when there is an unexpected integer overflow when the API may happen to return integers larger than 32 bits.
Can you describe where/why you're running into these type conversions? Are you working with an API SDK that deals exclusively with the loosely-defined int/*int types? For example, would providing a way to create a types.Int64 value from a Go int help? That sort of operation is safe because a 64-bit or lower integer can always be represented by the larger sized type.
I guess an int32 type would be fine. My specific cases that I've run into are:
- Writing code against an existing client library which uses in32 types.
- Using things like
strconv.Atoiwhere it would be nice to just pass a plain int type
For (1), I'm now using ObjectValue.As to do the type conversions and that seems to be working fine.
For (2), I should probably just use strconv.FormatInt or something else that accepts an int64.
If there is already a request for an int32 type, I think you can close this as a duplicate.
Writing code against an existing client library which uses in32 types.
Just to ensure we are on the same page, are those client library types the Go built-in int32 type or just int? When we have thought about introducing something like types.Int32/schema.Int32Attribute, it would explicitly be the int32 type to prevent any confusion about the value storage. Maybe it would be okay to have functionality on that those that also allowed int to and from though, since I'm doubtful that Go would support an architecture with less than 32 bits.
If there is already a request for an int32 type, I think you can close this as a duplicate.
I don't believe there is a public one in this issue tracker at the moment, so if you're okay with that we can re-title this.
Just to ensure we are on the same page, are those client library types the Go built-in int32 type or just int?
This particular library is using specifically int32 types.
if you're okay with that we can re-title this
Yes, that's fine with me