tfjsonpath

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2024 License: MPL-2.0 Imports: 2 Imported by: 1

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

func Traverse(object any, attrPath Path) (any, error)

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 MapStep

type MapStep string

MapStep represents a traversal for map[string]any

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 New

func New[T int | string](firstStep T) Path

New creates a new path with an initial MapStep or SliceStep.

func (Path) AtMapKey

func (s Path) AtMapKey(key string) Path

AtMapKey returns a copied Path with a new MapStep at the end.

func (Path) AtSliceIndex

func (s Path) AtSliceIndex(index int) Path

AtSliceIndex returns a copied Path with a new SliceStep at the end.

func (Path) String added in v1.7.0

func (s Path) String() string

String returns a string representation of the Path.

type SliceStep

type SliceStep int

SliceStep represents a traversal for []any

Jump to

Keyboard shortcuts

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