opentofu/opentofu · error

invalid opResourceInstanceCurrentMeta instAddr: %w

Error message

invalid opResourceInstanceCurrentMeta instAddr: %w

What it means

The first operand of opResourceInstanceCurrentMeta must reference a previous element producing addrs.AbsResourceInstance. The wrapped 'refers to %T, but need %T' error means the referenced element yields a different result type (e.g. a ConstantValue). A forward reference or out-of-range index instead coerces to a nil result and does not raise this error.

Source

Thrown at internal/engine/internal/execgraph/graph_unmarshal.go:160

	case opManagedChangeAddr:
		return unmarshalOpManagedChangeAddr(protoOp.GetOperands(), prevResults, builder)
	case opDataRead:
		return unmarshalOpDataRead(protoOp.GetOperands(), prevResults, builder)
	default:
		// The above cases should cover all valid values of [opCode], so we
		// should not get here unless the serialized graph was tampered
		// with outside of OpenTofu.
		return nil, fmt.Errorf("unrecognized opcode %d", c)
	}
}

func unmarshalOpResourceInstanceCurrentMeta(rawOperands []uint64, prevResults []AnyResultRef, builder *Builder) (AnyResultRef, error) {
	if len(rawOperands) != 2 {
		return nil, fmt.Errorf("wrong number of operands (%d) for opResourceInstanceCurrentMeta", len(rawOperands))
	}
	instAddr, err := unmarshalGetPrevResultOf[addrs.AbsResourceInstance](prevResults, rawOperands[0])
	if err != nil {
		return nil, fmt.Errorf("invalid opResourceInstanceCurrentMeta instAddr: %w", err)
	}
	prior, err := unmarshalGetPrevResultOf[*exec.ResourceInstanceObject](prevResults, rawOperands[1])
	if err != nil {
		return nil, fmt.Errorf("invalid opResourceInstanceCurrentMeta prior: %w", err)
	}
	return builder.ResourceInstanceCurrentMeta(instAddr, prior), nil
}

func unmarshalOpResourceInstanceDesired(rawOperands []uint64, prevResults []AnyResultRef, builder *Builder) (AnyResultRef, error) {
	if len(rawOperands) != 1 {
		return nil, fmt.Errorf("wrong number of operands (%d) for opResourceInstanceDesired", len(rawOperands))
	}
	meta, err := unmarshalGetPrevResultOf[*exec.ResourceInstanceObjectMeta](prevResults, rawOperands[0])
	if err != nil {
		return nil, fmt.Errorf("invalid opResourceInstanceDesired meta: %w", err)
	}
	return builder.ResourceInstanceDesired(meta), nil
}

View on GitHub (pinned to 3561785c48)

Solutions

  1. Regenerate the graph artifact with the same OpenTofu version
  2. Never modify serialized graphs between write and read
  3. File an issue if the same released version both wrote and read the artifact
Defensive patterns

Strategy: try-catch

Try / catch

g, err := execgraph.UnmarshalGraph(src)
if err != nil && strings.Contains(err.Error(), "invalid opResourceInstanceCurrentMeta instAddr") {
	return fmt.Errorf("graph operand type mismatch (instAddr): %w", err)
}

Prevention

When it happens

Trigger: Operand index 0 points at an element of the wrong result type in a tampered or cross-version serialized graph.

Common situations: Version-skewed or hand-modified graph artifacts.

Related errors


AI-assisted analysis of opentofu/opentofu@3561785c48 (2026-08-15). Data as JSON: /api/errors/a66fa28b73fcbbdb. Report an issue: GitHub.