Merge pull request #33543 from hashicorp/jbardin/get-schema-client-cache

always set schema caches from provider clients
This commit is contained in:
James Bardin 2023-07-19 08:47:25 -04:00 committed by GitHub
commit 62ee606752
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 10 deletions

View File

@ -79,12 +79,14 @@ func (p *GRPCProvider) GetProviderSchema() (resp providers.GetProviderSchemaResp
defer p.mu.Unlock()
// check the global cache if we can
if !p.Addr.IsZero() {
if !p.Addr.IsZero() && resp.ServerCapabilities.GetProviderSchemaOptional {
if resp, ok := providers.SchemaCache.Get(p.Addr); ok {
return resp
}
}
// If the local cache is non-zero, we know this instance has called
// GetProviderSchema at least once and we can return early.
if p.schema.Provider.Block != nil {
return p.schema
}
@ -139,13 +141,14 @@ 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)
} else {
// otherwise store it in the local cache
p.schema = resp
}
// always store this here in the client for providers that are not able to
// use GetProviderSchemaOptional
p.schema = resp
return resp
}

View File

@ -79,12 +79,14 @@ func (p *GRPCProvider) GetProviderSchema() (resp providers.GetProviderSchemaResp
defer p.mu.Unlock()
// check the global cache if we can
if !p.Addr.IsZero() {
if !p.Addr.IsZero() && resp.ServerCapabilities.GetProviderSchemaOptional {
if resp, ok := providers.SchemaCache.Get(p.Addr); ok {
return resp
}
}
// If the local cache is non-zero, we know this instance has called
// GetProviderSchema at least once and we can return early.
if p.schema.Provider.Block != nil {
return p.schema
}
@ -139,13 +141,14 @@ 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)
} else {
// otherwise store it in the local cache
p.schema = resp
}
// always store this here in the client for providers that are not able to
// use GetProviderSchemaOptional
p.schema = resp
return resp
}