-
Notifications
You must be signed in to change notification settings - Fork 238
TFECO-9166: Add support for ResourceIdentity#SchemaFunc to allow providers to save RAM #1459
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -37,6 +37,12 @@ type ResourceIdentity struct { | |||||
// previous resource schemas. | ||||||
Schema map[string]*Schema | ||||||
|
||||||
// SchemaFunc is an optional function that returns the schema for the | ||||||
// identity. Use this field instead of Schema on resource identity | ||||||
// declarations to prevent storing all identity schema information in | ||||||
// memory for the lifecycle of a provider. | ||||||
SchemaFunc func() map[string]*Schema | ||||||
|
||||||
// New struct, will be similar to (Resource).StateUpgraders | ||||||
IdentityUpgraders []IdentityUpgrader | ||||||
} | ||||||
|
@@ -70,3 +76,18 @@ type ResourceIdentity struct { | |||||
// identity schema version data for a managed resource instance. Values must | ||||||
// align to the typing mentioned above. | ||||||
type ResourceIdentityUpgradeFunc func(ctx context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) | ||||||
|
||||||
// SchemaMap returns the schema information for this Resource whether it is | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also same comment here if we remove the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done in #1461 |
||||||
// defined via the SchemaFunc field or Schema field. The SchemaFunc field, if | ||||||
// defined, takes precedence over the Schema field. | ||||||
func (ri *ResourceIdentity) SchemaMap() map[string]*Schema { | ||||||
if ri == nil { | ||||||
return nil | ||||||
} | ||||||
|
||||||
if ri.SchemaFunc != nil { | ||||||
return ri.SchemaFunc() | ||||||
} | ||||||
|
||||||
return ri.Schema | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package schema | ||
|
||
import "testing" | ||
|
||
func TestResourceIdentity_SchemaMap_handles_nil_identity(t *testing.T) { | ||
var ri *ResourceIdentity | ||
if ri.SchemaMap() != nil { | ||
t.Fatal("expected nil schema map") | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to just remove
Schema
now?Also, since we'll likely put another alpha out, might make sense to add a changelog describing this breaking change between alphas
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also if we remove
Schema
we should update the comment here to reflect that it's the only way to define an identity schema 😄There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also if we remove
Schema
we should update the comment here to reflect that it's the only way to define an identity schema 😄There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in #1461