Skip to content

Conversation

@bendbennett
Copy link
Contributor

Closes: #17

dependabot bot and others added 6 commits November 30, 2022 19:40
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)
@bendbennett bendbennett requested a review from a team as a code owner December 7, 2022 12:42
@bendbennett bendbennett changed the base branch from main to dependabot/go_modules/github.com/hashicorp/terraform-plugin-framework-0.17.0 December 7, 2022 12:42
Copy link
Contributor

@bflad bflad left a 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. 😄

return t.getTimeout(ctx, attributeNameDelete)
}

func (t TimeoutsValue) getTimeout(_ context.Context, timeoutName string) (time.Duration, error) {
Copy link
Contributor

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. 👍

Comment on lines 119 to 121
if opts.Create {
attrTypes[attributeNameCreate] = types.StringType
}
Copy link
Contributor

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.

@@ -0,0 +1,120 @@
package timeouts
Copy link
Contributor

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?

Copy link
Contributor Author

@bendbennett bendbennett Dec 14, 2022

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.

@bendbennett
Copy link
Contributor Author

bendbennett commented Dec 14, 2022

We should likely drop the existing tfsdk implementations in the same version too. 😄

Have dropped all usages of tfsdk. It might be worth noting that there is no prior released version that contains deprecation notices for the tfsdk implementations.

@bendbennett bendbennett requested a review from bflad December 15, 2022 16:57
Copy link
Contributor

@bflad bflad left a 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"
Copy link
Contributor

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

@bendbennett bendbennett added the enhancement New feature or request label Dec 16, 2022
@bendbennett bendbennett added this to the v0.3.0 milestone Dec 16, 2022
@bendbennett bendbennett changed the base branch from dependabot/go_modules/github.com/hashicorp/terraform-plugin-framework-0.17.0 to main December 16, 2022 12:14
Copy link
Contributor

@bflad bflad left a 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. ✅

Comment on lines 86 to 94
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
}
Copy link
Contributor

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")

Copy link
Contributor

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. 😄


// 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 {
Copy link
Contributor

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.

Copy link
Contributor Author

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
Copy link
Contributor

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)

Copy link
Contributor

@bflad bflad left a 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 🚀

@bendbennett bendbennett merged commit 638afa4 into main Dec 20, 2022
@bendbennett bendbennett deleted the bendbennett/issues-17 branch December 20, 2022 17:04
@github-actions
Copy link

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.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use Custom Types for Timeouts

3 participants