mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
Fix global schema caching (#954)
Signed-off-by: Dmitry Kisler <admin@dkisler.com>
This commit is contained in:
parent
478a6ecf81
commit
0d6a763a74
@ -81,9 +81,9 @@ func (p *GRPCProvider) GetProviderSchema() (resp providers.GetProviderSchemaResp
|
||||
|
||||
// check the global cache
|
||||
if !p.Addr.IsZero() {
|
||||
if resp, ok := providers.SchemaCache.Get(p.Addr); ok {
|
||||
if schemaCached, ok := providers.SchemaCache.Get(p.Addr); ok && schemaCached.ServerCapabilities.GetProviderSchemaOptional {
|
||||
logger.Trace("GRPCProvider: GetProviderSchema: serving from global schema cache", "address", p.Addr)
|
||||
return resp
|
||||
return schemaCached
|
||||
}
|
||||
}
|
||||
|
||||
@ -143,7 +143,7 @@ func (p *GRPCProvider) GetProviderSchema() (resp providers.GetProviderSchemaResp
|
||||
}
|
||||
|
||||
// set the global cache if we can
|
||||
if !p.Addr.IsZero() && resp.ServerCapabilities.GetProviderSchemaOptional {
|
||||
if !p.Addr.IsZero() {
|
||||
providers.SchemaCache.Set(p.Addr, resp)
|
||||
}
|
||||
|
||||
|
@ -81,9 +81,9 @@ func (p *GRPCProvider) GetProviderSchema() (resp providers.GetProviderSchemaResp
|
||||
|
||||
// check the global cache
|
||||
if !p.Addr.IsZero() {
|
||||
if resp, ok := providers.SchemaCache.Get(p.Addr); ok {
|
||||
if schemaCached, ok := providers.SchemaCache.Get(p.Addr); ok && schemaCached.ServerCapabilities.GetProviderSchemaOptional {
|
||||
logger.Trace("GRPCProvider: GetProviderSchema: serving from global schema cache", "address", p.Addr)
|
||||
return resp
|
||||
return schemaCached
|
||||
}
|
||||
}
|
||||
|
||||
@ -143,7 +143,7 @@ func (p *GRPCProvider) GetProviderSchema() (resp providers.GetProviderSchemaResp
|
||||
}
|
||||
|
||||
// set the global cache if we can
|
||||
if !p.Addr.IsZero() && resp.ServerCapabilities.GetProviderSchemaOptional {
|
||||
if !p.Addr.IsZero() {
|
||||
providers.SchemaCache.Set(p.Addr, resp)
|
||||
}
|
||||
|
||||
|
@ -123,6 +123,8 @@ type ServerCapabilities struct {
|
||||
// provider does not require calling GetProviderSchema to operate
|
||||
// normally, and the caller can used a cached copy of the provider's
|
||||
// schema.
|
||||
// In other words, the providers for which GetProviderSchemaOptional is false
|
||||
// require their schema to be read after EVERY instantiation to function normally.
|
||||
GetProviderSchemaOptional bool
|
||||
}
|
||||
|
||||
|
@ -66,8 +66,6 @@ func (cp *contextPlugins) NewProvisionerInstance(typ string) (provisioners.Inter
|
||||
// to repeatedly call this method with the same address if various different
|
||||
// parts of OpenTofu all need the same schema information.
|
||||
func (cp *contextPlugins) ProviderSchema(addr addrs.Provider) (providers.ProviderSchema, error) {
|
||||
log.Printf("[TRACE] tofu.contextPlugins: Initializing provider %q to read its schema", addr)
|
||||
|
||||
// Check the global schema cache first.
|
||||
// This cache is only written by the provider client, and transparently
|
||||
// used by GetProviderSchema, but we check it here because at this point we
|
||||
@ -78,6 +76,7 @@ func (cp *contextPlugins) ProviderSchema(addr addrs.Provider) (providers.Provide
|
||||
return schemas, nil
|
||||
}
|
||||
|
||||
log.Printf("[TRACE] tofu.contextPlugins: Initializing provider %q to read its schema", addr)
|
||||
provider, err := cp.NewProviderInstance(addr)
|
||||
if err != nil {
|
||||
return schemas, fmt.Errorf("failed to instantiate provider %q to obtain schema: %w", addr, err)
|
||||
|
Loading…
Reference in New Issue
Block a user