mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
enable global schema cache
This commit is contained in:
parent
fb35d7fd89
commit
642904204a
@ -68,9 +68,9 @@ type GRPCProvider struct {
|
|||||||
ctx context.Context
|
ctx context.Context
|
||||||
|
|
||||||
// schema stores the schema for this provider. This is used to properly
|
// schema stores the schema for this provider. This is used to properly
|
||||||
// serialize the state for requests.
|
// serialize the requests for schemas.
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
schemas providers.GetProviderSchemaResponse
|
schema providers.GetProviderSchemaResponse
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *GRPCProvider) GetProviderSchema() (resp providers.GetProviderSchemaResponse) {
|
func (p *GRPCProvider) GetProviderSchema() (resp providers.GetProviderSchemaResponse) {
|
||||||
@ -85,8 +85,8 @@ func (p *GRPCProvider) GetProviderSchema() (resp providers.GetProviderSchemaResp
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if p.schemas.Provider.Block != nil {
|
if p.schema.Provider.Block != nil {
|
||||||
return p.schemas
|
return p.schema
|
||||||
}
|
}
|
||||||
|
|
||||||
resp.ResourceTypes = make(map[string]providers.Schema)
|
resp.ResourceTypes = make(map[string]providers.Schema)
|
||||||
@ -135,18 +135,16 @@ func (p *GRPCProvider) GetProviderSchema() (resp providers.GetProviderSchemaResp
|
|||||||
|
|
||||||
if protoResp.ServerCapabilities != nil {
|
if protoResp.ServerCapabilities != nil {
|
||||||
resp.ServerCapabilities.PlanDestroy = protoResp.ServerCapabilities.PlanDestroy
|
resp.ServerCapabilities.PlanDestroy = protoResp.ServerCapabilities.PlanDestroy
|
||||||
|
resp.ServerCapabilities.GetProviderSchemaOptional = protoResp.ServerCapabilities.GetProviderSchemaOptional
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: Waiting for a provider capability to prevent caching
|
|
||||||
// providers which always need GetProviderSchema called.
|
|
||||||
// set the global cache if we can
|
// set the global cache if we can
|
||||||
//if !p.Addr.IsZero() {
|
if !p.Addr.IsZero() && resp.ServerCapabilities.GetProviderSchemaOptional {
|
||||||
// providers.SchemaCache.Set(p.Addr, resp)
|
providers.SchemaCache.Set(p.Addr, resp)
|
||||||
//} else {
|
} else {
|
||||||
// // otherwise store it in the local cache
|
// otherwise store it in the local cache
|
||||||
// p.schemas = resp
|
p.schema = resp
|
||||||
//}
|
}
|
||||||
p.schemas = resp
|
|
||||||
|
|
||||||
return resp
|
return resp
|
||||||
}
|
}
|
||||||
|
@ -68,9 +68,9 @@ type GRPCProvider struct {
|
|||||||
ctx context.Context
|
ctx context.Context
|
||||||
|
|
||||||
// schema stores the schema for this provider. This is used to properly
|
// schema stores the schema for this provider. This is used to properly
|
||||||
// serialize the state for requests.
|
// serialize the requests for schemas.
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
schemas providers.GetProviderSchemaResponse
|
schema providers.GetProviderSchemaResponse
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *GRPCProvider) GetProviderSchema() (resp providers.GetProviderSchemaResponse) {
|
func (p *GRPCProvider) GetProviderSchema() (resp providers.GetProviderSchemaResponse) {
|
||||||
@ -85,8 +85,8 @@ func (p *GRPCProvider) GetProviderSchema() (resp providers.GetProviderSchemaResp
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if p.schemas.Provider.Block != nil {
|
if p.schema.Provider.Block != nil {
|
||||||
return p.schemas
|
return p.schema
|
||||||
}
|
}
|
||||||
|
|
||||||
resp.ResourceTypes = make(map[string]providers.Schema)
|
resp.ResourceTypes = make(map[string]providers.Schema)
|
||||||
@ -135,18 +135,16 @@ func (p *GRPCProvider) GetProviderSchema() (resp providers.GetProviderSchemaResp
|
|||||||
|
|
||||||
if protoResp.ServerCapabilities != nil {
|
if protoResp.ServerCapabilities != nil {
|
||||||
resp.ServerCapabilities.PlanDestroy = protoResp.ServerCapabilities.PlanDestroy
|
resp.ServerCapabilities.PlanDestroy = protoResp.ServerCapabilities.PlanDestroy
|
||||||
|
resp.ServerCapabilities.GetProviderSchemaOptional = protoResp.ServerCapabilities.GetProviderSchemaOptional
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: Waiting for a provider capability to prevent caching
|
|
||||||
// providers which always need GetProviderSchema called.
|
|
||||||
// set the global cache if we can
|
// set the global cache if we can
|
||||||
//if !p.Addr.IsZero() {
|
if !p.Addr.IsZero() && resp.ServerCapabilities.GetProviderSchemaOptional {
|
||||||
// providers.SchemaCache.Set(p.Addr, resp)
|
providers.SchemaCache.Set(p.Addr, resp)
|
||||||
//} else {
|
} else {
|
||||||
// // otherwise store it in the local cache
|
// otherwise store it in the local cache
|
||||||
// p.schemas = resp
|
p.schema = resp
|
||||||
//}
|
}
|
||||||
p.schemas = resp
|
|
||||||
|
|
||||||
return resp
|
return resp
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,10 @@ func (cp *contextPlugins) NewProvisionerInstance(typ string) (provisioners.Inter
|
|||||||
func (cp *contextPlugins) ProviderSchema(addr addrs.Provider) (providers.ProviderSchema, error) {
|
func (cp *contextPlugins) ProviderSchema(addr addrs.Provider) (providers.ProviderSchema, error) {
|
||||||
log.Printf("[TRACE] terraform.contextPlugins: Initializing provider %q to read its schema", addr)
|
log.Printf("[TRACE] terraform.contextPlugins: Initializing provider %q to read its schema", addr)
|
||||||
|
|
||||||
// check the global schema cache first
|
// 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
|
||||||
|
// may be able to avoid spinning up the provider instance at all.
|
||||||
schemas, ok := providers.SchemaCache.Get(addr)
|
schemas, ok := providers.SchemaCache.Get(addr)
|
||||||
if ok {
|
if ok {
|
||||||
return schemas, nil
|
return schemas, nil
|
||||||
|
Loading…
Reference in New Issue
Block a user