Comments (8)
Hi @ewbankkit!
The improved configuration language interpreter we're currently working on integrating (based on what is currently codenamed HCL2 removes the int vs. float distinction and instead makes all numbers arbitrary-precision floats, which are internally represented as big.Float
.
As you noted, there are a lot of touchpoints to make this change across the whole of Terraform, and so our initial work is focused on making it work within Terraform Core, the interpolation language, functions, etc but will not include any changes to the helper/schema
API. For the moment it will convert the big.Float
representation to int
automatically, and will thus unfortunately still be constrained by the platform-dependent int
type in the initial release.
We plan to work on this helper/schema
API change separately so we can take the time to find a suitable compromise that keeps the existing wealth of provider code working while allowing for the various new possibilities in the new type system. This might entail adding new type constants to helper/schema
as you noted, or we may find some other strategy, but either way we need to complete the core-level integration first so that large integers (and more-precise floats) can safely pass through the rest of the system without error. Once Terraform Core is big-number-aware, a change to support additional Go native number types would be confined only to helper/schema
, as convenience conversions from big.Float
.
It will take some time for us to reach the point where this change is fully realized, so in the short term we've usually resorted to using TypeString
attributes and then parsing them into integers of the appropriate range within the provider code itself. This does, of course, have some drawbacks for maintainability and error checking, but it allows progress to be made without blocking on the big configuration language project. The CustomizeDiff
feature added in hashicorp/terraform#14887, in conjunction with the helper/customdiff
library, provides a means to do range validation at plan time so that any error can be reported to the user.
from terraform-plugin-sdk.
Yes, today the provider SDK is doing that automatic conversion.
From 0.12 onwards it will be Terraform Core that does the conversion, since it will then know the expected types of all arguments and the configuration language interpreter itself will do type checking and automatic conversions where possible. From the perspective of the provider SDK API there should be no discernible difference, though... just the same work being done in a different place.
from terraform-plugin-sdk.
I've labelled this with "schema-helper" because the Core type system work is already in progress and so I'd like to use this issue to represent the subsequent work to introduce new numeric types to helper/schema
.
from terraform-plugin-sdk.
@apparentlymart Thanks for the thorough explanation.
I saw this code
https://github.com/hashicorp/terraform/blob/71e989ba3edb40e339adaf72e9499060c5216b16/config/hcl2shim/values.go#L48-L49
which made me think that a workaround for my particular case would be to use TypeFloat
but I agree that use of TypeString
for now is more consistent.
from terraform-plugin-sdk.
Using a TypeFloat
could be reasonable in your case if the value you're looking for will fit within the significand of a float64
, which gives you 53 bits. I'd suggest still doing some validation on that to verify that the user did indeed provide a whole number (rather than implicitly rounding), which means that from the user's standpoint it shouldn't make a big difference compared to TypeString
.
This "hcl2shim" code is there to support the opt-in experimental version of the new language system that we're planning to release to gather feedback and do more testing before we switch wholesale to the new implementation, so this code is making a "best effort" attempt to map the new system onto the expectations of the old system so that the two can coexist for a few releases. This code will be removed once the new system is first-class, but indeed there will need to be some similar code in helper/schema
at that point to retain compatibility with that abstraction.
(Note that the shim is intentionally allowing loss of precision for integers that require more than 53 bits on a 32-bit system, since that compatibility shim's goal is to make sure we can represent all possible values that HCL and helper/schema
understand today, rather than to enable any new representations.)
from terraform-plugin-sdk.
Hey @apparentlymart - thanks for conveying the workaround of using TypeString
in the interim. If we have an existing resource argument that is currently represented as a TypeInt
and we change its schema to TypeString
, the corresponding .tf config doesn't need to explicitly quote the rvalue, right? I am assuming that the framework takes care of converting it.
Also, conversely, once a resource argument has been made as a TypeString
and we switch it to TypeInt
(or TypeInt64
in the future), the conversion to/from the state file will be seamlessly handled by the framework, right?
In my limited testing, I do see this being done by the framework, but was not sure if this was an intended behavior that the users of the framework can depend on.
Thanks!
from terraform-plugin-sdk.
I believe #662 resolved this.
from terraform-plugin-sdk.
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.
from terraform-plugin-sdk.
Related Issues (20)
- Behaviour of `terraform providers schema` command for computed fields HOT 4
- `diff.GetOk` return `nil` for the value of `TypeList` defined in `TypeSet` HOT 1
- Not Helpful Err When Running Tests For Provider HOT 4
- Unsupported Field Type for Resource
- TypeSet resource wanting to destroy and recreate everything when diff is found HOT 2
- losing precision when using maximum value for a 64-bit signed integer
- helper/schema: Provide Functionality to Reduce Resident Memory Usage from Schemas HOT 1
- Consider Method for Disabling Legacy SDK Data Consistency Warning Log Demotion HOT 7
- Updates for Protocol Version 5.4 HOT 1
- Value out of range on 32-bit architecture HOT 3
- Update Go Module to Go 1.20 Minimum HOT 1
- `Schema.Set` adds an empty value when attempting to Patch HOT 1
- `meta.SDKVersion` reporting incorrect version HOT 6
- Terraform CloudFormation Multi Region Stacksets HOT 3
- Is it possible to have a dependency between 2 attributes? HOT 2
- `schema.ResourceData.GetRaw<whatever>()` not populated during provider configuration HOT 3
- Consider Migrating from mitchellh/mapstructure to go-viper/mapstructure
- Low performance in deduplicate strings function HOT 4
- ForceNew doesn't trigger resource recreation when defined on TypeSet, which leads to Update error HOT 1
- helper/resource: Add Go Deprecation Messages That Point To terraform-plugin-testing
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from terraform-plugin-sdk.