-
Notifications
You must be signed in to change notification settings - Fork 34
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
tftypes: Introduce unknown value refinement support for Value
#448
Draft
austinvalle
wants to merge
21
commits into
main
Choose a base branch
from
av/refinements
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
austinvalle
commented
Nov 25, 2024
Comment on lines
+1901
to
+1953
"unknown-bool": { | ||
in: NewValue(Bool, UnknownValue), | ||
expected: "tftypes.Bool<unknown>", | ||
}, | ||
"unknown-bool-with-nullness-refinement": { | ||
in: NewValue(Bool, UnknownValue).Refine(refinement.Refinements{ | ||
refinement.KeyNullness: refinement.NewNullness(false), | ||
}), | ||
expected: `tftypes.Bool<unknown, not null>`, | ||
}, | ||
"unknown-string": { | ||
in: NewValue(String, UnknownValue), | ||
expected: "tftypes.String<unknown>", | ||
}, | ||
"unknown-string-with-multiple-refinements": { | ||
in: NewValue(String, UnknownValue).Refine(refinement.Refinements{ | ||
refinement.KeyNullness: refinement.NewNullness(false), | ||
refinement.KeyStringPrefix: refinement.NewStringPrefix("str://"), | ||
}), | ||
expected: `tftypes.String<unknown, not null, prefix = "str://">`, | ||
}, | ||
"unknown-number": { | ||
in: NewValue(Number, UnknownValue), | ||
expected: "tftypes.Number<unknown>", | ||
}, | ||
"unknown-number-with-multiple-refinements": { | ||
in: NewValue(Number, UnknownValue).Refine(refinement.Refinements{ | ||
refinement.KeyNullness: refinement.NewNullness(false), | ||
refinement.KeyNumberLowerBound: refinement.NewNumberLowerBound(big.NewFloat(5), true), | ||
refinement.KeyNumberUpperBound: refinement.NewNumberUpperBound(big.NewFloat(10), true), | ||
}), | ||
expected: `tftypes.Number<unknown, not null, lower bound = 5 (inclusive), upper bound = 10 (inclusive)>`, | ||
}, | ||
"unknown-number-float-with-multiple-refinements": { | ||
in: NewValue(Number, UnknownValue).Refine(refinement.Refinements{ | ||
refinement.KeyNullness: refinement.NewNullness(false), | ||
refinement.KeyNumberLowerBound: refinement.NewNumberLowerBound(big.NewFloat(5.67), true), | ||
refinement.KeyNumberUpperBound: refinement.NewNumberUpperBound(big.NewFloat(10.123), true), | ||
}), | ||
expected: `tftypes.Number<unknown, not null, lower bound = 5.67 (inclusive), upper bound = 10.123 (inclusive)>`, | ||
}, | ||
"unknown-list": { | ||
in: NewValue(List{ElementType: String}, UnknownValue), | ||
expected: "tftypes.List[tftypes.String]<unknown>", | ||
}, | ||
"unknown-list-with-multiple-refinements": { | ||
in: NewValue(List{ElementType: String}, UnknownValue).Refine(refinement.Refinements{ | ||
refinement.KeyNullness: refinement.NewNullness(false), | ||
refinement.KeyCollectionLengthLowerBound: refinement.NewCollectionLengthLowerBound(2), | ||
refinement.KeyCollectionLengthUpperBound: refinement.NewCollectionLengthUpperBound(7), | ||
}), | ||
expected: `tftypes.List[tftypes.String]<unknown, not null, length lower bound = 2, length upper bound = 7>`, | ||
}, |
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.
We can bikeshed the display of these attributes since there is no established pattern ATM (core displays the cty
methods when showing data consistency errors, but doesn't have a "user friendly" version of the data defined). Other thoughts:
tftypes.String<unknown, refinements = [not null, prefix = "str://"]>
tftypes.String<unknown, will not be null, will have prefix "str://">
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Ref: hashicorp/terraform#30937
Ref: hashicorp/terraform-plugin-framework#869
This PR introduces value refinement support to the
tftypes
package. This allows Terraform providers to communicate unknown value refinements to/from Terraform core (Terraform 1.6+).Value refinements are additional constraints that can be applied to unknown values in Terraform that can be used to produce known results from unknown values. For example, with value refinements, providers can now indicate specific attributes will "definitely not be null" during
PlanResourceChange
, which would allow Terraform core to successfully evaluate expressions likecount
during plan, rather than returning an error like:TODOs left on this PR