Open SarahFrench opened 1 week ago
Note: One of the potential causes of context-related errors in the plugin-framework implementation of configuration logic could be because the Context stored on the framework equivalent of the Config struct isn't a stop context..
Also, GetTokenSource and GetCredentials in the plugin-framework implementation passed context through as function arguments, versus what is described above in this issue for the SDK code.
GH issues related to context and the plugin-framework code:
Labelled with plugin-framework
as this was potentially a factor in some auth differences between the SDK and PF implementations of provider configuration logic; would be useful to know about in future
Description
The use of context in the provider is a bit confusing due to:
ctx
passed into functions,context.Background
,context.TODO()
, andc.Context
stored on the Config structschema.StopContext
).1) Context usage in
func (c *Config) GetCredentials
Currently in
func (c *Config) GetCredentials
, where provider arguments are used to get agoogleoauth.Credentials
struct:c.Context
is used in 2 places:credentials
context.Background
is used in 2 places:context.TODO()
is used in 3 places:access_token
credentials
We may want to revisit this and clarify what context should be used where. We might want to use the context passed via the Config struct, or we might want to update functions like getTokenSource and GetCredentials to accept a ctx argument.
If we want to use the context passed via the Config struct we should check our usage of schema.StopContext, see below.
2) Usage of deprecated
schema.StopContext
We use
schema.StopContext
infunc ProviderConfigure
to make a 'stop context'. This context is passed into functions that lead up to handling credentials and configuring the client (see supporting info below).Should
schema.StopContext
be removed? How would that affect configuration logic using that context?Supporting info
Info about configuring the (SDK) provider; what leads up to using
func (c *Config) GetCredentials
?How TF core tells the provider to configure itself:
func ProviderConfigure
, which is used to set the ConfigureContextFunc.What happens inside
ProviderConfigure
:schema.StopContext
(here)func (c *Config) LoadAndValidate
, which is needed to handle credentials and configure the client used by the provider etc.What happens inside
func (c *Config) LoadAndValidate
:func (c *Config) getTokenSource
to get a token source.func (c *Config) GetCredentials
is used to get agoogleoauth.Credentials
, which is required for making the token source.googleoauth.Credentials
requires passing in a context, but:New or Affected Resource(s)
N/A
Potential Terraform Configuration
N/A
References
No response