Help us shape the future of Go! Take the 2026 Go Developer Survey

instances

package
v1.20.2 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package instances resolves Terraform count and for_each expressions into bounded instance plans, without evaluating block bodies or charging budgets.

Index

Constants

View Source
const (
	// KindCount and KindForEach name the meta-argument a block expands by.
	KindCount   = "count"
	KindForEach = "for_each"
)
View Source
const MaxPerBlock = 50

MaxPerBlock caps the instances expanded from one count or for_each block.

Variables

This section is empty.

Functions

func Attributes

func Attributes(body *hclsyntax.Body) (count, forEach hcl.Expression)

Attributes picks the count and for_each expressions of an HCL body.

func ForEachCollection

func ForEachCollection(v cty.Value) bool

ForEachCollection reports whether v is a known, non-null map, object or set with known length. Keys are validated during expansion; values may be unknown.

Types

type Item

type Item struct {
	Key, Value cty.Value
}

Item is one instance's index or collection key and, for for_each, its value.

type Plan

type Plan struct {
	// Kind is empty for a block without count or for_each.
	Kind string
	// Unresolved means the expression failed or its instance keys are unknown
	// or invalid. No concrete Items are returned in this case.
	Unresolved bool
	// Requested is the full instance count before the per-block cap, when known.
	Requested int
	Items     []Item
	// ForEachKeys retains all keys only for truncated collections small enough
	// to preserve their output shape. Otherwise it is nil.
	ForEachKeys []cty.Value
}

Plan describes an expansion independently of the caller's evaluation context.

func Resolve

func Resolve(count, forEach hcl.Expression, ctx *hcl.EvalContext, maxShape int) Plan

Resolve expands the supplied expressions (nil when absent). Count takes precedence if both are present, matching the module evaluator's fallback for invalid configurations. maxShape bounds retention of truncated for_each keys; callers may use these keys to pad unevaluated outputs with unknown values. Values retain their cty marks, including marks on each.value.

func (*Plan) Truncated

func (p *Plan) Truncated() bool

Truncated reports whether a known expansion exceeded the per-block cap.

func (*Plan) Variable

func (p *Plan) Variable(item Item) (name string, value cty.Value)

Variable returns the count.index or each.key/each.value binding for item. For an unresolved plan, item is ignored and the binding is unknown. For a block without either meta-argument, it returns an empty name and cty.NilVal.

Jump to

Keyboard shortcuts

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