-
Notifications
You must be signed in to change notification settings - Fork 3
Added StateStore to timeouts #222
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
Open
rainkwan
wants to merge
3
commits into
main
Choose a base branch
from
rk/statestore-timeouts
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.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 hidden or 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,5 @@ | ||
| kind: FEATURES | ||
| body: Adds functions and types for statestore timeouts. | ||
| time: 2026-02-23T11:38:50.757069-05:00 | ||
| custom: | ||
| Issue: "222" |
This file contains hidden or 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 hidden or 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 hidden or 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,83 @@ | ||
| // Copyright IBM Corp. 2022, 2026 | ||
| // SPDX-License-Identifier: MPL-2.0 | ||
|
|
||
| package timeouts | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "github.com/hashicorp/terraform-plugin-framework/attr" | ||
| "github.com/hashicorp/terraform-plugin-framework/schema/validator" | ||
| "github.com/hashicorp/terraform-plugin-framework/statestore/schema" | ||
| "github.com/hashicorp/terraform-plugin-framework/types" | ||
|
|
||
| "github.com/hashicorp/terraform-plugin-framework-timeouts/internal/validators" | ||
| ) | ||
|
|
||
| const ( | ||
| attributeNameStateStore = "statestore" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See other comment, but this should be related to the operation the timeout applies to |
||
| ) | ||
|
|
||
| // Opts is used as an argument to BlockWithOpts and AttributesWithOpts to indicate | ||
| // whether supplied descriptions should override default descriptions. | ||
| type Opts struct { | ||
| StateStoreDescription string | ||
| } | ||
|
|
||
| // AttributesWithOpts returns a schema.SingleNestedAttribute which contains an | ||
| // attribute for `Open`, which is defined as types.StringType and optional. | ||
| // A validator is used to verify that the value assigned to an attribute | ||
| // can be parsed as time.Duration. The supplied Opts are used to override defaults. | ||
| func AttributesWithOpts(ctx context.Context, opts Opts) schema.Attribute { | ||
| return schema.SingleNestedAttribute{ | ||
| Attributes: attributesMap(opts), | ||
| CustomType: Type{ | ||
| ObjectType: types.ObjectType{ | ||
| AttrTypes: attrTypesMap(), | ||
| }, | ||
| }, | ||
| Optional: true, | ||
| } | ||
| } | ||
|
|
||
| // Attributes returns a schema.SingleNestedAttribute which contains an | ||
| // attribute for `Open`, which is defined as types.StringType and optional. | ||
| // A validator is used to verify that the value assigned to an attribute | ||
| // can be parsed as time.Duration. | ||
| func Attributes(ctx context.Context) schema.Attribute { | ||
| return schema.SingleNestedAttribute{ | ||
| Attributes: attributesMap(Opts{}), | ||
| CustomType: Type{ | ||
| ObjectType: types.ObjectType{ | ||
| AttrTypes: attrTypesMap(), | ||
| }, | ||
| }, | ||
| Optional: true, | ||
| } | ||
| } | ||
|
|
||
| func attributesMap(opts Opts) map[string]schema.Attribute { | ||
| attribute := schema.StringAttribute{ | ||
| Optional: true, | ||
| Description: `A string that can be [parsed as a duration](https://pkg.go.dev/time#ParseDuration) ` + | ||
| `consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are ` + | ||
| `"s" (seconds), "m" (minutes), "h" (hours).`, | ||
| Validators: []validator.String{ | ||
| validators.TimeDuration(), | ||
| }, | ||
| } | ||
|
|
||
| if opts.StateStoreDescription != "" { | ||
| attribute.Description = opts.StateStoreDescription | ||
| } | ||
|
|
||
| return map[string]schema.Attribute{ | ||
| attributeNameStateStore: attribute, | ||
| } | ||
| } | ||
|
|
||
| func attrTypesMap() map[string]attr.Type { | ||
| return map[string]attr.Type{ | ||
| attributeNameStateStore: types.StringType, | ||
| } | ||
| } | ||
This file contains hidden or 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,134 @@ | ||
| // Copyright IBM Corp. 2022, 2026 | ||
| // SPDX-License-Identifier: MPL-2.0 | ||
|
|
||
| package timeouts_test | ||
|
|
||
| import ( | ||
| "context" | ||
| "testing" | ||
|
|
||
| "github.com/google/go-cmp/cmp" | ||
| "github.com/hashicorp/terraform-plugin-framework/attr" | ||
| "github.com/hashicorp/terraform-plugin-framework/schema/validator" | ||
| "github.com/hashicorp/terraform-plugin-framework/statestore/schema" | ||
| "github.com/hashicorp/terraform-plugin-framework/types" | ||
|
|
||
| "github.com/hashicorp/terraform-plugin-framework-timeouts/internal/validators" | ||
| "github.com/hashicorp/terraform-plugin-framework-timeouts/statestore/timeouts" | ||
| ) | ||
|
|
||
| func TestAttributesWithOpts(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| type testCase struct { | ||
| opts timeouts.Opts | ||
| expected schema.Attribute | ||
| } | ||
| tests := map[string]testCase{ | ||
| "empty-opts": { | ||
| opts: timeouts.Opts{}, | ||
| expected: schema.SingleNestedAttribute{ | ||
| Attributes: map[string]schema.Attribute{ | ||
| "statestore": schema.StringAttribute{ | ||
| Optional: true, | ||
| Description: `A string that can be [parsed as a duration](https://pkg.go.dev/time#ParseDuration) ` + | ||
| `consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are ` + | ||
| `"s" (seconds), "m" (minutes), "h" (hours).`, | ||
| Validators: []validator.String{ | ||
| validators.TimeDuration(), | ||
| }, | ||
| }, | ||
| }, | ||
| CustomType: timeouts.Type{ | ||
| ObjectType: types.ObjectType{ | ||
| AttrTypes: map[string]attr.Type{ | ||
| "statestore": types.StringType, | ||
| }, | ||
| }, | ||
| }, | ||
| Optional: true, | ||
| }, | ||
| }, | ||
| "statestore-opts-description": { | ||
| opts: timeouts.Opts{ | ||
| StateStoreDescription: "statestore description", | ||
| }, | ||
| expected: schema.SingleNestedAttribute{ | ||
| Attributes: map[string]schema.Attribute{ | ||
| "statestore": schema.StringAttribute{ | ||
| Optional: true, | ||
| Description: "statestore description", | ||
| Validators: []validator.String{ | ||
| validators.TimeDuration(), | ||
| }, | ||
| }, | ||
| }, | ||
| CustomType: timeouts.Type{ | ||
| ObjectType: types.ObjectType{ | ||
| AttrTypes: map[string]attr.Type{ | ||
| "statestore": types.StringType, | ||
| }, | ||
| }, | ||
| }, | ||
| Optional: true, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| for name, test := range tests { | ||
|
|
||
| t.Run(name, func(t *testing.T) { | ||
| t.Parallel() | ||
| actual := timeouts.AttributesWithOpts(context.Background(), test.opts) | ||
|
|
||
| if diff := cmp.Diff(actual, test.expected); diff != "" { | ||
| t.Errorf("unexpected block difference: %s", diff) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestAttributes(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| type testCase struct { | ||
| expected schema.Attribute | ||
| } | ||
| tests := map[string]testCase{ | ||
| "statestore": { | ||
| expected: schema.SingleNestedAttribute{ | ||
| Attributes: map[string]schema.Attribute{ | ||
| "statestore": schema.StringAttribute{ | ||
| Optional: true, | ||
| Description: `A string that can be [parsed as a duration](https://pkg.go.dev/time#ParseDuration) ` + | ||
| `consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are ` + | ||
| `"s" (seconds), "m" (minutes), "h" (hours).`, | ||
| Validators: []validator.String{ | ||
| validators.TimeDuration(), | ||
| }, | ||
| }, | ||
| }, | ||
| CustomType: timeouts.Type{ | ||
| ObjectType: types.ObjectType{ | ||
| AttrTypes: map[string]attr.Type{ | ||
| "statestore": types.StringType, | ||
| }, | ||
| }, | ||
| }, | ||
| Optional: true, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| for name, test := range tests { | ||
|
|
||
| t.Run(name, func(t *testing.T) { | ||
| t.Parallel() | ||
| actual := timeouts.Attributes(context.Background()) | ||
|
|
||
| if diff := cmp.Diff(actual, test.expected); diff != "" { | ||
| t.Errorf("unexpected block difference: %s", diff) | ||
| } | ||
| }) | ||
| } | ||
| } |
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.
I guess we need to wait for Framework and plugin-go to be released until we merge this PR (or at least until we release the timeouts package after merging this)
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.
Looks like this PR just needs to be rebased and it'll bring in the right framework Go module 👍🏻