v0.11.1 Latest Latest

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

Go to latest
Published: Aug 15, 2022 License: MPL-2.0 Imports: 13 Imported by: 0



Package fwschemadata implements the shared schema-based data implementation for configuration, plan, and state values.



This section is empty.


This section is empty.


func CreateParentTerraformValue

func CreateParentTerraformValue(_ context.Context, parentPath path.Path, parentType tftypes.Type, childValue interface{}) (tftypes.Value, diag.Diagnostics)

CreateParentTerraformValue ensures that the given parent value can have children values upserted. If the parent value is known and not null, it is returned without modification. A null Object or Tuple is converted to known with null children. An unknown Object or Tuple is converted to known with unknown children. List, Map, and Set are created with empty elements.

func UpsertChildTerraformValue

func UpsertChildTerraformValue(_ context.Context, parentPath path.Path, parentValue tftypes.Value, childStep path.PathStep, childValue tftypes.Value) (tftypes.Value, diag.Diagnostics)

UpsertChildTerraformValue will upsert a child value into a parent value. If the path step already has a value, it will be overwritten. Otherwise, the child value will be added.

Lists can only have the next element added according to the current length.


type Data

type Data struct {
	// Schema contains the data structure and types for the value.
	Schema fwschema.Schema

	// TerraformValue contains the terraform-plugin-go value implementation.
	// TODO: In the future this may be migrated to attr.Value, or more
	// succinctly, types.Object.
	// Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/172
	TerraformValue tftypes.Value

Data is the shared storage implementation for schema-based values, such as configuration, plan, and state.

func (Data) Get

func (d Data) Get(ctx context.Context, target any) diag.Diagnostics

Get populates the struct passed as `target` with the entire state.

func (Data) GetAtPath

func (d Data) GetAtPath(ctx context.Context, schemaPath path.Path, target any) diag.Diagnostics

GetAtPath retrieves the attribute found at `path` and populates the `target` with the value.

func (Data) PathExists

func (d Data) PathExists(ctx context.Context, path path.Path) (bool, diag.Diagnostics)

PathExists returns true if the path can be reached. The value at the path may be null or unknown.

func (Data) PathMatches

func (d Data) PathMatches(ctx context.Context, pathExpr path.Expression) (path.Paths, diag.Diagnostics)

PathMatches returns all matching path.Paths from the given path.Expression.

If a parent path is null or unknown, which would prevent a full expression from matching, the parent path is returned rather than no match to prevent false positives.

func (*Data) Set

func (d *Data) Set(ctx context.Context, val any) diag.Diagnostics

Set replaces the entire value. The value should be a struct whose fields have one of the attr.Value types. Each field must have the tfsdk field tag.

func (*Data) SetAtPath

func (d *Data) SetAtPath(ctx context.Context, path path.Path, val interface{}) diag.Diagnostics

SetAtPath sets the attribute at `path` using the supplied Go value.

The attribute path and value must be valid with the current schema. If the attribute path already has a value, it will be overwritten. If the attribute path does not have a value, it will be added, including any parent attribute paths as necessary.

Lists can only have the next element added according to the current length.

func (Data) SetAtPathTransformFunc

func (d Data) SetAtPathTransformFunc(ctx context.Context, path path.Path, tfVal tftypes.Value, diags diag.Diagnostics) (func(*tftypes.AttributePath, tftypes.Value) (tftypes.Value, error), diag.Diagnostics)

SetAttributeTransformFunc recursively creates a value based on the current Plan values along the path. If the value at the path does not yet exist, this will perform recursion to add the child value to a parent value, creating the parent value if necessary.

func (Data) TerraformValueAtTerraformPath

func (d Data) TerraformValueAtTerraformPath(_ context.Context, path *tftypes.AttributePath) (tftypes.Value, error)

TerraformValueAtTerraformPath returns the tftypes.Value at a given tftypes.AttributePath or an error.

func (Data) ValueAtPath

func (d Data) ValueAtPath(ctx context.Context, schemaPath path.Path) (attr.Value, diag.Diagnostics)

ValueAtPath retrieves the attribute found at `path` and returns it as an attr.Value. Consumers should assert the type of the returned value with the desired attr.Type.

Jump to

Keyboard shortcuts

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