-
Notifications
You must be signed in to change notification settings - Fork 3
Implement Using Custom Types for Timeouts #18
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
Conversation
Bumps [github.com/hashicorp/terraform-plugin-framework](https://github.com/hashicorp/terraform-plugin-framework) from 0.16.0 to 0.17.0. - [Release notes](https://github.com/hashicorp/terraform-plugin-framework/releases) - [Changelog](https://github.com/hashicorp/terraform-plugin-framework/blob/main/CHANGELOG.md) - [Commits](hashicorp/terraform-plugin-framework@v0.16.0...v0.17.0) --- updated-dependencies: - dependency-name: github.com/hashicorp/terraform-plugin-framework dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com>
…e use of type-specific schema and attributes
…chema-specific functions to add a nested blocks or nested attributes into a schema (#17)
bflad
left a comment
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 should likely drop the existing tfsdk implementations in the same version too. 😄
timeouts/type/timeouts.go
Outdated
| return t.getTimeout(ctx, attributeNameDelete) | ||
| } | ||
|
|
||
| func (t TimeoutsValue) getTimeout(_ context.Context, timeoutName string) (time.Duration, error) { |
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 would recommend switching this to diag.Diagnostics over error so its more friendly to use in provider code. 👍
| if opts.Create { | ||
| attrTypes[attributeNameCreate] = types.StringType | ||
| } |
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.
Not due to this pull request, but data source schemas should only support a read timeout.
timeouts/type/timeouts.go
Outdated
| @@ -0,0 +1,120 @@ | |||
| package timeouts | |||
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 wonder if this should be promoted to the top level timeouts package so provider developers do not have an awkward type import if they do not import alias it?
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 did this initially and then thought that it would be useful to have timeouts value that only has the relevant functions for the schema type that it is being used with. For instance, data source should only have access to the timeouts Read function.
I think we need some different naming from Type and Value though. Be interested to hear your thoughts.
…to resource and data source specific implementations (#17)
Have dropped all usages of |
bflad
left a comment
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.
😅 Apparently I had this comment queued up but didn't submit it.
README.md
Outdated
| ```go | ||
| import ( | ||
| /* ... */ | ||
| "github.com/hashicorp/terraform-plugin-framework-timeouts/timeouts/resource" |
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 think it'd be good to avoid the naming collision with the github.com/hashicorp/terraform-plugin-framework/resource package for these and in Go its generally good practice to have the underlying package name match the end of the import path to prevent confusion -- to that end, I'd suggest either github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts or github.com/hashicorp/terraform-plugin-framework-timeouts/resourcetimeouts
bflad
left a comment
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.
A diagnostics usability question, but otherwise optimistically approving this. ✅
| value, ok := t.Object.Attributes()[timeoutName] | ||
| if !ok { | ||
| diags.Append(diag.NewErrorDiagnostic( | ||
| "Timeout Does Not Exist", | ||
| fmt.Sprintf("timeout for %q does not exist", timeoutName), | ||
| )) | ||
|
|
||
| return defaultTimeout, diags | ||
| } |
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.
How do you feel about the prior implementation that accepted a default timeout duration inline? I think returning an error diagnostic here could be problematic for provider implementations which elsewhere in the framework do not need to conditionally choose when to append diagnostics to their response diagnostics. I'd expect something like the following to "always work" (configured or not):
timeout, diags := data.Timeouts.Read(ctx) // or Read(ctx, 20*time.Minute)
resp.Diagnostics(diags...)If we wanted to make this nicer for troubleshooting, I'd suggest passing context.Context through and logging using tflog.Info(ctx, timeoutName + " timeout configuration not found, using provided default")
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 think the super cool thing here is that once we have a custom type for "Go time durations", we can likely remove the diag.Diagnostics return completely. 😄
datasource/timeouts/timeouts_test.go
Outdated
|
|
||
| // equateErrorMessage reports errors to be equal if both are nil | ||
| // or both have the same message. | ||
| var equateErrorMessage = cmp.Comparer(func(x, y error) bool { |
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.
Is this necessary? I haven't come across needing anything special necessary with go-cmp comparing diag.Diagnostics, but if there is something special it'd be good to figure it out.
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.
Hmmmm..........have just checked and following the most recent code changes this no longer seems to be required.
README.md
Outdated
| The following illustrates nested block syntax for defining timeouts on a resource and a data source. | ||
|
|
||
| ```terraform | ||
| ```hcl |
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.
Using terraform for code blocks should be valid in GitHub: https://github.com/github/linguist/blob/c1c34e5260797b4d598f5ec76f19723bfc5a1894/lib/linguist/languages.yml#L2529-L2544 (and especially helpful should the language ever be split off from generic hcl formatting)
Co-authored-by: Brian Flad <bflad417@gmail.com>
…t is not in the Terraform configuration (#17)
bflad
left a comment
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 good to me 🚀
|
I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions. |
Closes: #17