Movatterモバイル変換


[0]ホーム

URL:


path

package
v1.17.0Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2025 License:MPL-2.0Imports:3Imported by:714

Details

Repository

github.com/hashicorp/terraform-plugin-framework

Links

Documentation

Overview

Package path implements attribute path functionality, which definestransversals into schema-based data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

typeExpression

type Expression struct {// contains filtered or unexported fields}

Expression represents an attribute path with expression steps, which canrepresent zero, one, or more actual paths in schema data. This logic iseither based on an absolute path starting at the root of the schema data,similar to Path, or a relative path which is intended to be merged with anexisting absolute path.

Use the MatchRoot() function to create an Expression for an absolute pathwith an initial AtName() step. Use the MatchRelative() function to createan Expression for a relative path, which will be merged with an existingabsolute path.

Similar to Path, Expression functionality has some overlapping method namesand follows a builder pattern, which allows for chaining method calls toconstruct a full expression. The available traversal steps after Expressioncreation are:

  • AtAnyListIndex(): Step into a list at any index
  • AtAnyMapKey(): Step into a map at any key
  • AtAnySetValue(): Step into a set at any attr.Value element
  • AtListIndex(): Step into a list at a specific index
  • AtMapKey(): Step into a map at a specific key
  • AtName(): Step into an attribute or block with a specific name
  • AtParent(): Step backwards one step
  • AtSetValue(): Step into a set at a specific attr.Value element

For example, to express any list element with a root list attribute named"some_attribute":

path.MatchRoot("some_attribute").AtAnyListIndex()

An Expression is generally preferable over a Path in schema-definedfunctionality that is intended to accept paths as parameters, such asattribute validators and attribute plan modifiers, since it allows consumersto support relative paths. Use the Merge() or MergeExpressions() method tocombine the current attribute path expression with those expression(s).

To find Paths from an Expression in schema based data structures, such astfsdk.Config, tfsdk.Plan, and tfsdk.State, use their PathMatches() method.

funcMatchRelative

func MatchRelative()Expression

MatchRelative creates an empty attribute path expression that is intendedto be combined with an existing attribute path expression. This allowscreating a relative expression in nested schemas, using AtParent() totraverse up the path or other At methods to traverse further down.

funcMatchRoot

func MatchRoot(rootAttributeNamestring)Expression

MatchRoot creates an attribute path expression starting withExpressionStepAttributeNameExact.

func (Expression)AtAnyListIndex

func (eExpression) AtAnyListIndex()Expression

AtAnyListIndex returns a copied expression with a new list index step at theend. The returned path is safe to modify without affecting the original.

func (Expression)AtAnyMapKey

func (eExpression) AtAnyMapKey()Expression

AtAnyMapKey returns a copied expression with a new map key step at the end.The returned path is safe to modify without affecting the original.

func (Expression)AtAnySetValue

func (eExpression) AtAnySetValue()Expression

AtAnySetValue returns a copied expression with a new set value step at theend. The returned path is safe to modify without affecting the original.

func (Expression)AtListIndex

func (eExpression) AtListIndex(indexint)Expression

AtListIndex returns a copied expression with a new list index step at theend. The returned path is safe to modify without affecting the original.

func (Expression)AtMapKey

func (eExpression) AtMapKey(keystring)Expression

AtMapKey returns a copied expression with a new map key step at the end.The returned path is safe to modify without affecting the original.

func (Expression)AtName

func (eExpression) AtName(namestring)Expression

AtName returns a copied expression with a new attribute or block name stepat the end. The returned path is safe to modify without affecting theoriginal.

func (Expression)AtParent

func (eExpression) AtParent()Expression

AtParent returns a copied expression with a new parent step at the end.The returned path is safe to modify without affecting the original.

func (Expression)AtSetValue

func (eExpression) AtSetValue(valueattr.Value)Expression

AtSetValue returns a copied expression with a new set value step at the end.The returned path is safe to modify without affecting the original.

func (Expression)Copy

func (eExpression) Copy()Expression

Copy returns a duplicate of the expression that is safe to modify withoutaffecting the original.

func (Expression)Equal

func (eExpression) Equal(oExpression)bool

Equal returns true if the given expression is exactly equivalent.

func (Expression)Matches

func (eExpression) Matches(pathPath)bool

Matches returns true if the given Path is valid for the Expression. Anyrelative expression steps, such as ExpressionStepParent, are automaticallyresolved before matching.

func (Expression)MatchesParent

func (eExpression) MatchesParent(pathPath)bool

MatchesParent returns true if the given Path is a valid parent for theExpression. This is helpful for determining if a child Path wouldpotentially match the full Expression during depth-first traversal. Anyrelative expression steps, such as ExpressionStepParent, are automaticallyresolved before matching.

func (Expression)Merge

func (eExpression) Merge(otherExpression)Expression

Merge returns a copied expression either with the steps of the givenexpression added to the end of the existing steps, or overwriting thesteps if the given expression was a root expression.

Any merged expressions will preserve all expressions steps, such asExpressionStepParent, for troubleshooting. Methods such as Matches() willautomatically resolve the expression when using it. Call the Resolve()method explicitly if a resolved expression without any ExpressionStepParentis desired.

func (Expression)MergeExpressions

func (eExpression) MergeExpressions(others ...Expression)Expressions

MergeExpressions returns collection of expressions that calls Merge() onthe current expression with each of the others.

If no Expression are given, then it will return a collection of expressionscontaining only the current expression.

func (Expression)Resolve

func (eExpression) Resolve()Expression

Resolve returns a copied expression with any relative steps, such asExpressionStepParent, resolved. This is not necessary before calling methodssuch as Matches(), however it can be useful before returning the String()method so the path information is simplified.

Returns an empty expression if any ExpressionStepParent attempt to gobeyond the first element.

func (Expression)Steps

Steps returns a copy of the underlying expression steps. Returns an emptycollection of steps if expression is nil.

func (Expression)String

func (eExpression) String()string

String returns the human-readable representation of the path.It is intended for logging and error messages and is not protected bycompatibility guarantees.

typeExpressionStep

type ExpressionStep interface {// Equal should return true if the given Step is exactly equivalent.Equal(ExpressionStep)bool// Matches should return true if the given PathStep can be fulfilled by the// ExpressionStep.Matches(PathStep)bool// String should return a human-readable representation of the step// intended for logging and error messages. There should not be usage// that needs to be protected by compatibility guarantees.String()string// contains filtered or unexported methods}

ExpressionStep represents an expression of an attribute path step, which maymatch zero, one, or more actual paths.

typeExpressionStepAttributeNameExact

type ExpressionStepAttributeNameExactstring

ExpressionStepAttributeNameExact is an attribute path expression for anexact attribute name match within an object.

func (ExpressionStepAttributeNameExact)Equal

Equal returns true if the given ExpressionStep is aExpressionStepAttributeNameExact and the attribute name is equivalent.

func (ExpressionStepAttributeNameExact)Matches

Matches returns true if the given PathStep is fulfilled by theExpressionStepAttributeNameExact condition.

func (ExpressionStepAttributeNameExact)String

String returns the human-readable representation of the attribute nameexpression. It is intended for logging and error messages and is notprotected by compatibility guarantees.

typeExpressionStepElementKeyIntAny

type ExpressionStepElementKeyIntAny struct{}

ExpressionStepElementKeyIntAny is an attribute path expression for a matching anyinteger element key within a list.

func (ExpressionStepElementKeyIntAny)Equal

Equal returns true if the given ExpressionStep is aExpressionStepElementKeyIntAny.

func (ExpressionStepElementKeyIntAny)Matches

Matches returns true if the given PathStep is fulfilled by theExpressionStepElementKeyIntAny condition.

func (ExpressionStepElementKeyIntAny)String

String returns the human-readable representation of the element keyexpression. It is intended for logging and error messages and is notprotected by compatibility guarantees.

typeExpressionStepElementKeyIntExact

type ExpressionStepElementKeyIntExactint64

ExpressionStepElementKeyIntExact is an attribute path expression for an exact integerelement key match within a list. List indexing starts at 0.

func (ExpressionStepElementKeyIntExact)Equal

Equal returns true if the given ExpressionStep is aExpressionStepElementKeyIntExact and the integer element key is equivalent.

func (ExpressionStepElementKeyIntExact)Matches

Matches returns true if the given PathStep is fulfilled by theExpressionStepElementKeyIntExact condition.

func (ExpressionStepElementKeyIntExact)String

String returns the human-readable representation of the element keyexpression. It is intended for logging and error messages and is notprotected by compatibility guarantees.

typeExpressionStepElementKeyStringAny

type ExpressionStepElementKeyStringAny struct{}

ExpressionStepElementKeyStringAny is an attribute path expression for a matching anystring key within a map.

func (ExpressionStepElementKeyStringAny)Equal

Equal returns true if the given ExpressionStep is aExpressionStepElementKeyStringAny.

func (ExpressionStepElementKeyStringAny)Matches

Matches returns true if the given PathStep is fulfilled by theExpressionStepElementKeyStringAny condition.

func (ExpressionStepElementKeyStringAny)String

String returns the human-readable representation of the element keyexpression. It is intended for logging and error messages and is notprotected by compatibility guarantees.

typeExpressionStepElementKeyStringExact

type ExpressionStepElementKeyStringExactstring

ExpressionStepElementKeyStringExact is an attribute path expression for an exact stringkey within a map. Map keys are always strings.

func (ExpressionStepElementKeyStringExact)Equal

Equal returns true if the given ExpressionStep is aExpressionStepElementKeyStringExact and the string element key is equivalent.

func (ExpressionStepElementKeyStringExact)Matches

Matches returns true if the given PathStep is fulfilled by theExpressionStepElementKeyStringExact condition.

func (ExpressionStepElementKeyStringExact)String

String returns the human-readable representation of the element keyexpression. It is intended for logging and error messages and is notprotected by compatibility guarantees.

typeExpressionStepElementKeyValueAny

type ExpressionStepElementKeyValueAny struct{}

ExpressionStepElementKeyValueAny is an attribute path expression for a matching anyValue element within a set.

func (ExpressionStepElementKeyValueAny)Equal

Equal returns true if the given ExpressionStep is aExpressionStepElementKeyValueAny.

func (ExpressionStepElementKeyValueAny)Matches

Matches returns true if the given PathStep is fulfilled by theExpressionStepElementKeyValueAny condition.

func (ExpressionStepElementKeyValueAny)String

String returns the human-readable representation of the element keyexpression. It is intended for logging and error messages and is notprotected by compatibility guarantees.

typeExpressionStepElementKeyValueExact

type ExpressionStepElementKeyValueExact struct {// Value is an interface, so it cannot be type aliased with methods.attr.Value}

ExpressionStepElementKeyValueExact is an attribute path expression for an exact Valueelement within a set. Sets do not use integer-based indexing.

func (ExpressionStepElementKeyValueExact)Equal

Equal returns true if the given ExpressionStep is aExpressionStepElementKeyValueExact and the Value element key is equivalent.

func (ExpressionStepElementKeyValueExact)Matches

Matches returns true if the given PathStep is fulfilled by theExpressionStepElementKeyValueExact condition.

func (ExpressionStepElementKeyValueExact)String

String returns the human-readable representation of the element keyexpression. It is intended for logging and error messages and is notprotected by compatibility guarantees.

typeExpressionStepParent

type ExpressionStepParent struct{}

StepParent is an attribute path expression for a traversing to the parentattribute path relative to the current one. This is intended only for thestart of attribute-level expressions which will be combined with the currentattribute path being called.

func (ExpressionStepParent)Equal

Equal returns true if the given ExpressionStep is a ExpressionStepParent.

func (ExpressionStepParent)Matches

Matches returns true if the given PathStep is fulfilled by theExpressionStepParent condition.

func (ExpressionStepParent)String

String returns the human-readable representation of the element keyexpression. It is intended for logging and error messages and is notprotected by compatibility guarantees.

typeExpressionSteps

type ExpressionSteps []ExpressionStep

ExpressionSteps represents an ordered collection of attribute pathexpressions.

func (*ExpressionSteps)Append

Append adds the given ExpressionSteps to the end of the previous ExpressionSteps andreturns the combined result.

func (ExpressionSteps)Copy

Copy returns a duplicate of the steps that is safe to modify withoutaffecting the original. Returns nil if the original steps is nil.

func (ExpressionSteps)Equal

Equal returns true if the given ExpressionSteps are equivalent.

func (ExpressionSteps)LastStep

LastStep returns the final ExpressionStep and the remaining ExpressionSteps.

func (ExpressionSteps)Matches

func (sExpressionSteps) Matches(pathStepsPathSteps)bool

Matches returns true if the given PathSteps match each ExpressionStep.

Any ExpressionStepParent will automatically be resolved.

func (ExpressionSteps)MatchesParent

func (sExpressionSteps) MatchesParent(pathStepsPathSteps)bool

MatchesParent returns true if the given PathSteps match each ExpressionStepuntil there are no more PathSteps. This is helpful for determining if thePathSteps would potentially match the full ExpressionSteps duringdepth-first traversal.

Any ExpressionStepParent will automatically be resolved.

func (ExpressionSteps)NextStep

NextStep returns the first ExpressionStep and the remaining ExpressionSteps.

func (ExpressionSteps)Resolve

Resolve returns a copy of ExpressionSteps without any ExpressionStepParent.

Returns empty ExpressionSteps if any ExpressionStepParent attempt to gobeyond the first element. Returns nil if the original steps is nil.

func (ExpressionSteps)String

func (sExpressionSteps) String()string

String returns the human-readable representation of the ExpressionSteps.It is intended for logging and error messages and is not protected bycompatibility guarantees.

typeExpressions

type Expressions []Expression

Expressions is a collection of attribute path expressions.

Refer to the Expression documentation for more details about intended usage.

func (*Expressions)Append

func (e *Expressions) Append(expressions ...Expression)Expressions

Append adds the given Expressions to the collection without duplication andreturns the combined result.

func (Expressions)Contains

func (eExpressions) Contains(checkExpressionExpression)bool

Contains returns true if the collection of expressions includes the givenexpression.

func (Expressions)Matchesadded inv1.1.0

func (eExpressions) Matches(checkPathPath)bool

Matches returns true if one of the expressions in the collection matches thegiven path.

func (Expressions)String

func (pExpressions) String()string

String returns the human-readable representation of the expressioncollection. It is intended for logging and error messages and is notprotected by compatibility guarantees.

Empty expressions are skipped.

typePath

type Path struct {// contains filtered or unexported fields}

Path represents exact traversal steps into a schema or schema-based data.These steps always start from the root of the schema, which is an objectwith zero or more attributes and blocks.

Use the Root() function to create a Path with an initial AtName() step. Pathfunctionality follows a builder pattern, which allows for chaining methodcalls to construct a full path. The available traversal steps after Pathcreation are:

  • AtListIndex(): Step into a list at a specific 0-based index
  • AtMapKey(): Step into a map at a specific key
  • AtName(): Step into an attribute or block with a specific name
  • AtSetValue(): Step into a set at a specific attr.Value element

For example, to represent the first list element with a root list attributenamed "some_attribute":

path.MatchRoot("some_attribute").AtListIndex(0)

Path is used for functionality which must exactly match the underlyingschema structure and types, such as diagnostics that are intended for aspecific attribute or working with specific attribute values in a schemabased data structure such as tfsdk.Config, tfsdk.Plan, or tfsdk.State.

Refer to Expression for situations where relative or wildcard step logic isdesirable for schema defined functionality, such as attribute validators orattribute plan modifiers.

funcEmpty

func Empty()Path

Empty creates an empty attribute path. Provider code should use Root.

funcRoot

func Root(rootAttributeNamestring)Path

Root creates an attribute path starting with a PathStepAttributeName.

func (Path)AtListIndex

func (pPath) AtListIndex(indexint)Path

AtListIndex returns a copied path with a new list index step at the end.The returned path is safe to modify without affecting the original.

List indices are 0-based. The first element of a list is 0.

func (Path)AtMapKey

func (pPath) AtMapKey(keystring)Path

AtMapKey returns a copied path with a new map key step at the end.The returned path is safe to modify without affecting the original.

func (Path)AtName

func (pPath) AtName(namestring)Path

AtName returns a copied path with a new attribute or block name step at theend. The returned path is safe to modify without affecting the original.

func (Path)AtSetValue

func (pPath) AtSetValue(valueattr.Value)Path

AtSetValue returns a copied path with a new set value step at the end.The returned path is safe to modify without affecting the original.

func (Path)AtTupleIndexadded inv1.6.0

func (pPath) AtTupleIndex(indexint)Path

AtTupleIndex returns a copied path with a new tuple index step at the end.The returned path is safe to modify without affecting the original.

Tuple indices are 0-based. The first element of a tuple is 0.

func (Path)Copy

func (pPath) Copy()Path

Copy returns a duplicate of the path that is safe to modify withoutaffecting the original.

func (Path)Equal

func (pPath) Equal(oPath)bool

Equal returns true if the given path is exactly equivalent.

func (Path)Expression

func (pPath) Expression()Expression

Expression returns an Expression which exactly matches the Path.

func (Path)ParentPath

func (pPath) ParentPath()Path

ParentPath returns a copy of the path with the last step removed.

If the current path is empty, an empty path is returned.

func (Path)Steps

func (pPath) Steps()PathSteps

Steps returns a copy of the underlying path steps. Returns an emptycollection of steps if path is nil.

func (Path)String

func (pPath) String()string

String returns the human-readable representation of the path.It is intended for logging and error messages and is not protected bycompatibility guarantees.

typePathStep

type PathStep interface {// Equal should return true if the given PathStep is exactly equivalent.Equal(PathStep)bool// ExpressionStep should return an ExpressionStep which exactly// matches the PathStep.ExpressionStep()ExpressionStep// String should return a human-readable representation of the step// intended for logging and error messages. There should not be usage// that needs to be protected by compatibility guarantees.String()string// contains filtered or unexported methods}

PathStep represents a transversal for an attribute path. Only exact pathtransversals are supported as implementations of this interface must remaincompatible with all protocol implementations.

typePathStepAttributeName

type PathStepAttributeNamestring

PathStepAttributeName is an attribute path tranversal for an attribute namewithin an object.

List elements must be transversed by PathStepElementKeyInt.Map elements must be transversed by PathStepElementKeyString.Set elements must be transversed by PathStepElementKeyValue.

func (PathStepAttributeName)Equal

Equal returns true if the given PathStep is a PathStepAttributeName and theattribute name is equivalent.

func (PathStepAttributeName)ExpressionStep

func (sPathStepAttributeName) ExpressionStep()ExpressionStep

ExpressionStep returns the ExpressionStep for the PathStep.

func (PathStepAttributeName)String

String returns the human-readable representation of the attribute name.It is intended for logging and error messages and is not protected bycompatibility guarantees.

typePathStepElementKeyInt

type PathStepElementKeyIntint64

PathStepElementKeyInt is an attribute path transversal for an integerelement of a list. List indexing starts a 0.

Map elements must be transversed by PathStepElementKeyString.Object attributes must be transversed by PathStepAttributeName.Set elements must be transversed by PathStepElementKeyValue.

func (PathStepElementKeyInt)Equal

Equal returns true if the given PathStep is a PathStepAttributeName and theattribute name is equivalent.

func (PathStepElementKeyInt)ExpressionStep

func (sPathStepElementKeyInt) ExpressionStep()ExpressionStep

ExpressionStep returns the ExpressionStep for the PathStep.

func (PathStepElementKeyInt)String

String returns the human-readable representation of the element key.It is intended for logging and error messages and is not protected bycompatibility guarantees.

typePathStepElementKeyString

type PathStepElementKeyStringstring

PathStepElementKeyString is an attribute path transversal for a stringkey of a map. Map keys are always strings.

List elements must be transversed by PathStepElementKeyInt.Object attributes must be transversed by PathStepAttributeName.Set elements must be transversed by PathStepElementKeyValue.

func (PathStepElementKeyString)Equal

Equal returns true if the given PathStep is a PathStepAttributeName and theattribute name is equivalent.

func (PathStepElementKeyString)ExpressionStep

ExpressionStep returns the ExpressionStep for the PathStep.

func (PathStepElementKeyString)String

String returns the human-readable representation of the element key.It is intended for logging and error messages and is not protected bycompatibility guarantees.

typePathStepElementKeyValue

type PathStepElementKeyValue struct {// Value is an interface, so it cannot be type aliased with methods.attr.Value}

PathStepElementKeyValue is an attribute path transversal for a Value elementof a set. Sets do not use integer-based indexing.

List elements must be transversed by PathStepElementKeyInt.Map elements must be transversed by PathStepElementKeyString.Object attributes must be transversed by PathStepAttributeName.

func (PathStepElementKeyValue)Equal

Equal returns true if the given PathStep is a PathStepAttributeName and theattribute name is equivalent.

func (PathStepElementKeyValue)ExpressionStep

func (sPathStepElementKeyValue) ExpressionStep()ExpressionStep

ExpressionStep returns the ExpressionStep for the PathStep.

func (PathStepElementKeyValue)String

String returns the human-readable representation of the element key.It is intended for logging and error messages and is not protected bycompatibility guarantees.

typePathSteps

type PathSteps []PathStep

PathSteps represents an ordered collection of attribute path transversals.

func (*PathSteps)Append

func (s *PathSteps) Append(steps ...PathStep)PathSteps

Append adds the given PathSteps to the end of the previous PathSteps andreturns the combined result.

func (PathSteps)Copy

func (sPathSteps) Copy()PathSteps

Copy returns a duplicate of the steps that is safe to modify withoutaffecting the original. Returns nil if the original steps is nil.

func (PathSteps)Equal

func (sPathSteps) Equal(oPathSteps)bool

Equal returns true if the given PathSteps are equivalent.

func (PathSteps)ExpressionSteps

func (sPathSteps) ExpressionSteps()ExpressionSteps

ExpressionSteps returns the ordered collection of expression steps whichexactly matches the PathSteps.

func (PathSteps)LastStep

func (sPathSteps) LastStep() (PathStep,PathSteps)

LastStep returns the final PathStep and the remaining PathSteps.

func (PathSteps)NextStep

func (sPathSteps) NextStep() (PathStep,PathSteps)

NextStep returns the first PathStep and the remaining PathSteps.

func (PathSteps)String

func (sPathSteps) String()string

String returns the human-readable representation of the PathSteps.It is intended for logging and error messages and is not protected bycompatibility guarantees.

typePaths

type Paths []Path

Paths is a collection of exact attribute paths.

Refer to the Path documentation for more details about intended usage.

func (*Paths)Append

func (p *Paths) Append(paths ...Path)Paths

Append adds the given Paths to the collection without duplication andreturns the combined result.

func (Paths)Contains

func (pPaths) Contains(checkPathPath)bool

Contains returns true if the collection of paths includes the given path.

func (Paths)String

func (pPaths) String()string

String returns the human-readable representation of the path collection.It is intended for logging and error messages and is not protected bycompatibility guarantees.

Empty paths are skipped.

Source Files

View all Source files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp