stateutil

package
v0.16.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 23, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CollapseListPath

func CollapseListPath(m map[string]any, key, pathLabel string) diag.Diagnostics

CollapseListPath applies the singleton-list collapse rule for Terraform state upgrades at m[key]. It handles the SDK-to-Plugin-Framework migration where MaxItems:1 / SizeBetween(1,1) list blocks become SingleNestedBlock.

Semantics:

  • key absent: no-op
  • value nil or non-list: no-op (pass-through)
  • empty list: m[key] = nil
  • singleton list: m[key] = list[0]
  • multi-element list: returns an error diagnostic (corrupt state)

func EnsureMapKeys

func EnsureMapKeys(m map[string]any, keys ...string)

EnsureMapKeys sets each key in keys to nil in m if the key is absent. Used during state upgrades to ensure the Plugin Framework can decode the JSON state even when optional blocks were omitted in the prior SDK state.

func MarshalStateMap

func MarshalStateMap(m map[string]any, resp *resource.UpgradeStateResponse)

MarshalStateMap encodes m as JSON and assigns it to resp.DynamicValue.

func NullifyEmptySlice

func NullifyEmptySlice(m map[string]any, keys ...string)

NullifyEmptySlice sets each key in keys to nil in m when the existing value is an empty slice. SDKv2 stored omitted optional TypeSet/TypeList attributes as [] rather than null; the Plugin Framework expects null.

func NullifyEmptyString

func NullifyEmptyString(m map[string]any, keys ...string)

NullifyEmptyString sets each key in keys to nil in m when the existing value is an empty string. SDKv2 stored omitted optional string attributes as "" rather than null; the Plugin Framework expects null, so this normalisation prevents known-empty-vs-null mismatches during state upgrades.

func SetDefaultState

func SetDefaultState(req resource.UpgradeStateRequest, resp *resource.UpgradeStateResponse)

SetDefaultState sets resp.DynamicValue to the original raw state when req.RawState is non-nil. Call this at the top of a state upgrade function so that early returns leave a valid response even when no modifications are needed.

func UnmarshalStateMap

func UnmarshalStateMap(req resource.UpgradeStateRequest, resp *resource.UpgradeStateResponse) map[string]any

UnmarshalStateMap decodes req.RawState.JSON into a map[string]any for use in state upgrade functions. Returns nil and sets a diagnostic error on failure.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL