Documentation ¶
Overview ¶
Package fwschemadata implements the shared schema-based data implementation for configuration, plan, and state values.
Index ¶
- func CreateParentTerraformValue(_ context.Context, parentPath path.Path, parentType tftypes.Type, ...) (tftypes.Value, diag.Diagnostics)
- func UpsertChildTerraformValue(_ context.Context, parentPath path.Path, parentValue tftypes.Value, ...) (tftypes.Value, diag.Diagnostics)
- type Data
- func (d Data) Get(ctx context.Context, target any) diag.Diagnostics
- func (d Data) GetAtPath(ctx context.Context, schemaPath path.Path, target any) diag.Diagnostics
- func (d Data) PathExists(ctx context.Context, path path.Path) (bool, diag.Diagnostics)
- func (d Data) PathMatches(ctx context.Context, pathExpr path.Expression) (path.Paths, diag.Diagnostics)
- func (d *Data) Set(ctx context.Context, val any) diag.Diagnostics
- func (d *Data) SetAtPath(ctx context.Context, path path.Path, val interface{}) diag.Diagnostics
- func (d Data) SetAtPathTransformFunc(ctx context.Context, path path.Path, tfVal tftypes.Value, ...) (func(*tftypes.AttributePath, tftypes.Value) (tftypes.Value, error), ...)
- func (d Data) TerraformValueAtTerraformPath(_ context.Context, path *tftypes.AttributePath) (tftypes.Value, error)
- func (d Data) ValueAtPath(ctx context.Context, schemaPath path.Path) (attr.Value, diag.Diagnostics)
- type DataDescription
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.
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) GetAtPath ¶
GetAtPath retrieves the attribute found at `path` and populates the `target` with the value.
func (Data) PathExists ¶
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 ¶
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 ¶
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.
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.