tfsdk

package
Version: v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2023 License: MPL-2.0 Imports: 9 Imported by: 103

Documentation

Overview

Package tfsdk contains core framework functionality for schema data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertValue added in v0.4.0

func ConvertValue(ctx context.Context, val attr.Value, typ attr.Type) (attr.Value, diag.Diagnostics)

ConvertValue creates a new attr.Value of the attr.Type `typ`, using the data in `val`, which can be of any attr.Type so long as its TerraformType method returns a tftypes.Type that `typ`'s ValueFromTerraform method can accept.

func ValueAs added in v0.3.0

func ValueAs(ctx context.Context, val attr.Value, target interface{}) diag.Diagnostics

ValueAs takes the attr.Value `val` and populates the Go value `target` with its content.

This is achieved using reflection rules provided by the internal/reflect package.

func ValueFrom added in v0.9.0

func ValueFrom(ctx context.Context, val interface{}, targetType attr.Type, target interface{}) diag.Diagnostics

ValueFrom takes the Go value `val` and populates `target` with an attr.Value, based on the type definition provided in `targetType`.

This is achieved using reflection rules provided by the internal/reflect package.

Types

type Config

type Config struct {
	Raw    tftypes.Value
	Schema fwschema.Schema
}

Config represents a Terraform config.

func (Config) Get

func (c Config) Get(ctx context.Context, target interface{}) diag.Diagnostics

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

func (Config) GetAttribute

func (c Config) GetAttribute(ctx context.Context, path path.Path, target interface{}) diag.Diagnostics

GetAttribute retrieves the attribute or block found at `path` and populates the `target` with the value. This method is intended for top level schema attributes or blocks. Use `types` package methods or custom types to step into collections.

Attributes or elements under null or unknown collections return null values, however this behavior is not protected by compatibility promises.

func (Config) PathMatches added in v0.10.0

func (c Config) 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.

type Plan

type Plan struct {
	Raw    tftypes.Value
	Schema fwschema.Schema
}

Plan represents a Terraform plan.

func (Plan) Get

func (p Plan) Get(ctx context.Context, target interface{}) diag.Diagnostics

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

func (Plan) GetAttribute

func (p Plan) GetAttribute(ctx context.Context, path path.Path, target interface{}) diag.Diagnostics

GetAttribute retrieves the attribute or block found at `path` and populates the `target` with the value. This method is intended for top level schema attributes or blocks. Use `types` package methods or custom types to step into collections.

Attributes or elements under null or unknown collections return null values, however this behavior is not protected by compatibility promises.

func (Plan) PathMatches added in v0.10.0

func (p Plan) 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 (*Plan) Set

func (p *Plan) Set(ctx context.Context, val interface{}) diag.Diagnostics

Set populates the entire plan using the supplied Go value. The value `val` should be a struct whose values have one of the attr.Value types. Each field must be tagged with the corresponding schema field.

func (*Plan) SetAttribute

func (p *Plan) SetAttribute(ctx context.Context, path path.Path, val interface{}) diag.Diagnostics

SetAttribute 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.

The value must not be an untyped nil. Use a typed nil or types package null value function instead. For example with a types.StringType attribute, use (*string)(nil) or types.StringNull().

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

type State

type State struct {
	Raw    tftypes.Value
	Schema fwschema.Schema
}

State represents a Terraform state.

func (State) Get

func (s State) Get(ctx context.Context, target interface{}) diag.Diagnostics

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

func (State) GetAttribute

func (s State) GetAttribute(ctx context.Context, path path.Path, target interface{}) diag.Diagnostics

GetAttribute retrieves the attribute or block found at `path` and populates the `target` with the value. This method is intended for top level schema attributes or blocks. Use `types` package methods or custom types to step into collections.

Attributes or elements under null or unknown collections return null values, however this behavior is not protected by compatibility promises.

func (State) PathMatches added in v0.10.0

func (s State) 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 (*State) RemoveResource

func (s *State) RemoveResource(ctx context.Context)

RemoveResource removes the entire resource from state.

If a Resource type Delete method is completed without error, this is automatically called on the DeleteResourceResponse.State.

func (*State) Set

func (s *State) Set(ctx context.Context, val interface{}) diag.Diagnostics

Set populates the entire state using the supplied Go value. The value `val` should be a struct whose values have one of the attr.Value types. Each field must be tagged with the corresponding schema field.

func (*State) SetAttribute

func (s *State) SetAttribute(ctx context.Context, path path.Path, val interface{}) diag.Diagnostics

SetAttribute 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.

The value must not be an untyped nil. Use a typed nil or types package null value function instead. For example with a types.StringType attribute, use (*string)(nil) or types.StringNull().

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

Jump to

Keyboard shortcuts

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