mirror of
https://github.com/hashicorp/terraform.git
synced 2026-02-03 20:50:59 -05:00
* Persist resource identity in Terraform state * make syncdeps * Move identity schema merging closer to the protocol * mock GetResourceIdentitySchemas * Fix identity refresh tests * Add more tests * Change grcpwrap upgrade identity * Review feedback * Remove unnecessary version conversion * Check if GetResourceIdentitySchemas RPC call is implemented * Update function signature docs * Adapt protocol changes * Check unimplemented error for identities in GetSchema
41 lines
1,006 B
Go
41 lines
1,006 B
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package providers
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"github.com/hashicorp/terraform/internal/addrs"
|
|
)
|
|
|
|
// SchemaCache is a global cache of Schemas.
|
|
// This will be accessed by both core and the provider clients to ensure that
|
|
// large schemas are stored in a single location.
|
|
var SchemaCache = &schemaCache{
|
|
m: make(map[addrs.Provider]ProviderSchema),
|
|
}
|
|
|
|
// Global cache for provider schemas
|
|
// Cache the entire response to ensure we capture any new fields, like
|
|
// ServerCapabilities. This also serves to capture errors so that multiple
|
|
// concurrent calls resulting in an error can be handled in the same manner.
|
|
type schemaCache struct {
|
|
mu sync.Mutex
|
|
m map[addrs.Provider]ProviderSchema
|
|
}
|
|
|
|
func (c *schemaCache) Set(p addrs.Provider, s ProviderSchema) {
|
|
c.mu.Lock()
|
|
defer c.mu.Unlock()
|
|
|
|
c.m[p] = s
|
|
}
|
|
|
|
func (c *schemaCache) Get(p addrs.Provider) (ProviderSchema, bool) {
|
|
c.mu.Lock()
|
|
defer c.mu.Unlock()
|
|
|
|
s, ok := c.m[p]
|
|
return s, ok
|
|
}
|