Skip to content

Commit 40ff3ed

Browse files
authored
helper/schema: Update Go documentation for StateUpgradeFunc (#921)
Reference: hashicorp/terraform-plugin-sdk#386
1 parent afa8402 commit 40ff3ed

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

helper/schema/resource.go

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,7 @@ type DeleteContextFunc func(context.Context, *ResourceData, interface{}) diag.Di
637637
type StateMigrateFunc func(
638638
int, *terraform.InstanceState, interface{}) (*terraform.InstanceState, error)
639639

640+
// Implementation of a single schema version state upgrade.
640641
type StateUpgrader struct {
641642
// Version is the version schema that this Upgrader will handle, converting
642643
// it to Version+1.
@@ -655,7 +656,36 @@ type StateUpgrader struct {
655656
Upgrade StateUpgradeFunc
656657
}
657658

658-
// See StateUpgrader
659+
// Function signature for a schema version state upgrade handler.
660+
//
661+
// The Context parameter stores SDK information, such as loggers. It also
662+
// is wired to receive any cancellation from Terraform such as a system or
663+
// practitioner sending SIGINT (Ctrl-c).
664+
//
665+
// The map[string]interface{} parameter contains the previous schema version
666+
// state data for a managed resource instance. The keys are top level attribute
667+
// or block names mapped to values that can be type asserted similar to
668+
// fetching values using the ResourceData Get* methods:
669+
//
670+
// - TypeBool: bool
671+
// - TypeFloat: float
672+
// - TypeInt: int
673+
// - TypeList: []interface{}
674+
// - TypeMap: map[string]interface{}
675+
// - TypeSet: *Set
676+
// - TypeString: string
677+
//
678+
// In certain scenarios, the map may be nil, so checking for that condition
679+
// upfront is recommended to prevent potential panics.
680+
//
681+
// The interface{} parameter is the result of the Provider type
682+
// ConfigureFunc field execution. If the Provider does not define
683+
// a ConfigureFunc, this will be nil. This parameter is conventionally
684+
// used to store API clients and other provider instance specific data.
685+
//
686+
// The map[string]interface{} return parameter should contain the upgraded
687+
// schema version state data for a managed resource instance. Values must
688+
// align to the typing mentioned above.
659689
type StateUpgradeFunc func(ctx context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error)
660690

661691
// See Resource documentation.

0 commit comments

Comments
 (0)