hashicorp/terraform · critical

found invalid type within path (%v:%T), the validation shoul

Error message

found invalid type within path (%v:%T), the validation shouldn't have allowed this to happen; this is a bug in Terraform, please report it

What it means

This is a panic (not a returned error) raised by PathMatcher.GetChildWithKey (matcher.go:154-164) when an element of a parsed attribute path is neither a string nor a float64. Paths are built from JSON unmarshalling of replace_paths / relevant_attributes, and validation elsewhere is expected to guarantee only those two types appear — so this panic signals an internal bug or corrupted path data.

Source

Thrown at internal/command/jsonformat/structured/attribute_path/matcher.go:164

				child.Paths = append(child.Paths, path)
			}

			// If not we would simply drop this path from our set of paths but
			// either way we just continue.
			continue
		}

		switch val := path[0].(type) {
		case string:
			if val == key {
				child.Paths = append(child.Paths, path[1:])
			}
		case float64:
			// here we must assume the path being looked up no longer matches
			// the given data structure, so the caller in incorrect. This is
			// fine, because it only means that we don't match any paths.
		default:
			panic(fmt.Errorf("found invalid type within path (%v:%T), the validation shouldn't have allowed this to happen; this is a bug in Terraform, please report it", val, val))

		}
	}
	return child
}

func (p *PathMatcher) GetChildWithIndex(index int) Matcher {
	child := &PathMatcher{
		Propagate: p.Propagate,
	}
	for _, path := range p.Paths {
		if len(path) == 0 {
			// This means that the current value matched, but not necessarily
			// it's child.

			if p.Propagate {
				// If propagate is true, then our child match our matches
				child.Paths = append(child.Paths, path)

View on GitHub (pinned to c9def3e214)

Solutions

  1. Re-run `terraform plan` to regenerate the plan/state with correctly-formed paths.
  2. Report the panic to the Terraform project with the plan/config that reproduces it (the message explicitly asks for a bug report).
  3. Ensure the same terraform binary/version produces and renders the plan (avoid cross-version plan files).
  4. If editing plan JSON by hand, ensure every path element is a string or number.
Defensive patterns

Strategy: type-guard

Validate before calling

// Validate path elements are only string/float before handing them to the matcher.
for _, path := range paths {
    for _, el := range path {
        switch el.(type) {
        case string, float64:
        default:
            return fmt.Errorf("invalid path element type %T; regenerate plan", el)
        }
    }
}

Type guard

// isValidPathElement narrows allowed attribute-path step types.
func isValidPathElement(v interface{}) bool {
    switch v.(type) {
    case string, float64:
        return true
    }
    return false
}

Prevention

When it happens

Trigger: Rendering a plan/state diff whose ReplacePaths or RelevantAttributes contain a path element of an unexpected JSON type (e.g. bool, null, nested object/array) — which should have been rejected during the cty→JSON path conversion. Triggered via `terraform plan`/`show -json` rendering of resources with replace-due-to attributes.

Common situations: A bug in the jsonplan path conversion producing malformed path entries; feeding hand-crafted/edited plan JSON into the renderer; version mismatch between a plan produced by one terraform build and rendered by another; corrupted plan file.

Related errors


AI-assisted analysis of hashicorp/terraform@c9def3e214 (2026-08-07). Data as JSON: /api/errors/44167298f8ca8b44. Report an issue: GitHub.