helper/schema: Introduce context-aware resource CRUD functions without default timeout #723
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.
Closes #675
(Test changes may be easiest to view with the "hide whitespace changes" option in GitHub as they are just introducing looping to cover relevant Create/CreateContext/CreateWithoutTimeout method implementations.)
The Terraform Plugin SDK has always supported customizable timeouts, declared at the
helper/schema.Resource.Timeouts
level with the operation awarehelper/schema.ResourceTimeout
type. These were designed to allow practitioners to implement a timeout per resource, e.g.Where the resource logic could fetch the timeout value via
(helper/schema.ResourceData).Timeout()
function.Recently, context-aware resource operation functions were introduced and the existing non-context-aware functions were deprecated. These new context-aware resource operations forcibly introduce an operation timeout (defaults to 20 minutes) for the called logic, e.g.
terraform-plugin-sdk/helper/schema/resource.go
Lines 283 to 285 in e21a5bb
Previously, the non-context-aware resources could be implemented with
helper/schema.Resource.Timeouts.Create
defined and operation logic such as:Where in this case, the create timeout could be referenced in the code via
d.Timeout(schema.TimeoutCreate)
after the synchronization coordination. The creation timeout only affected this single operation, even if multiple operations were going to occur.In the case of the context-aware functionality however, the timeout is configured before the mutex. So when multiple operations are waiting on the mutex, they are now sharing the same resource operation timeout. Since the timeout cannot be extended within the resource logic, developers are stuck either setting an arbitrarily high timeout (losing its usefulness) or practitioners are arbitrarily hitting the timeout as they scale out their configuration.
To characterize how some remote systems can require that operations must be serialized or otherwise synchronized:
This essentially means the semantics of the synchronization can be based off resource configuration, operation type, and potentially accordant to the limits set by a remote system.
Here we introduce separate CRUD methods that are invoked before the context is set with the timeout, so as to not "force" the resource timeout. If timeout behavior is still desired, developers must manually implement timeout handling in the function logic when using these.
Most developers should prefer the existing context-aware functions and this is documented as such. However, another minor side benefit of these functions is that it also allows developers to upgrade CRUD function signatures for context awareness without logically changing resource behavior, then slowly switch to the timeout functions over time.