You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When attempting to setup a provider with terraform-plugin-log/tflog, trying to add variables via tflog.With() or use subsystems requires each logging context to be explicitly built up in a lot of logic:
The SDK could offer a new Resource interface, that can support function logic before all these various logic points are invoked, e.g.
typeResourceWithSetupContextinterface {
Resource// SetupContext is a hook which can be used to instantiate details inside the context before it is passed into Resource logic.SetupContextfunc(context.Context) context.Context
}
An example provider implementation:
func(rexampleResource) SetupContext(ctx context.Context) context.Context {
ctx=tfsdk.NewSubsystem(ctx, /* ... */)
// Provider may not have been configured yet.ifr.client.configured {
ctx=tfsdk.With(ctx, "account_id", r.client.accountID)
ctx=tfsdk.With(ctx, "region", r.client.region)
}
returnctx
}
When defined on a resource, this logic would be invoked automatically prior to executing the provider defined Create, etc. functions.
One thing that isn't immediately clear is whether this should be split up per RPC/SDK functionality per resource, left as a monolithic configuration per resource, or potentially offered at an even higher level (e.g. Provider). Being monolithic at the resource level seems to be the most pragmatic choice given how providers are typically written with "API service" boundaries that may dictate needing multiple configurations across the provider. This does however prevent providing these hooks with "rich" information like Config, Plan, and State since that is dependent on the RPC.
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.
Module version
Use-cases
When attempting to setup a provider with
terraform-plugin-log/tflog
, trying to add variables viatflog.With()
or use subsystems requires each logging context to be explicitly built up in a lot of logic:Currently the setup must be done within each and every one of those provider defined pieces, which could be confusing and/or error prone.
Attempted Solutions
Adding a helper function, which gets invoked within every CRUD, CustomizeDiff, etc. function. e.g.
Proposal
The SDK could offer a new
Resource
interface, that can support function logic before all these various logic points are invoked, e.g.An example provider implementation:
When defined on a resource, this logic would be invoked automatically prior to executing the provider defined Create, etc. functions.
One thing that isn't immediately clear is whether this should be split up per RPC/SDK functionality per resource, left as a monolithic configuration per resource, or potentially offered at an even higher level (e.g.
Provider
). Being monolithic at the resource level seems to be the most pragmatic choice given how providers are typically written with "API service" boundaries that may dictate needing multiple configurations across the provider. This does however prevent providing these hooks with "rich" information like Config, Plan, and State since that is dependent on the RPC.References
The text was updated successfully, but these errors were encountered: