Documentation ¶
Overview ¶
Package tfjsonpath implements terraform-json path functionality, which defines traversals into Terraform JSON data, for testing purposes.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Traverse ¶
Traverse returns the element found when traversing the given object using the specified Path. The object is an unmarshalled JSON object representing Terraform data.
Traverse returns an error if the value specified by the Path is not found in the given object or if the given object does not conform to format of Terraform JSON data.
Types ¶
type Path ¶
type Path struct {
// contains filtered or unexported fields
}
Path represents exact traversal steps specifying a value inside Terraform JSON data. These steps always start from a MapStep with a key specifying the name of a top-level JSON object or array.
The [terraform-json] library serves as the de facto documentation for JSON format of Terraform data.
Use the New() function to create a Path with an initial AtMapKey() step. Path functionality follows a builder pattern, which allows for chaining method calls to construct a full path. The available traversal steps after Path creation are:
- AtSliceIndex(): Step into a slice at a specific 0-based index
- AtMapKey(): Step into a map at a specific key
For example, to represent the first element of a JSON array underneath a "some_array" property of this JSON value:
{ "some_array": [true] } The path code would be represented by: tfjsonpath.New("some_array").AtSliceIndex(0)
[terraform-json]: (https://pkg.go.dev/github.com/hashicorp/terraform-json)
func (Path) AtSliceIndex ¶
AtSliceIndex returns a copied Path with a new SliceStep at the end.