-
Notifications
You must be signed in to change notification settings - Fork 94
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
all: Add support for unknown value refinement data to all types #1062
Draft
austinvalle
wants to merge
41
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.
Draft
Changes from all commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
64d9274
quick fix on equals for later
austinvalle 8a8f3fc
test fixes
austinvalle 0d0f4fc
not null and string prefix implementations
austinvalle 15121c4
add number bounds
austinvalle ec7cc42
Merge branch 'main' into av/refinements
austinvalle dfdef53
switch back to local - go mod tidy
austinvalle dcd19d9
switched up interface
austinvalle d67bd4a
Merge branch 'main' into av/refinements
austinvalle 31d81ad
bump versions
austinvalle f297cce
update existing docs + equal/string methods
austinvalle 4de17f2
new refinements
austinvalle 0b35094
var name
austinvalle 53802ef
update string type and value
austinvalle 4d923dc
string tests
austinvalle e242cac
clean up int64 value and type, add tests
austinvalle 12d8bb8
int32 refinements
austinvalle 9f965c4
float64 refinements
austinvalle c65976c
float 32 refinements
austinvalle ab222bc
variable change
austinvalle 82ad8e7
number refinements
austinvalle cfa53db
bool refinements
austinvalle cdaf3d9
object refinements
austinvalle cd8d8ed
tuple refinements
austinvalle 54b5cfb
list refinements
austinvalle b4eee34
set refinements
austinvalle 093adf2
fix testtype
austinvalle 3fce8d5
map refinements
austinvalle cc81de3
order comment
austinvalle c6333be
string plan modifiers
austinvalle 18d08f9
int64 plan modifiers
austinvalle 6063b92
int32 plan modifiers
austinvalle 7fd8967
float64 plan modifiers
austinvalle b52b2c8
float32 plan modifiers
austinvalle b45f8af
number plan modifiers
austinvalle 2a7b3dd
object and bool plan modifiers
austinvalle 411df8d
list plan modifiers
austinvalle 972929c
map and set plan modifiers
austinvalle b59f093
add tests for not null refinement
austinvalle 96d9ccf
spelling
austinvalle a2d4066
switch to commit hash
austinvalle a85b9d5
fix custom type implementations
austinvalle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package boolplanmodifier | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" | ||
) | ||
|
||
// WillNotBeNull returns a plan modifier that will add a refinement to an unknown planned value | ||
// which promises that the final value will not be null. | ||
// | ||
// This unknown value refinement allows Terraform to validate more of the configuration during plan | ||
// and evaluate conditional logic in meta-arguments such as "count": | ||
// | ||
// resource "examplecloud_thing" "b" { | ||
// // Will successfully evaluate during plan with a "not null" refinement on "bool_attribute" | ||
// count = examplecloud_thing.a.bool_attribute != null ? 1 : 0 | ||
// | ||
// // .. resource config | ||
// } | ||
func WillNotBeNull() planmodifier.Bool { | ||
return willNotBeNullModifier{} | ||
} | ||
|
||
type willNotBeNullModifier struct{} | ||
|
||
func (m willNotBeNullModifier) Description(_ context.Context) string { | ||
return "Promises the value of this attribute will not be null once it becomes known" | ||
} | ||
|
||
func (m willNotBeNullModifier) MarkdownDescription(_ context.Context) string { | ||
return "Promises the value of this attribute will not be null once it becomes known" | ||
} | ||
|
||
func (m willNotBeNullModifier) PlanModifyBool(ctx context.Context, req planmodifier.BoolRequest, resp *planmodifier.BoolResponse) { | ||
// Do nothing if there is a known planned value. | ||
if !req.PlanValue.IsUnknown() { | ||
return | ||
} | ||
|
||
// Do nothing if there is an unknown configuration value, otherwise interpolation gets messed up. | ||
if req.ConfigValue.IsUnknown() { | ||
return | ||
} | ||
|
||
resp.PlanValue = req.PlanValue.RefineAsNotNull() | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package boolplanmodifier_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
"github.com/hashicorp/terraform-plugin-framework/resource/schema/boolplanmodifier" | ||
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
) | ||
|
||
func TestWillNotBeNullModifierPlanModifyBool(t *testing.T) { | ||
t.Parallel() | ||
|
||
testCases := map[string]struct { | ||
request planmodifier.BoolRequest | ||
expected *planmodifier.BoolResponse | ||
}{ | ||
"known-plan": { | ||
request: planmodifier.BoolRequest{ | ||
StateValue: types.BoolValue(false), | ||
PlanValue: types.BoolValue(true), | ||
ConfigValue: types.BoolNull(), | ||
}, | ||
expected: &planmodifier.BoolResponse{ | ||
PlanValue: types.BoolValue(true), | ||
}, | ||
}, | ||
"unknown-config": { | ||
// this is the situation in which a user is | ||
// interpolating into a field. We want that to still | ||
// show up as unknown (with no refinement), otherwise they'll | ||
// get apply-time errors for changing the value even though | ||
// we knew it was legitimately possible for it to change and the | ||
// provider can't prevent this from happening | ||
request: planmodifier.BoolRequest{ | ||
StateValue: types.BoolValue(true), | ||
PlanValue: types.BoolUnknown(), | ||
ConfigValue: types.BoolUnknown(), | ||
}, | ||
expected: &planmodifier.BoolResponse{ | ||
PlanValue: types.BoolUnknown(), | ||
}, | ||
}, | ||
"unknown-plan-null-state": { | ||
request: planmodifier.BoolRequest{ | ||
StateValue: types.BoolNull(), | ||
PlanValue: types.BoolUnknown(), | ||
ConfigValue: types.BoolNull(), | ||
}, | ||
expected: &planmodifier.BoolResponse{ | ||
PlanValue: types.BoolUnknown().RefineAsNotNull(), | ||
}, | ||
}, | ||
"unknown-plan-non-null-state": { | ||
request: planmodifier.BoolRequest{ | ||
StateValue: types.BoolValue(true), | ||
PlanValue: types.BoolUnknown(), | ||
ConfigValue: types.BoolNull(), | ||
}, | ||
expected: &planmodifier.BoolResponse{ | ||
PlanValue: types.BoolUnknown().RefineAsNotNull(), | ||
}, | ||
}, | ||
} | ||
|
||
for name, testCase := range testCases { | ||
name, testCase := name, testCase | ||
|
||
t.Run(name, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
resp := &planmodifier.BoolResponse{ | ||
PlanValue: testCase.request.PlanValue, | ||
} | ||
|
||
boolplanmodifier.WillNotBeNull().PlanModifyBool(context.Background(), testCase.request, resp) | ||
|
||
if diff := cmp.Diff(testCase.expected, resp); diff != "" { | ||
t.Errorf("unexpected difference: %s", diff) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
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.
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.
TODO: update with released version