fwschemadata

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2023 License: MPL-2.0 Imports: 15 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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.

func ValueSemanticEquality added in v1.3.0

func ValueSemanticEquality(ctx context.Context, req ValueSemanticEqualityRequest, resp *ValueSemanticEqualityResponse)

ValueSemanticEquality runs all semantic equality logic for a value, including recursive checking against collection and structural types.

func ValueSemanticEqualityBool added in v1.3.0

func ValueSemanticEqualityBool(ctx context.Context, req ValueSemanticEqualityRequest, resp *ValueSemanticEqualityResponse)

ValueSemanticEqualityBool performs bool type semantic equality.

func ValueSemanticEqualityFloat64 added in v1.3.0

func ValueSemanticEqualityFloat64(ctx context.Context, req ValueSemanticEqualityRequest, resp *ValueSemanticEqualityResponse)

ValueSemanticEqualityFloat64 performs float64 type semantic equality.

func ValueSemanticEqualityInt64 added in v1.3.0

func ValueSemanticEqualityInt64(ctx context.Context, req ValueSemanticEqualityRequest, resp *ValueSemanticEqualityResponse)

ValueSemanticEqualityInt64 performs int64 type semantic equality.

func ValueSemanticEqualityList added in v1.3.0

func ValueSemanticEqualityList(ctx context.Context, req ValueSemanticEqualityRequest, resp *ValueSemanticEqualityResponse)

ValueSemanticEqualityList performs list type semantic equality.

This will perform semantic equality checking on elements, regardless of whether the collection type implements the expected interface, since it cannot be assumed that the collection type implementation runs all possible element implementations.

func ValueSemanticEqualityListElements added in v1.3.0

func ValueSemanticEqualityListElements(ctx context.Context, req ValueSemanticEqualityRequest, resp *ValueSemanticEqualityResponse)

ValueSemanticEqualityListElements performs list type semantic equality on elements, returning a modified list as necessary.

func ValueSemanticEqualityMap added in v1.3.0

func ValueSemanticEqualityMap(ctx context.Context, req ValueSemanticEqualityRequest, resp *ValueSemanticEqualityResponse)

ValueSemanticEqualityMap performs map type semantic equality.

This will perform semantic equality checking on elements, regardless of whether the collection type implements the expected interface, since it cannot be assumed that the collection type implementation runs all possible element implementations.

func ValueSemanticEqualityMapElements added in v1.3.0

func ValueSemanticEqualityMapElements(ctx context.Context, req ValueSemanticEqualityRequest, resp *ValueSemanticEqualityResponse)

ValueSemanticEqualityMapElements performs list type semantic equality on elements, returning a modified list as necessary.

func ValueSemanticEqualityNumber added in v1.3.0

func ValueSemanticEqualityNumber(ctx context.Context, req ValueSemanticEqualityRequest, resp *ValueSemanticEqualityResponse)

ValueSemanticEqualityNumber performs number type semantic equality.

func ValueSemanticEqualityObject added in v1.3.0

func ValueSemanticEqualityObject(ctx context.Context, req ValueSemanticEqualityRequest, resp *ValueSemanticEqualityResponse)

ValueSemanticEqualityObject performs object type semantic equality.

This will perform semantic equality checking on attributes, regardless of whether the structural type implements the expected interface, since it cannot be assumed that the structural type implementation runs all possible attribute implementations.

func ValueSemanticEqualityObjectAttributes added in v1.3.0

func ValueSemanticEqualityObjectAttributes(ctx context.Context, req ValueSemanticEqualityRequest, resp *ValueSemanticEqualityResponse)

ValueSemanticEqualityObjectAttributes performs object type semantic equality on attributes, returning a modified object as necessary.

func ValueSemanticEqualitySet added in v1.3.0

func ValueSemanticEqualitySet(ctx context.Context, req ValueSemanticEqualityRequest, resp *ValueSemanticEqualityResponse)

ValueSemanticEqualitySet performs set type semantic equality.

This will perform semantic equality checking on elements, regardless of whether the collection type implements the expected interface, since it cannot be assumed that the collection type implementation runs all possible element implementations.

func ValueSemanticEqualitySetElements added in v1.3.0

func ValueSemanticEqualitySetElements(ctx context.Context, req ValueSemanticEqualityRequest, resp *ValueSemanticEqualityResponse)

ValueSemanticEqualitySetElements performs list type semantic equality on elements, returning a modified list as necessary.

func ValueSemanticEqualityString added in v1.3.0

func ValueSemanticEqualityString(ctx context.Context, req ValueSemanticEqualityRequest, resp *ValueSemanticEqualityResponse)

ValueSemanticEqualityString performs string type semantic equality.

Types

type Data

type Data struct {
	// Description contains the human friendly type of the data. Used in error
	// diagnostics.
	Description DataDescription

	// 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) NullifyCollectionBlocks added in v1.1.0

func (d *Data) NullifyCollectionBlocks(ctx context.Context) diag.Diagnostics

NullifyCollectionBlocks converts list and set block empty values to null values. The reverse conversion is ReifyNullCollectionBlocks.

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) ReifyNullCollectionBlocks added in v1.1.0

func (d *Data) ReifyNullCollectionBlocks(ctx context.Context) diag.Diagnostics

ReifyNullCollectionBlocks converts list and set block null values to empty values. This is the reverse conversion of NullifyCollectionBlocks.

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) TransformDefaults added in v1.2.0

func (d *Data) TransformDefaults(ctx context.Context, configRaw tftypes.Value) diag.Diagnostics

TransformDefaults walks the schema and applies schema defined default values when configRaw contains a null value at the same path.

func (Data) ValidPathExpression added in v1.1.0

func (d Data) ValidPathExpression(ctx context.Context, expression path.Expression) bool

ValidPathExpression returns true if the given expression is valid for the schema underlying the Data. This can be used to determine if there was an expression implementation error versus an expression returning no path matches based on implementation details of the underlying data storage.

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.

type DataDescription added in v0.12.0

type DataDescription string

DataDescription is a human friendly type for Data. Used in error diagnostics.

const (
	// DataDescriptionConfiguration is used for Data that represents
	// a configuration-based value.
	DataDescriptionConfiguration DataDescription = "configuration"

	// DataDescriptionPlan is used for Data that represents
	// a plan-based value.
	DataDescriptionPlan DataDescription = "plan"

	// DataDescriptionState is used for Data that represents
	// a state-based value.
	DataDescriptionState DataDescription = "state"
)

func (DataDescription) String added in v0.12.0

func (d DataDescription) String() string

String returns the lowercase string of the description.

func (DataDescription) Title added in v0.12.0

func (d DataDescription) Title() string

Title returns the titlecase string of the description.

type ValueSemanticEqualityRequest added in v1.3.0

type ValueSemanticEqualityRequest struct {
	// Path is the schema-based path of the value.
	Path path.Path

	// PriorValue is the prior value.
	PriorValue attr.Value

	// ProposedNewValue is the proposed new value. NewValue in the response
	// contains the results of semantic equality logic.
	ProposedNewValue attr.Value
}

ValueSemanticEqualityRequest represents a request for the provider to perform semantic equality logic on a value.

type ValueSemanticEqualityResponse added in v1.3.0

type ValueSemanticEqualityResponse struct {
	// NewValue contains the new value based on the semantic equality logic.
	NewValue attr.Value

	// Diagnostics contains any errors and warnings for the logic.
	Diagnostics diag.Diagnostics
}

ValueSemanticEqualityResponse represents a response to a ValueSemanticEqualityRequest.

Jump to

Keyboard shortcuts

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